Skip to content

Commit

Permalink
telebot: refactor bot api 6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
demget committed Nov 18, 2023
1 parent 5d4079a commit d883371
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 37 deletions.
20 changes: 10 additions & 10 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
type User struct {
ID int64 `json:"id"`

FirstName string `json:"first_name"`
LastName string `json:"last_name"`
IsForum bool `json:"is_forum"`
Username string `json:"username"`
LanguageCode string `json:"language_code"`
IsBot bool `json:"is_bot"`
IsPremium bool `json:"is_premium"`
AddedToMenu bool `json:"added_to_attachment_menu"`
Usernames []string `json:"active_usernames"`
EmojiStatusCustomEmojiID string `json:"emoji_status_custom_emoji_id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
IsForum bool `json:"is_forum"`
Username string `json:"username"`
LanguageCode string `json:"language_code"`
IsBot bool `json:"is_bot"`
IsPremium bool `json:"is_premium"`
AddedToMenu bool `json:"added_to_attachment_menu"`
Usernames []string `json:"active_usernames"`
CustomEmojiStatusID string `json:"emoji_status_custom_emoji_id"`

// Returns only in getMe
CanJoinGroups bool `json:"can_join_groups"`
Expand Down
4 changes: 2 additions & 2 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ type Message struct {
// (Optional) Time of last edit in Unix.
LastEdit int64 `json:"edit_date"`

// (Optional True, if the message is sent to a forum topic
TopicMessage bool `json:"is_topic_message"`
// (Optional) True, if the message is sent to a forum topic.
IsTopicMessage bool `json:"is_topic_message"`

// (Optional) Message can't be forwarded.
Protected bool `json:"has_protected_content,omitempty"`
Expand Down
10 changes: 5 additions & 5 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ type SendOptions struct {
// AllowWithoutReply allows sending messages not a as reply if the replied-to message has already been deleted.
AllowWithoutReply bool

// Protected protects the contents of the sent message from forwarding and saving
// Protected protects the contents of sent message from forwarding and saving.
Protected bool

// MessageThreadID supports sending messages to a thread.
MessageThreadID int
// ThreadID supports sending messages to a thread.
ThreadID int
}

func (og *SendOptions) copy() *SendOptions {
Expand Down Expand Up @@ -191,8 +191,8 @@ func (b *Bot) embedSendOptions(params map[string]string, opt *SendOptions) {
params["protect_content"] = "true"
}

if opt.MessageThreadID != 0 {
params["message_thread_id"] = strconv.Itoa(opt.MessageThreadID)
if opt.ThreadID != 0 {
params["message_thread_id"] = strconv.Itoa(opt.ThreadID)
}
}

Expand Down
32 changes: 12 additions & 20 deletions topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,15 @@ type Topic struct {
Name string `json:"name"`
IconColor int `json:"icon_color"`
IconCustomEmojiID string `json:"icon_custom_emoji_id"`
MessageThreadID int `json:"message_thread_id"`
ThreadID int `json:"message_thread_id"`
}

type TopicCreated struct {
Topic
}

type TopicClosed struct{}

type TopicDeleted struct {
Name string `json:"name"`
IconCustomEmojiID string `json:"icon_custom_emoji_id"`
}

type TopicReopened struct {
Topic
}
type (
TopicCreated struct{ Topic }
TopicClosed struct{}
TopicDeleted struct{ Topic }
TopicReopened struct{ Topic }
)

// CreateTopic creates a topic in a forum supergroup chat.
func (b *Bot) CreateTopic(chat *Chat, forum *Topic) error {
Expand All @@ -49,7 +41,7 @@ func (b *Bot) CreateTopic(chat *Chat, forum *Topic) error {
func (b *Bot) EditTopic(chat *Chat, forum *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
"message_thread_id": forum.MessageThreadID,
"message_thread_id": forum.ThreadID,
}

if forum.Name != "" {
Expand All @@ -67,7 +59,7 @@ func (b *Bot) EditTopic(chat *Chat, forum *Topic) error {
func (b *Bot) CloseTopic(chat *Chat, forum *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
"message_thread_id": forum.MessageThreadID,
"message_thread_id": forum.ThreadID,
}

_, err := b.Raw("closeForumTopic", params)
Expand All @@ -78,7 +70,7 @@ func (b *Bot) CloseTopic(chat *Chat, forum *Topic) error {
func (b *Bot) ReopenTopic(chat *Chat, forum *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
"message_thread_id": forum.MessageThreadID,
"message_thread_id": forum.ThreadID,
}

_, err := b.Raw("reopenForumTopic", params)
Expand All @@ -89,7 +81,7 @@ func (b *Bot) ReopenTopic(chat *Chat, forum *Topic) error {
func (b *Bot) DeleteTopic(chat *Chat, forum *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
"message_thread_id": forum.MessageThreadID,
"message_thread_id": forum.ThreadID,
}

_, err := b.Raw("deleteForumTopic", params)
Expand All @@ -100,7 +92,7 @@ func (b *Bot) DeleteTopic(chat *Chat, forum *Topic) error {
func (b *Bot) UnpinAllTopicMessages(chat *Chat, forum *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
"message_thread_id": forum.MessageThreadID,
"message_thread_id": forum.ThreadID,
}

_, err := b.Raw("unpinAllForumTopicMessages", params)
Expand Down

0 comments on commit d883371

Please sign in to comment.