-
Notifications
You must be signed in to change notification settings - Fork 470
/
topic.go
184 lines (152 loc) · 4.93 KB
/
topic.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package telebot
import (
"encoding/json"
"strconv"
)
type Topic struct {
Name string `json:"name"`
IconColor int `json:"icon_color"`
IconCustomEmojiID string `json:"icon_custom_emoji_id"`
ThreadID int `json:"message_thread_id"`
}
// CreateTopic creates a topic in a forum supergroup chat.
func (b *Bot) CreateTopic(chat *Chat, topic *Topic) (*Topic, error) {
params := map[string]string{
"chat_id": chat.Recipient(),
"name": topic.Name,
}
if topic.IconColor != 0 {
params["icon_color"] = strconv.Itoa(topic.IconColor)
}
if topic.IconCustomEmojiID != "" {
params["icon_custom_emoji_id"] = topic.IconCustomEmojiID
}
data, err := b.Raw("createForumTopic", params)
if err != nil {
return nil, err
}
var resp struct {
Result *Topic
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return resp.Result, err
}
// EditTopic edits name and icon of a topic in a forum supergroup chat.
func (b *Bot) EditTopic(chat *Chat, topic *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
"message_thread_id": topic.ThreadID,
}
if topic.Name != "" {
params["name"] = topic.Name
}
if topic.IconCustomEmojiID != "" {
params["icon_custom_emoji_id"] = topic.IconCustomEmojiID
}
_, err := b.Raw("editForumTopic", params)
return err
}
// CloseTopic closes an open topic in a forum supergroup chat.
func (b *Bot) CloseTopic(chat *Chat, topic *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
"message_thread_id": topic.ThreadID,
}
_, err := b.Raw("closeForumTopic", params)
return err
}
// ReopenTopic reopens a closed topic in a forum supergroup chat.
func (b *Bot) ReopenTopic(chat *Chat, topic *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
"message_thread_id": topic.ThreadID,
}
_, err := b.Raw("reopenForumTopic", params)
return err
}
// DeleteTopic deletes a forum topic along with all its messages in a forum supergroup chat.
func (b *Bot) DeleteTopic(chat *Chat, topic *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
"message_thread_id": topic.ThreadID,
}
_, err := b.Raw("deleteForumTopic", params)
return err
}
// UnpinAllTopicMessages clears the list of pinned messages in a forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup.
func (b *Bot) UnpinAllTopicMessages(chat *Chat, topic *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
"message_thread_id": topic.ThreadID,
}
_, err := b.Raw("unpinAllForumTopicMessages", params)
return err
}
// TopicIconStickers gets custom emoji stickers, which can be used as a forum topic icon by any user.
func (b *Bot) TopicIconStickers() ([]Sticker, error) {
params := map[string]string{}
data, err := b.Raw("getForumTopicIconStickers", params)
if err != nil {
return nil, err
}
var resp struct {
Result []Sticker
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return resp.Result, nil
}
// EditGeneralTopic edits name of the 'General' topic in a forum supergroup chat.
func (b *Bot) EditGeneralTopic(chat *Chat, topic *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
"name": topic.Name,
}
_, err := b.Raw("editGeneralForumTopic", params)
return err
}
// CloseGeneralTopic closes an open 'General' topic in a forum supergroup chat.
func (b *Bot) CloseGeneralTopic(chat *Chat) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
}
_, err := b.Raw("closeGeneralForumTopic", params)
return err
}
// ReopenGeneralTopic reopens a closed 'General' topic in a forum supergroup chat.
func (b *Bot) ReopenGeneralTopic(chat *Chat) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
}
_, err := b.Raw("reopenGeneralForumTopic", params)
return err
}
// HideGeneralTopic hides the 'General' topic in a forum supergroup chat.
func (b *Bot) HideGeneralTopic(chat *Chat) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
}
_, err := b.Raw("hideGeneralForumTopic", params)
return err
}
// UnhideGeneralTopic unhides the 'General' topic in a forum supergroup chat.
func (b *Bot) UnhideGeneralTopic(chat *Chat) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
}
_, err := b.Raw("unhideGeneralForumTopic", params)
return err
}
// UnpinAllGeneralTopicMessages clears the list of pinned messages in a General forum topic.
// The bot must be an administrator in the chat for this to work and must have the
// can_pin_messages administrator right in the supergroup.
func (b *Bot) UnpinAllGeneralTopicMessages(chat *Chat) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
}
_, err := b.Raw("unpinAllGeneralForumTopicMessages", params)
return err
}