From 4670ccf5a3814b884544b216e73578e686f77e94 Mon Sep 17 00:00:00 2001 From: Nash-Well <107937600+Nash-Well@users.noreply.github.com> Date: Wed, 28 Feb 2024 17:58:27 +0200 Subject: [PATCH] api: implement 6.8 features (#652) * api: implement 6.8 features * chat,topic: refactor * chat: change unixtime to lowercase --- chat.go | 46 ++++++++++++++++++++++++++++++---------------- message.go | 3 +++ poll.go | 1 + topic.go | 12 ++++++++++++ 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/chat.go b/chat.go index 19b93ff..37ac05d 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"` + EmojiExpirationUnixtime int64 `json:"emoji_status_expiration_date"` } // Recipient returns chat ID (see Recipient interface). @@ -243,6 +244,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 + Poster *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) @@ -253,6 +262,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/message.go b/message.go index 5520b2a..d3fee36 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 8e2e509..48018e7 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 d81fe9a..f8848a9 100644 --- a/topic.go +++ b/topic.go @@ -170,3 +170,15 @@ func (b *Bot) UnhideGeneralTopic(chat *Chat) error { _, err := b.Raw("unhideGeneralForumTopic", params) return err } + +// 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(), + } + + _, err := b.Raw("unpinAllGeneralForumTopicMessages", params) + return err +}