forked from mail-ru-im/bot-golang
-
Notifications
You must be signed in to change notification settings - Fork 1
/
chat.go
131 lines (101 loc) · 3.19 KB
/
chat.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
package botgolang
//go:generate easyjson -all chat.go
type ChatAction = string
const (
TypingAction ChatAction = "typing"
LookingAction ChatAction = "looking"
)
type ChatType = string
const (
Private ChatType = "private"
Group ChatType = "group"
Channel ChatType = "channel"
)
type Chat struct {
client *Client
// Id of the chat
ID string `json:"chatId"`
// Type of the chat: channel, group or private
Type ChatType `json:"type"`
// First name of the user
FirstName string `json:"firstName"`
// Last name of the user
LastName string `json:"lastName"`
// Nick of the user
Nick string `json:"nick"`
// User about or group/channel description
About string `json:"about"`
// Rules of the group/channel
Rules string `json:"rules"`
// Title of the chat
Title string `json:"title"`
// Flag that indicates that requested chat is the bot
IsBot bool `json:"isBot"`
// Is this chat public?
Public bool `json:"public"`
// Is this chat has join moderation?
JoinModeration bool `json:"joinModeration"`
// You can send this link to all your friends
InviteLink string `json:"inviteLink"`
}
func (c *Chat) resolveID() string {
switch c.Type {
case Private:
return c.Nick
default:
return c.ID
}
}
// Send bot actions to the chat
//
// You can call this method every time you change the current actions,
// or every 10 seconds if the actions have not changed. After sending a
// request without active action, you should not re-notify of their absence.
func (c *Chat) SendActions(actions ...ChatAction) error {
return c.client.SendChatActions(c.resolveID(), actions...)
}
// Get chat administrators list
func (c *Chat) GetAdmins() ([]ChatMember, error) {
return c.client.GetChatAdmins(c.ID)
}
// Get chat members list
func (c *Chat) GetMembers() ([]ChatMember, error) {
return c.client.GetChatMembers(c.ID)
}
// Get chat blocked users list
func (c *Chat) GetBlockedUsers() ([]User, error) {
return c.client.GetChatBlockedUsers(c.ID)
}
// Get chat join pending users list
func (c *Chat) GetPendingUsers() ([]User, error) {
return c.client.GetChatPendingUsers(c.ID)
}
// Block user and remove him from chat.
// If deleteLastMessages is true, the messages written recently will be deleted
func (c *Chat) BlockUser(userID string, deleteLastMessages bool) error {
return c.client.BlockChatUser(c.ID, userID, deleteLastMessages)
}
// Unblock user in chat (but not add him back)
func (c *Chat) UnblockUser(userID string) error {
return c.client.UnblockChatUser(c.ID, userID)
}
// ResolveJoinRequest resolve specific user chat join request
func (c *Chat) ResolveJoinRequest(userID string, accept bool) error {
return c.client.ResolveChatPending(c.ID, userID, accept, false)
}
// ResolveAllJoinRequest resolve all chat join requests
func (c *Chat) ResolveAllJoinRequests(accept bool) error {
return c.client.ResolveChatPending(c.ID, "", accept, true)
}
// SetTitle changes chat title
func (c *Chat) SetTitle(title string) error {
return c.client.SetChatTitle(c.ID, title)
}
// SetAbout changes chat about
func (c *Chat) SetAbout(about string) error {
return c.client.SetChatAbout(c.ID, about)
}
// SetRules changes chat rules
func (c *Chat) SetRules(rules string) error {
return c.client.SetChatRules(c.ID, rules)
}