Skip to content

Commit

Permalink
api: implement 6.8 features (tucnak#652)
Browse files Browse the repository at this point in the history
* api: implement 6.8 features

* chat,topic: refactor

* chat: change unixtime to lowercase
  • Loading branch information
Nash-Well authored Feb 28, 2024
1 parent 435ad60 commit 4670ccf
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
46 changes: 30 additions & 16 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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)
Expand All @@ -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{
Expand Down
3 changes: 3 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
1 change: 1 addition & 0 deletions poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
12 changes: 12 additions & 0 deletions topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 4670ccf

Please sign in to comment.