2022-04-26 00:02:51 +08:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2022-04-29 17:21:42 +08:00
|
|
|
// ChatMemberUpdated https://core.telegram.org/bots/api#chatmemberupdated
|
2022-04-26 00:02:51 +08:00
|
|
|
type ChatMemberUpdated struct {
|
2023-04-24 14:11:48 +08:00
|
|
|
Chat Chat `json:"chat"`
|
|
|
|
From User `json:"from"`
|
|
|
|
Date int `json:"date"`
|
|
|
|
OldChatMember ChatMember `json:"old_chat_member"`
|
|
|
|
NewChatMember ChatMember `json:"new_chat_member"`
|
|
|
|
InviteLink *ChatInviteLink `json:"invite_link,omitempty"`
|
2024-05-20 17:07:43 +08:00
|
|
|
ViaJoinRequest bool `json:"via_join_request,omitempty"`
|
2023-04-24 14:11:48 +08:00
|
|
|
ViaChatFolderInviteLink bool `json:"via_chat_folder_invite_link,omitempty"`
|
2022-04-26 00:02:51 +08:00
|
|
|
}
|
|
|
|
|
2024-05-22 22:14:55 +08:00
|
|
|
type ChatMemberType string
|
2022-04-26 00:02:51 +08:00
|
|
|
|
|
|
|
const (
|
2024-05-22 22:14:55 +08:00
|
|
|
ChatMemberTypeOwner ChatMemberType = "creator"
|
|
|
|
ChatMemberTypeAdministrator ChatMemberType = "administrator"
|
|
|
|
ChatMemberTypeMember ChatMemberType = "member"
|
|
|
|
ChatMemberTypeRestricted ChatMemberType = "restricted"
|
|
|
|
ChatMemberTypeLeft ChatMemberType = "left"
|
|
|
|
ChatMemberTypeBanned ChatMemberType = "kicked"
|
2022-04-26 00:02:51 +08:00
|
|
|
)
|
|
|
|
|
2022-04-29 17:21:42 +08:00
|
|
|
// ChatMember https://core.telegram.org/bots/api#chatmember
|
2022-04-26 00:02:51 +08:00
|
|
|
type ChatMember struct {
|
|
|
|
Type ChatMemberType
|
|
|
|
|
|
|
|
Owner *ChatMemberOwner
|
|
|
|
Administrator *ChatMemberAdministrator
|
|
|
|
Member *ChatMemberMember
|
|
|
|
Restricted *ChatMemberRestricted
|
|
|
|
Left *ChatMemberLeft
|
|
|
|
Banned *ChatMemberBanned
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ChatMember) UnmarshalJSON(data []byte) error {
|
2024-01-10 20:16:04 +08:00
|
|
|
v := struct {
|
2024-05-22 22:14:55 +08:00
|
|
|
Status ChatMemberType `json:"status"`
|
2024-01-10 20:16:04 +08:00
|
|
|
}{}
|
|
|
|
if err := json.Unmarshal(data, &v); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
switch v.Status {
|
2024-05-22 22:14:55 +08:00
|
|
|
case ChatMemberTypeOwner:
|
2022-04-26 00:02:51 +08:00
|
|
|
c.Type = ChatMemberTypeOwner
|
|
|
|
c.Owner = &ChatMemberOwner{}
|
|
|
|
return json.Unmarshal(data, c.Owner)
|
2024-05-22 22:14:55 +08:00
|
|
|
case ChatMemberTypeAdministrator:
|
2022-04-26 00:02:51 +08:00
|
|
|
c.Type = ChatMemberTypeAdministrator
|
|
|
|
c.Administrator = &ChatMemberAdministrator{}
|
|
|
|
return json.Unmarshal(data, c.Administrator)
|
2024-05-22 22:14:55 +08:00
|
|
|
case ChatMemberTypeMember:
|
2022-04-26 00:02:51 +08:00
|
|
|
c.Type = ChatMemberTypeMember
|
|
|
|
c.Member = &ChatMemberMember{}
|
|
|
|
return json.Unmarshal(data, c.Member)
|
2024-05-22 22:14:55 +08:00
|
|
|
case ChatMemberTypeRestricted:
|
2022-04-26 00:02:51 +08:00
|
|
|
c.Type = ChatMemberTypeRestricted
|
|
|
|
c.Restricted = &ChatMemberRestricted{}
|
|
|
|
return json.Unmarshal(data, c.Restricted)
|
2024-05-22 22:14:55 +08:00
|
|
|
case ChatMemberTypeLeft:
|
2022-04-26 00:02:51 +08:00
|
|
|
c.Type = ChatMemberTypeLeft
|
|
|
|
c.Left = &ChatMemberLeft{}
|
|
|
|
return json.Unmarshal(data, c.Left)
|
2024-05-22 22:14:55 +08:00
|
|
|
case ChatMemberTypeBanned:
|
2022-04-26 00:02:51 +08:00
|
|
|
c.Type = ChatMemberTypeBanned
|
|
|
|
c.Banned = &ChatMemberBanned{}
|
|
|
|
return json.Unmarshal(data, c.Banned)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("unsupported ChatMember type")
|
|
|
|
}
|
|
|
|
|
2024-05-22 22:14:55 +08:00
|
|
|
func (c *ChatMember) MarshalJSON() ([]byte, error) {
|
|
|
|
switch c.Type {
|
|
|
|
case ChatMemberTypeOwner:
|
|
|
|
c.Owner.Status = ChatMemberTypeOwner
|
|
|
|
return json.Marshal(c.Owner)
|
|
|
|
case ChatMemberTypeAdministrator:
|
|
|
|
c.Administrator.Status = ChatMemberTypeAdministrator
|
|
|
|
return json.Marshal(c.Administrator)
|
|
|
|
case ChatMemberTypeMember:
|
|
|
|
c.Member.Status = ChatMemberTypeMember
|
|
|
|
return json.Marshal(c.Member)
|
|
|
|
case ChatMemberTypeRestricted:
|
|
|
|
c.Restricted.Status = ChatMemberTypeRestricted
|
|
|
|
return json.Marshal(c.Restricted)
|
|
|
|
case ChatMemberTypeLeft:
|
|
|
|
c.Left.Status = ChatMemberTypeLeft
|
|
|
|
return json.Marshal(c.Left)
|
|
|
|
case ChatMemberTypeBanned:
|
|
|
|
c.Banned.Status = ChatMemberTypeBanned
|
|
|
|
return json.Marshal(c.Banned)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("unsupported ChatMember type")
|
|
|
|
}
|
|
|
|
|
2022-04-29 17:21:42 +08:00
|
|
|
// ChatMemberOwner https://core.telegram.org/bots/api#chatmemberowner
|
2022-04-26 00:02:51 +08:00
|
|
|
type ChatMemberOwner struct {
|
2024-05-22 22:14:55 +08:00
|
|
|
Status ChatMemberType `json:"status"` // The member's status in the chat, always “creator”
|
|
|
|
User *User `json:"user"`
|
|
|
|
IsAnonymous bool `json:"is_anonymous"`
|
|
|
|
CustomTitle string `json:"custom_title,omitempty"`
|
2022-04-26 00:02:51 +08:00
|
|
|
}
|
|
|
|
|
2022-04-29 17:21:42 +08:00
|
|
|
// ChatMemberAdministrator https://core.telegram.org/bots/api#chatmemberadministrator
|
2022-04-26 00:02:51 +08:00
|
|
|
type ChatMemberAdministrator struct {
|
2024-05-22 22:14:55 +08:00
|
|
|
Status ChatMemberType `json:"status"` // The member's status in the chat, always “administrator”
|
|
|
|
User User `json:"user"`
|
|
|
|
CanBeEdited bool `json:"can_be_edited"`
|
|
|
|
IsAnonymous bool `json:"is_anonymous"`
|
|
|
|
CanManageChat bool `json:"can_manage_chat"`
|
|
|
|
CanDeleteMessages bool `json:"can_delete_messages"`
|
|
|
|
CanManageVideoChats bool `json:"can_manage_video_chats"`
|
|
|
|
CanRestrictMembers bool `json:"can_restrict_members"`
|
|
|
|
CanPromoteMembers bool `json:"can_promote_members"`
|
|
|
|
CanChangeInfo bool `json:"can_change_info"`
|
|
|
|
CanInviteUsers bool `json:"can_invite_users"`
|
|
|
|
CanPostMessages bool `json:"can_post_messages,omitempty"`
|
|
|
|
CanEditMessages bool `json:"can_edit_messages,omitempty"`
|
|
|
|
CanPinMessages bool `json:"can_pin_messages,omitempty"`
|
|
|
|
CanPostStories bool `json:"can_post_stories,omitempty"`
|
|
|
|
CanEditStories bool `json:"can_edit_stories,omitempty"`
|
|
|
|
CanDeleteStories bool `json:"can_delete_stories,omitempty"`
|
|
|
|
CanManageTopics bool `json:"can_manage_topics,omitempty"`
|
|
|
|
CustomTitle string `json:"custom_title,omitempty"`
|
2022-04-26 00:02:51 +08:00
|
|
|
}
|
|
|
|
|
2022-04-29 17:21:42 +08:00
|
|
|
// ChatMemberMember https://core.telegram.org/bots/api#chatmembermember
|
2022-04-26 00:02:51 +08:00
|
|
|
type ChatMemberMember struct {
|
2024-08-14 21:43:42 +08:00
|
|
|
Status ChatMemberType `json:"status"` // The member's status in the chat, always “member”
|
|
|
|
User *User `json:"user"`
|
|
|
|
UntilDate int `json:"until_date,omitempty"`
|
2022-04-26 00:02:51 +08:00
|
|
|
}
|
|
|
|
|
2022-04-29 17:21:42 +08:00
|
|
|
// ChatMemberRestricted https://core.telegram.org/bots/api#chatmemberrestricted
|
2022-04-26 00:02:51 +08:00
|
|
|
type ChatMemberRestricted struct {
|
2024-05-22 22:14:55 +08:00
|
|
|
Status ChatMemberType `json:"status"` // The member's status in the chat, always “restricted”
|
|
|
|
User *User `json:"user"`
|
|
|
|
IsMember bool `json:"is_member"`
|
|
|
|
CanSendMessages bool `json:"can_send_messages"`
|
|
|
|
CanSendAudios bool `json:"can_send_audios"`
|
|
|
|
CanSendDocuments bool `json:"can_send_documents"`
|
|
|
|
CanSendPhotos bool `json:"can_send_photos"`
|
|
|
|
CanSendVideos bool `json:"can_send_videos"`
|
|
|
|
CanSendVideoNotes bool `json:"can_send_video_notes"`
|
|
|
|
CanSendVoiceNotes bool `json:"can_send_voice_notes"`
|
|
|
|
CanSendPolls bool `json:"can_send_polls"`
|
|
|
|
CanSendOtherMessages bool `json:"can_send_other_messages"`
|
|
|
|
CanAddWebPagePreviews bool `json:"can_add_web_page_previews"`
|
|
|
|
CanChangeInfo bool `json:"can_change_info"`
|
|
|
|
CanInviteUsers bool `json:"can_invite_users"`
|
|
|
|
CanPinMessages bool `json:"can_pin_messages"`
|
|
|
|
CanManageTopics bool `json:"can_manage_topics,omitempty"`
|
|
|
|
UntilDate int `json:"until_date"`
|
2022-04-26 00:02:51 +08:00
|
|
|
}
|
|
|
|
|
2022-04-29 17:21:42 +08:00
|
|
|
// ChatMemberLeft https://core.telegram.org/bots/api#chatmemberleft
|
2022-04-26 00:02:51 +08:00
|
|
|
type ChatMemberLeft struct {
|
2024-05-22 22:14:55 +08:00
|
|
|
Status ChatMemberType `json:"status"` // The member's status in the chat, always “left”
|
|
|
|
User *User `json:"user"`
|
2022-04-26 00:02:51 +08:00
|
|
|
}
|
|
|
|
|
2022-04-29 17:21:42 +08:00
|
|
|
// ChatMemberBanned https://core.telegram.org/bots/api#chatmemberbanned
|
2022-04-26 00:02:51 +08:00
|
|
|
type ChatMemberBanned struct {
|
2024-05-22 22:14:55 +08:00
|
|
|
Status ChatMemberType `json:"status"` // The member's status in the chat, always “kicked”
|
|
|
|
User *User `json:"user"`
|
|
|
|
UntilDate int `json:"until_date"`
|
2022-04-26 00:02:51 +08:00
|
|
|
}
|