forked from go-telegram/bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat_member.go
150 lines (135 loc) · 5.51 KB
/
chat_member.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package models
import (
"encoding/json"
"fmt"
)
// ChatMemberUpdated https://core.telegram.org/bots/api#chatmemberupdated
type ChatMemberUpdated struct {
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"`
ViaChatFolderInviteLink bool `json:"via_chat_folder_invite_link,omitempty"`
}
type ChatMemberType int
const (
ChatMemberTypeOwner ChatMemberType = iota
ChatMemberTypeAdministrator
ChatMemberTypeMember
ChatMemberTypeRestricted
ChatMemberTypeLeft
ChatMemberTypeBanned
)
// ChatMember https://core.telegram.org/bots/api#chatmember
type ChatMember struct {
Type ChatMemberType
Owner *ChatMemberOwner
Administrator *ChatMemberAdministrator
Member *ChatMemberMember
Restricted *ChatMemberRestricted
Left *ChatMemberLeft
Banned *ChatMemberBanned
}
func (c *ChatMember) UnmarshalJSON(data []byte) error {
v := struct {
Status string `json:"status"`
}{}
if err := json.Unmarshal(data, &v); err != nil {
return err
}
switch v.Status {
case "creator":
c.Type = ChatMemberTypeOwner
c.Owner = &ChatMemberOwner{}
return json.Unmarshal(data, c.Owner)
case "administrator":
c.Type = ChatMemberTypeAdministrator
c.Administrator = &ChatMemberAdministrator{}
return json.Unmarshal(data, c.Administrator)
case "member":
c.Type = ChatMemberTypeMember
c.Member = &ChatMemberMember{}
return json.Unmarshal(data, c.Member)
case "restricted":
c.Type = ChatMemberTypeRestricted
c.Restricted = &ChatMemberRestricted{}
return json.Unmarshal(data, c.Restricted)
case "left":
c.Type = ChatMemberTypeLeft
c.Left = &ChatMemberLeft{}
return json.Unmarshal(data, c.Left)
case "kicked":
c.Type = ChatMemberTypeBanned
c.Banned = &ChatMemberBanned{}
return json.Unmarshal(data, c.Banned)
}
return fmt.Errorf("unsupported ChatMember type")
}
// ChatMemberOwner https://core.telegram.org/bots/api#chatmemberowner
type ChatMemberOwner struct {
Status string `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"`
}
// ChatMemberAdministrator https://core.telegram.org/bots/api#chatmemberadministrator
type ChatMemberAdministrator struct {
Status string `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"`
}
// ChatMemberMember https://core.telegram.org/bots/api#chatmembermember
type ChatMemberMember struct {
Status string `json:"status"` // The member's status in the chat, always “member”
User *User `json:"user"`
}
// ChatMemberRestricted https://core.telegram.org/bots/api#chatmemberrestricted
type ChatMemberRestricted struct {
Status string `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"`
}
// ChatMemberLeft https://core.telegram.org/bots/api#chatmemberleft
type ChatMemberLeft struct {
Status string `json:"status"` // The member's status in the chat, always “left”
User *User `json:"user"`
}
// ChatMemberBanned https://core.telegram.org/bots/api#chatmemberbanned
type ChatMemberBanned struct {
Status string `json:"status"` // The member's status in the chat, always “kicked”
User *User `json:"user"`
UntilDate int `json:"until_date"`
}