Skip to content

Commit

Permalink
Merge pull request tucnak#382 from omar-polo/v2
Browse files Browse the repository at this point in the history
implement my_chat_member and chat_member
  • Loading branch information
demget committed Jul 25, 2021
1 parent 8da1ac5 commit e03da5d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
55 changes: 55 additions & 0 deletions admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,61 @@ import (
"time"
)

// ChatInviteLink object represents an invite for a chat.
type ChatInviteLink struct {
// The invite link.
InviteLink string `json:"invite_link"`

// The creator of the link.
Creator *User `json:"creator"`

// If the link is primary.
IsPrimary bool `json:"is_primary"`

// If the link is revoked.
IsRevoked bool `json:"is_revoked"`

// (Optional) Point in time when the link will expire, use
// ChatInviteLink.ExpireTime() to get time.Time
Unixtime int64 `json:"expire_date,omitempty"`

// (Optional) Maximum number of users that can be members of
// the chat simultaneously.
MemberLimit int `json:"member_limit,omitempty"`
}

// ExpireTime returns the moment of the link expiration in local time.
func (c *ChatInviteLink) ExpireTime() time.Time {
return time.Unix(c.Unixtime, 0)
}

// ChatMemberUpdated object represents changes in the status of a chat member.
type ChatMemberUpdated struct {
// Chat where the user belongs to.
Chat Chat `json:"chat"`

// From which user the action was triggered.
From User `json:"user"`

// Unixtime, use ChatMemberUpdated.Time() to get time.Time
Unixtime int64 `json:"date"`

// Previous information about the chat member.
OldChatMember *ChatMember `json:"old_chat_member"`

// New information about the chat member.
NewChatMember *ChatMember `json:"new_chat_member"`

// (Optional) ChatInviteLink which was used by the user to
// join the chat; for joining by invite link events only.
ChatInviteLink *ChatInviteLink `json:"chat_invite_link"`
}

// Time returns the moment of the change in local time.
func (c *ChatMemberUpdated) Time() time.Time {
return time.Unix(c.Unixtime, 0)
}

// Rights is a list of privileges available to chat members.
type Rights struct {
CanBeEdited bool `json:"can_be_edited"`
Expand Down
12 changes: 12 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ type Update struct {
PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query,omitempty"`
Poll *Poll `json:"poll,omitempty"`
PollAnswer *PollAnswer `json:"poll_answer,omitempty"`
MyChatMember *ChatMemberUpdated `json:"my_chat_member,omitempty"`
ChatMember *ChatMemberUpdated `json:"chat_member,omitempty"`
}

// Command represents a bot command.
Expand Down Expand Up @@ -451,6 +453,16 @@ func (b *Bot) ProcessUpdate(upd Update) {
b.handle(OnPollAnswer, c)
return
}

if upd.MyChatMember != nil {
b.handle(OnMyChatMember, c)
return
}

if upd.ChatMember != nil {
b.handle(OnChatMember, c)
return
}
}

func (b *Bot) handle(end string, c Context) bool {
Expand Down
10 changes: 10 additions & 0 deletions telebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ const (
// Handler: func(*PollAnswer)
OnPollAnswer = "\apoll_answer"

// Will fire on MyChatMember
//
// Handler: func(*ChatMemberUpdated)
OnMyChatMember = "\amy_chat_member"

// Will fire on ChatMember
//
// Handler: func(*ChatMemberUpdated)
OnChatMember = "\achat_member"

// Will fire on VoiceChatStarted
//
// Handler: func(*Message)
Expand Down

0 comments on commit e03da5d

Please sign in to comment.