From 6c99a96d79dcc76b29073fa4ac3b0ae5a706998b Mon Sep 17 00:00:00 2001 From: nash Date: Tue, 20 Feb 2024 16:21:46 +0200 Subject: [PATCH 1/3] api: implement 6.8 features --- chat.go | 41 +++++++++++++++++++++++++---------------- message.go | 3 +++ poll.go | 1 + topic.go | 10 ++++++++++ 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/chat.go b/chat.go index 74d6333b..7744038f 100644 --- a/chat.go +++ b/chat.go @@ -47,22 +47,23 @@ type Chat struct { Username string `json:"username"` // Returns only in getChat - Bio string `json:"bio,omitempty"` - Photo *ChatPhoto `json:"photo,omitempty"` - Description string `json:"description,omitempty"` - InviteLink string `json:"invite_link,omitempty"` - PinnedMessage *Message `json:"pinned_message,omitempty"` - Permissions *Rights `json:"permissions,omitempty"` - SlowMode int `json:"slow_mode_delay,omitempty"` - StickerSet string `json:"sticker_set_name,omitempty"` - CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"` - LinkedChatID int64 `json:"linked_chat_id,omitempty"` - ChatLocation *ChatLocation `json:"location,omitempty"` - Private bool `json:"has_private_forwards,omitempty"` - Protected bool `json:"has_protected_content,omitempty"` - NoVoiceAndVideo bool `json:"has_restricted_voice_and_video_messages"` - HiddenMembers bool `json:"has_hidden_members,omitempty"` - AggressiveAntiSpam bool `json:"has_aggressive_anti_spam_enabled,omitempty"` + Bio string `json:"bio,omitempty"` + Photo *ChatPhoto `json:"photo,omitempty"` + Description string `json:"description,omitempty"` + InviteLink string `json:"invite_link,omitempty"` + PinnedMessage *Message `json:"pinned_message,omitempty"` + Permissions *Rights `json:"permissions,omitempty"` + SlowMode int `json:"slow_mode_delay,omitempty"` + StickerSet string `json:"sticker_set_name,omitempty"` + CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"` + LinkedChatID int64 `json:"linked_chat_id,omitempty"` + ChatLocation *ChatLocation `json:"location,omitempty"` + Private bool `json:"has_private_forwards,omitempty"` + Protected bool `json:"has_protected_content,omitempty"` + NoVoiceAndVideo bool `json:"has_restricted_voice_and_video_messages"` + HiddenMembers bool `json:"has_hidden_members,omitempty"` + AggressiveAntiSpam bool `json:"has_aggressive_anti_spam_enabled,omitempty"` + ExpirationEmojiDate int `json:"emoji_status_expiration_date"` } // Recipient returns chat ID (see Recipient interface). @@ -240,6 +241,14 @@ type ChatInviteLink struct { PendingCount int `json:"pending_join_request_count"` } +type Story struct { + // Unique identifier for the story in the chat + ID int `json:"id"` + + // Chat that posted the story + Sender *Chat `json:"chat"` +} + // ExpireDate returns the moment of the link expiration in local time. func (c *ChatInviteLink) ExpireDate() time.Time { return time.Unix(c.ExpireUnixtime, 0) diff --git a/message.go b/message.go index 82997569..27b16117 100644 --- a/message.go +++ b/message.go @@ -56,6 +56,9 @@ type Message struct { // itself is a reply. ReplyTo *Message `json:"reply_to_message"` + // (Optional) For replies to a story, the original story + Story *Story `json:"reply_to_story"` + // Shows through which bot the message was sent. Via *User `json:"via_bot"` diff --git a/poll.go b/poll.go index 8e2e5091..48018e7b 100644 --- a/poll.go +++ b/poll.go @@ -49,6 +49,7 @@ type PollOption struct { type PollAnswer struct { PollID string `json:"poll_id"` Sender *User `json:"user"` + Chat *Chat `json:"voter_chat"` Options []int `json:"option_ids"` } diff --git a/topic.go b/topic.go index d81fe9a9..83842d6a 100644 --- a/topic.go +++ b/topic.go @@ -170,3 +170,13 @@ func (b *Bot) UnhideGeneralTopic(chat *Chat) error { _, err := b.Raw("unhideGeneralForumTopic", params) return err } + +// UnpinGeneralTopicMessages clears the list of pinned messages in a General forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. +func (b *Bot) UnpinGeneralTopicMessages(chat *Chat) error { + params := map[string]interface{}{ + "chat_id": chat.Recipient(), + } + + _, err := b.Raw("unpinAllGeneralForumTopicMessages", params) + return err +} From ac66328a1fe933b921c40f0b5862b25e377922f9 Mon Sep 17 00:00:00 2001 From: nash Date: Fri, 23 Feb 2024 16:24:52 +0200 Subject: [PATCH 2/3] chat,topic: refactor --- chat.go | 41 +++++++++++++++++++++++------------------ topic.go | 6 ++++-- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/chat.go b/chat.go index 7744038f..616b8ea2 100644 --- a/chat.go +++ b/chat.go @@ -47,23 +47,23 @@ type Chat struct { Username string `json:"username"` // Returns only in getChat - Bio string `json:"bio,omitempty"` - Photo *ChatPhoto `json:"photo,omitempty"` - Description string `json:"description,omitempty"` - InviteLink string `json:"invite_link,omitempty"` - PinnedMessage *Message `json:"pinned_message,omitempty"` - Permissions *Rights `json:"permissions,omitempty"` - SlowMode int `json:"slow_mode_delay,omitempty"` - StickerSet string `json:"sticker_set_name,omitempty"` - CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"` - LinkedChatID int64 `json:"linked_chat_id,omitempty"` - ChatLocation *ChatLocation `json:"location,omitempty"` - Private bool `json:"has_private_forwards,omitempty"` - Protected bool `json:"has_protected_content,omitempty"` - NoVoiceAndVideo bool `json:"has_restricted_voice_and_video_messages"` - HiddenMembers bool `json:"has_hidden_members,omitempty"` - AggressiveAntiSpam bool `json:"has_aggressive_anti_spam_enabled,omitempty"` - ExpirationEmojiDate int `json:"emoji_status_expiration_date"` + Bio string `json:"bio,omitempty"` + Photo *ChatPhoto `json:"photo,omitempty"` + Description string `json:"description,omitempty"` + InviteLink string `json:"invite_link,omitempty"` + PinnedMessage *Message `json:"pinned_message,omitempty"` + Permissions *Rights `json:"permissions,omitempty"` + SlowMode int `json:"slow_mode_delay,omitempty"` + StickerSet string `json:"sticker_set_name,omitempty"` + CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"` + LinkedChatID int64 `json:"linked_chat_id,omitempty"` + ChatLocation *ChatLocation `json:"location,omitempty"` + Private bool `json:"has_private_forwards,omitempty"` + Protected bool `json:"has_protected_content,omitempty"` + NoVoiceAndVideo bool `json:"has_restricted_voice_and_video_messages"` + HiddenMembers bool `json:"has_hidden_members,omitempty"` + AggressiveAntiSpam bool `json:"has_aggressive_anti_spam_enabled,omitempty"` + EmojiExpirationUnixTime int64 `json:"emoji_status_expiration_date"` } // Recipient returns chat ID (see Recipient interface). @@ -246,7 +246,7 @@ type Story struct { ID int `json:"id"` // Chat that posted the story - Sender *Chat `json:"chat"` + Poster *Chat `json:"chat"` } // ExpireDate returns the moment of the link expiration in local time. @@ -259,6 +259,11 @@ func (r ChatJoinRequest) Time() time.Time { return time.Unix(r.Unixtime, 0) } +// Time returns the moment of the emoji status expiration. +func (c *Chat) Time() time.Time { + return time.Unix(c.EmojiExpirationUnixTime, 0) +} + // InviteLink should be used to export chat's invite link. func (b *Bot) InviteLink(chat *Chat) (string, error) { params := map[string]string{ diff --git a/topic.go b/topic.go index 83842d6a..f8848a9d 100644 --- a/topic.go +++ b/topic.go @@ -171,8 +171,10 @@ func (b *Bot) UnhideGeneralTopic(chat *Chat) error { return err } -// UnpinGeneralTopicMessages clears the list of pinned messages in a General forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. -func (b *Bot) UnpinGeneralTopicMessages(chat *Chat) error { +// UnpinAllGeneralTopicMessages clears the list of pinned messages in a General forum topic. +// The bot must be an administrator in the chat for this to work and must have the +// can_pin_messages administrator right in the supergroup. +func (b *Bot) UnpinAllGeneralTopicMessages(chat *Chat) error { params := map[string]interface{}{ "chat_id": chat.Recipient(), } From 6e049b91cd200292e7b3d1978478f0200c8aa42e Mon Sep 17 00:00:00 2001 From: nash Date: Mon, 26 Feb 2024 17:11:17 +0200 Subject: [PATCH 3/3] chat: change unixtime to lowercase --- chat.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chat.go b/chat.go index 616b8ea2..9a017fee 100644 --- a/chat.go +++ b/chat.go @@ -63,7 +63,7 @@ type Chat struct { NoVoiceAndVideo bool `json:"has_restricted_voice_and_video_messages"` HiddenMembers bool `json:"has_hidden_members,omitempty"` AggressiveAntiSpam bool `json:"has_aggressive_anti_spam_enabled,omitempty"` - EmojiExpirationUnixTime int64 `json:"emoji_status_expiration_date"` + EmojiExpirationUnixtime int64 `json:"emoji_status_expiration_date"` } // Recipient returns chat ID (see Recipient interface). @@ -261,7 +261,7 @@ func (r ChatJoinRequest) Time() time.Time { // Time returns the moment of the emoji status expiration. func (c *Chat) Time() time.Time { - return time.Unix(c.EmojiExpirationUnixTime, 0) + return time.Unix(c.EmojiExpirationUnixtime, 0) } // InviteLink should be used to export chat's invite link.