Merge pull request #407 from DiscoreMe/develop

api: support 5.1
pull/425/head
demget 3 years ago committed by Demian
parent 2d17e0e12c
commit e7f0e64c71

@ -21,17 +21,17 @@ type ChatInviteLink struct {
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"`
// ChatInviteLink.ExpireDate() to get time.Time
ExpireUnixtime 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)
// ExpireDate returns the moment of the link expiration in local time.
func (c *ChatInviteLink) ExpireDate() time.Time {
return time.Unix(c.ExpireUnixtime, 0)
}
// ChatMemberUpdated object represents changes in the status of a chat member.
@ -51,9 +51,9 @@ type ChatMemberUpdated struct {
// New information about the chat member.
NewChatMember *ChatMember `json:"new_chat_member"`
// (Optional) ChatInviteLink which was used by the user to
// (Optional) InviteLink which was used by the user to
// join the chat; for joining by invite link events only.
ChatInviteLink *ChatInviteLink `json:"chat_invite_link"`
InviteLink *ChatInviteLink `json:"invite_link"`
}
// Time returns the moment of the change in local time.
@ -78,6 +78,7 @@ type Rights struct {
CanSendOther bool `json:"can_send_other_messages"`
CanAddPreviews bool `json:"can_add_web_page_previews"`
CanManageVoiceChats bool `json:"can_manage_voice_chats"`
CanManageChat bool `json:"can_manage_chat"`
}
// NoRights is the default Rights{}.
@ -106,6 +107,7 @@ func NoRestrictions() Rights {
CanSendOther: true,
CanAddPreviews: true,
CanManageVoiceChats: false,
CanManageChat: false,
}
}
@ -127,21 +129,25 @@ func AdminRights() Rights {
CanSendOther: true,
CanAddPreviews: true,
CanManageVoiceChats: true,
CanManageChat: true,
}
}
// Forever is a Unixtime of "forever" banning.
// Forever is a ExpireUnixtime of "forever" banning.
func Forever() int64 {
return time.Now().Add(367 * 24 * time.Hour).Unix()
}
// Ban will ban user from chat until `member.RestrictedUntil`.
func (b *Bot) Ban(chat *Chat, member *ChatMember) error {
func (b *Bot) Ban(chat *Chat, member *ChatMember, revokeMessages ...bool) error {
params := map[string]string{
"chat_id": chat.Recipient(),
"user_id": member.User.Recipient(),
"until_date": strconv.FormatInt(member.RestrictedUntil, 10),
}
if len(revokeMessages) > 0 {
params["revoke_messages"] = strconv.FormatBool(revokeMessages[0])
}
_, err := b.Raw("kickChatMember", params)
return err

@ -371,6 +371,11 @@ func (b *Bot) ProcessUpdate(upd Update) {
b.handle(OnProximityAlert, c)
return
}
if m.AutoDeleteTimer != nil {
b.handle(OnAutoDeleteTimer, c)
return
}
}
if upd.EditedMessage != nil {
@ -1504,3 +1509,70 @@ func (b *Bot) Close() (bool, error) {
return resp.Result, nil
}
// CreateInviteLink creates an additional invite link for a chat.
func (b *Bot) CreateInviteLink(chat *Chat, link *ChatInviteLink) (*ChatInviteLink, error) {
params := map[string]string{
"chat_id": chat.Recipient(),
}
if link != nil {
params["expire_date"] = strconv.FormatInt(link.ExpireUnixtime, 10)
params["member_limit"] = strconv.Itoa(link.MemberLimit)
}
data, err := b.Raw("createChatInviteLink", params)
if err != nil {
return nil, err
}
var resp ChatInviteLink
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return &resp, nil
}
// EditInviteLink edits a non-primary invite link created by the bot.
func (b *Bot) EditInviteLink(chat *Chat, link *ChatInviteLink) (*ChatInviteLink, error) {
params := map[string]string{
"chat_id": chat.Recipient(),
}
if link != nil {
params["invite_link"] = link.InviteLink
params["expire_date"] = strconv.FormatInt(link.ExpireUnixtime, 10)
params["member_limit"] = strconv.Itoa(link.MemberLimit)
}
data, err := b.Raw("editChatInviteLink", params)
if err != nil {
return nil, err
}
var resp ChatInviteLink
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return &resp, nil
}
// RevokeInviteLink revokes an invite link created by the bot.
func (b *Bot) RevokeInviteLink(chat *Chat, link string) (*ChatInviteLink, error) {
params := map[string]string{
"chat_id": chat.Recipient(),
"link": link,
}
data, err := b.Raw("revokeChatInviteLink", params)
if err != nil {
return nil, err
}
var resp ChatInviteLink
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return &resp, nil
}

@ -233,6 +233,14 @@ type Message struct {
// For a service message, represents the content of a service message,
// sent whenever a user in the chat triggers a proximity alert set by another user.
ProximityAlert *ProximityAlert `json:"proximity_alert_triggered,omitempty"`
// For a service message, represents about a change in auto-delete timer settings.
AutoDeleteTimer *AutoDeleteTimer `json:"message_auto_delete_timer_changed,omitempty"`
}
// AutoDeleteTimer represents a service message about a change in auto-delete timer settings.
type AutoDeleteTimer struct {
Unixtime int `json:"message_auto_delete_time"`
}
// MessageEntity object represents "special" parts of text messages,

@ -151,6 +151,11 @@ const (
//
// Handler: func(*Message)
OnProximityAlert = "\aproximity_alert_triggered"
// Will fire on AudoDeleteTimer
//
// Handler: func(*Message)
OnAutoDeleteTimer = "\amessage_auto_delete_timer_changed"
)
// ChatAction is a client-side status indicating bot activity.

@ -60,6 +60,7 @@ func TestEmbedRights(t *testing.T) {
"can_pin_messages": false,
"can_promote_members": false,
"can_manage_voice_chats": false,
"can_manage_chat": false,
}
assert.Equal(t, expected, params)
}

Loading…
Cancel
Save