-
Notifications
You must be signed in to change notification settings - Fork 26
/
stickers.go
271 lines (221 loc) · 10.3 KB
/
stickers.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*
* Echotron
* Copyright (C) 2018 The Echotron Contributors
*
* Echotron is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Echotron is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package echotron
import (
"encoding/json"
"net/url"
)
// Sticker represents a sticker.
type Sticker struct {
Thumbnail *PhotoSize `json:"thumbnail,omitempty"`
MaskPosition *MaskPosition `json:"mask_position,omitempty"`
Type StickerSetType `json:"type"`
FileUniqueID string `json:"file_unique_id"`
SetName string `json:"set_name,omitempty"`
FileID string `json:"file_id"`
Emoji string `json:"emoji,omitempty"`
CustomEmojiID string `json:"custom_emoji_id,omitempty"`
PremiumAnimation File `json:"premium_animation,omitempty"`
FileSize int `json:"file_size,omitempty"`
Width int `json:"width"`
Height int `json:"height"`
IsVideo bool `json:"is_video"`
IsAnimated bool `json:"is_animated"`
NeedsRepainting bool `json:"needs_repainting,omitempty"`
}
// StickerSet represents a sticker set.
type StickerSet struct {
Thumbnail *PhotoSize `json:"thumbnail,omitempty"`
Title string `json:"title"`
Name string `json:"name"`
StickerType StickerSetType `json:"sticker_type"`
Stickers []Sticker `json:"stickers"`
}
// StickerSetType represents the type of a sticker or of the entire set
type StickerSetType string
const (
RegularStickerSet StickerSetType = "regular"
MaskStickerSet = "mask"
CustomEmojiStickerSet = "custom_emoji"
)
// StickerFormat is a custom type for the various sticker formats.
type StickerFormat string
// These are all the possible sticker formats.
const (
StaticFormat StickerFormat = "static"
AnimatedFormat = "animated"
VideoFormat = "video"
)
// MaskPosition describes the position on faces where a mask should be placed by default.
type MaskPosition struct {
Point MaskPoint `json:"point"`
XShift float32 `json:"x_shift"`
YShift float32 `json:"y_shift"`
Scale float32 `json:"scale"`
}
// MaskPoint is a custom type for the various part of face where a mask should be placed.
type MaskPoint string
// These are all the possible parts of the face for a mask.
const (
ForeheadPoint MaskPoint = "forehead"
EyesPoint = "eyes"
MouthPoint = "mouth"
ChinPoint = "chin"
)
// NewStickerSetOptions contains the optional parameters used in the CreateNewStickerSet method.
type NewStickerSetOptions struct {
StickerType StickerSetType `query:"sticker_type"`
NeedsRepainting bool `query:"needs_repainting"`
}
// InputSticker is a struct which describes a sticker to be added to a sticker set.
type InputSticker struct {
MaskPosition *MaskPosition `json:"mask_position,omitempty"`
Keywords *[]string `json:"keywords,omitempty"`
Format StickerFormat `json:"format"`
Sticker InputFile `json:"-"`
EmojiList []string `json:"emoji_list"`
}
// stickerEnvelope is a generic struct for all the various structs under the InputSticker interface.
type stickerEnvelope struct {
Sticker string `json:"sticker"`
InputSticker
}
// SendSticker is used to send static .WEBP or animated .TGS stickers.
func (a API) SendSticker(stickerID string, chatID int64, opts *StickerOptions) (res APIResponseMessage, err error) {
var vals = make(url.Values)
vals.Set("sticker", stickerID)
vals.Set("chat_id", itoa(chatID))
return res, client.get(a.base, "sendSticker", addValues(vals, opts), &res)
}
// GetStickerSet is used to get a sticker set.
func (a API) GetStickerSet(name string) (res APIResponseStickerSet, err error) {
var vals = make(url.Values)
vals.Set("name", name)
return res, client.get(a.base, "getStickerSet", vals, &res)
}
// GetCustomEmojiStickers is used to get information about custom emoji stickers by their identifiers.
func (a API) GetCustomEmojiStickers(customEmojiIDs ...string) (res APIResponseStickers, err error) {
var vals = make(url.Values)
jsn, _ := json.Marshal(customEmojiIDs)
vals.Set("custom_emoji_ids", string(jsn))
return res, client.get(a.base, "getCustomEmojiStickers", vals, &res)
}
// UploadStickerFile is used to upload a .PNG file with a sticker for later use in
// CreateNewStickerSet and AddStickerToSet methods (can be used multiple times).
func (a API) UploadStickerFile(userID int64, sticker InputFile, format StickerFormat) (res APIResponseFile, err error) {
var vals = make(url.Values)
vals.Set("user_id", itoa(userID))
vals.Set("sticker_format", string(format))
return res, client.postFile(a.base, "uploadStickerFile", "sticker", sticker, InputFile{}, vals, &res)
}
// CreateNewStickerSet is used to create a new sticker set owned by a user.
func (a API) CreateNewStickerSet(userID int64, name, title string, stickers []InputSticker, opts *NewStickerSetOptions) (res APIResponseBool, err error) {
var vals = make(url.Values)
vals.Set("user_id", itoa(userID))
vals.Set("name", name)
vals.Set("title", title)
return res, client.postStickers(a.base, "createNewStickerSet", addValues(vals, opts), &res, stickers...)
}
// AddStickerToSet is used to add a new sticker to a set created by the bot.
func (a API) AddStickerToSet(userID int64, name string, sticker InputSticker) (res APIResponseBool, err error) {
var vals = make(url.Values)
vals.Set("user_id", itoa(userID))
vals.Set("name", name)
return res, client.postStickers(a.base, "addStickerToSet", vals, &res, sticker)
}
// SetStickerPositionInSet is used to move a sticker in a set created by the bot to a specific position.
func (a API) SetStickerPositionInSet(sticker string, position int) (res APIResponseBase, err error) {
var vals = make(url.Values)
vals.Set("sticker", sticker)
vals.Set("position", itoa(int64(position)))
return res, client.get(a.base, "setStickerPositionInSet", vals, &res)
}
// DeleteStickerFromSet is used to delete a sticker from a set created by the bot.
func (a API) DeleteStickerFromSet(sticker string) (res APIResponseBase, err error) {
var vals = make(url.Values)
vals.Set("sticker", sticker)
return res, client.get(a.base, "deleteStickerFromSet", vals, &res)
}
// ReplaceStickerInSet is used to replace an existing sticker in a sticker set with a new one.
// The method is equivalent to calling DeleteStickerFromSet, then AddStickerToSet, then SetStickerPositionInSet.
func (a API) ReplaceStickerInSet(userID int64, name string, old_sticker string, sticker InputSticker) (res APIResponseBool, err error) {
var vals = make(url.Values)
vals.Set("user_id", itoa(userID))
vals.Set("name", name)
vals.Set("old_sticker", old_sticker)
return res, client.postStickers(a.base, "replaceStickerInSet", vals, &res, sticker)
}
// SetStickerEmojiList is used to change the list of emoji assigned to a regular or custom emoji sticker.
// The sticker must belong to a sticker set created by the bot.
func (a API) SetStickerEmojiList(sticker string, emojis []string) (res APIResponseBool, err error) {
var vals = make(url.Values)
jsn, _ := json.Marshal(emojis)
vals.Set("sticker", sticker)
vals.Set("emoji_list", string(jsn))
return res, client.get(a.base, "setStickerEmojiList", vals, &res)
}
// SetStickerKeywords is used to change search keywords assigned to a regular or custom emoji sticker.
// The sticker must belong to a sticker set created by the bot.
func (a API) SetStickerKeywords(sticker string, keywords []string) (res APIResponseBool, err error) {
var vals = make(url.Values)
jsn, _ := json.Marshal(keywords)
vals.Set("sticker", sticker)
vals.Set("keywords", string(jsn))
return res, client.get(a.base, "setStickerKeywords", vals, &res)
}
// SetStickerMaskPosition is used to change the mask position of a mask sticker.
// The sticker must belong to a sticker set that was created by the bot.
func (a API) SetStickerMaskPosition(sticker string, mask MaskPosition) (res APIResponseBool, err error) {
var vals = make(url.Values)
jsn, _ := json.Marshal(mask)
vals.Set("sticker", sticker)
vals.Set("mask_position", string(jsn))
return res, client.get(a.base, "setStickerMaskPosition", vals, &res)
}
// SetStickerSetTitle is used to set the title of a created sticker set.
func (a API) SetStickerSetTitle(name, title string) (res APIResponseBool, err error) {
var vals = make(url.Values)
vals.Set("name", name)
vals.Set("title", title)
return res, client.get(a.base, "setStickerSetTitle", vals, &res)
}
// SetStickerSetThumbnail is used to set the thumbnail of a sticker set.
func (a API) SetStickerSetThumbnail(name string, userID int64, thumbnail InputFile, format StickerFormat) (res APIResponseBase, err error) {
var vals = make(url.Values)
vals.Set("name", name)
vals.Set("user_id", itoa(userID))
vals.Set("format", string(format))
return res, client.postFile(a.base, "setStickerSetThumbnail", "thumbnail", thumbnail, InputFile{}, vals, &res)
}
// SetCustomEmojiStickerSetThumbnail is used to set the thumbnail of a custom emoji sticker set.
func (a API) SetCustomEmojiStickerSetThumbnail(name, emojiID string) (res APIResponseBool, err error) {
var vals = make(url.Values)
vals.Set("name", name)
vals.Set("custom_emoji_id", emojiID)
return res, client.get(a.base, "setCustomEmojiStickerSetThumbnail", vals, &res)
}
// DeleteStickerSet is used to delete a sticker set that was created by the bot.
func (a API) DeleteStickerSet(name string) (res APIResponseBool, err error) {
var vals = make(url.Values)
vals.Set("name", name)
return res, client.get(a.base, "DeleteStickerSet", vals, &res)
}
// GetForumTopicIconStickers is used to get custom emoji stickers, which can be used as a forum topic icon by any user.
func (a API) GetForumTopicIconStickers() (res APIResponseStickers, err error) {
return res, client.get(a.base, "getForumTopicIconStickers", nil, &res)
}