Skip to content

Commit

Permalink
telebot: move disable_content_type_detection from options to document
Browse files Browse the repository at this point in the history
  • Loading branch information
demget committed Feb 4, 2022
1 parent f029113 commit 6a0ece4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
39 changes: 21 additions & 18 deletions media.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ type Media interface {
// InputMedia represents a composite InputMedia struct that is
// used by Telebot in sending and editing media methods.
type InputMedia struct {
Type string `json:"type"`
Media string `json:"media"`
Caption string `json:"caption"`
Thumbnail string `json:"thumb,omitempty"`
ParseMode string `json:"parse_mode,omitempty"`
Entities Entities `json:"caption_entities,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
Duration int `json:"duration,omitempty"`
Title string `json:"title,omitempty"`
Performer string `json:"performer,omitempty"`
Streaming bool `json:"supports_streaming,omitempty"`
Type string `json:"type"`
Media string `json:"media"`
Caption string `json:"caption"`
Thumbnail string `json:"thumb,omitempty"`
ParseMode string `json:"parse_mode,omitempty"`
Entities Entities `json:"caption_entities,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
Duration int `json:"duration,omitempty"`
Title string `json:"title,omitempty"`
Performer string `json:"performer,omitempty"`
Streaming bool `json:"supports_streaming,omitempty"`
DisableTypeDetection bool `json:"disable_content_type_detection,omitempty"`
}

// Inputtable is a generic type for all kinds of media you
Expand Down Expand Up @@ -143,10 +144,11 @@ type Document struct {
File

// (Optional)
Thumbnail *Photo `json:"thumb,omitempty"`
Caption string `json:"caption,omitempty"`
MIME string `json:"mime_type"`
FileName string `json:"file_name,omitempty"`
Thumbnail *Photo `json:"thumb,omitempty"`
Caption string `json:"caption,omitempty"`
MIME string `json:"mime_type"`
FileName string `json:"file_name,omitempty"`
DisableTypeDetection bool `json:"disable_content_type_detection,omitempty"`
}

func (d *Document) MediaType() string {
Expand All @@ -160,8 +162,9 @@ func (d *Document) MediaFile() *File {

func (d *Document) InputMedia() InputMedia {
return InputMedia{
Type: d.MediaType(),
Caption: d.Caption,
Type: d.MediaType(),
Caption: d.Caption,
DisableTypeDetection: d.DisableTypeDetection,
}
}

Expand Down
3 changes: 0 additions & 3 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ type SendOptions struct {
// Entities is a list of special entities that appear in message text, which can be specified instead of parse_mode.
Entities Entities

// DisableContentDetection abilities to disable server-side file content type detection.
DisableContentDetection bool

// AllowWithoutReply allows sending messages not a as reply if the replied-to message has already been deleted.
AllowWithoutReply bool
}
Expand Down
3 changes: 3 additions & 0 deletions sendable.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ func (d *Document) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error
if d.FileSize != 0 {
params["file_size"] = strconv.Itoa(d.FileSize)
}
if d.DisableTypeDetection {
params["disable_content_type_detection"] = "true"
}

msg, err := b.sendMedia(d, params, thumbnailToFilemap(d.Thumbnail))
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,6 @@ func (b *Bot) embedSendOptions(params map[string]string, opt *SendOptions) {
}
}

if opt.DisableContentDetection {
params["disable_content_type_detection"] = "true"
}

if opt.AllowWithoutReply {
params["allow_sending_without_reply"] = "true"
}
Expand Down

0 comments on commit 6a0ece4

Please sign in to comment.