-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsendtypes.go
534 lines (454 loc) · 11.5 KB
/
sendtypes.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
package tgbot
import (
"errors"
"io"
"io/ioutil"
)
// Send general construct to generate send actions
type Send struct {
ChatID int
Bot *TgBot
}
// Text return a SendText instance to chain actions easy
func (s *Send) Text(text string) *SendText {
return &SendText{s, text, nil, nil, nil, nil}
}
// Forward return a SendForward instance to chain actions easy
func (s *Send) Forward(to int, msg int) *SendForward {
return &SendForward{s, to, msg}
}
// Photo return a SendPhoto instance to chain actions easy
func (s *Send) Photo(photo interface{}) *SendPhoto {
// Check here that the interface works?
return &SendPhoto{s, photo, nil, nil, nil}
}
// Audio return a SendAudio instance to chain actions easy
func (s *Send) Audio(audio string) *SendAudio {
return &SendAudio{s, audio, nil, nil, nil, nil, nil}
}
// Voice return a SendVoice instance to chain actions easy
func (s *Send) Voice(voice string) *SendVoice {
return &SendVoice{s, voice, nil, nil, nil}
}
// Document return a SendDocument instance to chain actions easy
func (s *Send) Document(doc interface{}) *SendDocument {
return &SendDocument{s, doc, nil, nil}
}
// Sticker return a SendSticker instance to chain actions easy
func (s *Send) Sticker(stick interface{}) *SendSticker {
return &SendSticker{s, stick, nil, nil}
}
// Video return a SendVideo instance to chain actions easy
func (s *Send) Video(vid string) *SendVideo {
return &SendVideo{s, vid, nil, nil, nil, nil}
}
// Location return a SendLocation instance to chain actions easy
func (s *Send) Location(latitude float64, long float64) *SendLocation {
return &SendLocation{s, latitude, long, nil, nil}
}
// Action return a SendAction instance to chain actions easy
func (s *Send) Action(action ChatAction) *SendChatAction {
return &SendChatAction{s, action}
}
// SendText ...
type SendText struct {
Send *Send
Text string
ParseModeS *ParseModeT
DisableWebPagePreview *bool
ReplyToMessageID *int
ReplyMarkup *ReplyMarkupInt
}
func (sp *SendText) ParseMode(pm ParseModeT) *SendText {
sp.ParseModeS = &pm
return sp
}
// DisablePreview ...
func (sp *SendText) DisablePreview(disab bool) *SendText {
sp.DisableWebPagePreview = &disab
return sp
}
// ReplyToMessage ...
func (sp *SendText) ReplyToMessage(rm int) *SendText {
sp.ReplyToMessageID = &rm
return sp
}
// Keyboard ...
func (sp *SendText) Keyboard(kb ReplyKeyboardMarkup) *SendText {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// KeyboardHide ...
func (sp *SendText) KeyboardHide(kb ReplyKeyboardHide) *SendText {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// ForceReply ...
func (sp *SendText) ForceReply(fr ForceReply) *SendText {
var rmi ReplyMarkupInt = fr
sp.ReplyMarkup = &rmi
return sp
}
// End ...
func (sp SendText) End() ResultWithMessage {
return sp.Send.Bot.SendMessage(sp.Send.ChatID, sp.Text, sp.ParseModeS, sp.DisableWebPagePreview, sp.ReplyToMessageID, sp.ReplyMarkup)
}
// SendForward ...
type SendForward struct {
Send *Send
to int
msg int
}
// End ...
func (sf *SendForward) End() ResultWithMessage {
return sf.Send.Bot.ForwardMessage(sf.Send.ChatID, sf.to, sf.msg)
}
// SendPhoto ...
type SendPhoto struct {
Send *Send
Photo interface{}
CaptionField *string
ReplyToMessageID *int
ReplyMarkup *ReplyMarkupInt
}
// Caption ...
func (sp *SendPhoto) Caption(caption string) *SendPhoto {
sp.CaptionField = &caption
return sp
}
// ReplyToMessage ...
func (sp *SendPhoto) ReplyToMessage(rm int) *SendPhoto {
sp.ReplyToMessageID = &rm
return sp
}
// Keyboard ...
func (sp *SendPhoto) Keyboard(kb ReplyKeyboardMarkup) *SendPhoto {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// KeyboardHide ...
func (sp *SendPhoto) KeyboardHide(kb ReplyKeyboardHide) *SendPhoto {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// ForceReply ...
func (sp *SendPhoto) ForceReply(fr ForceReply) *SendPhoto {
var rmi ReplyMarkupInt = fr
sp.ReplyMarkup = &rmi
return sp
}
// End ...
func (sp SendPhoto) End() ResultWithMessage {
return sp.Send.Bot.SendPhoto(sp.Send.ChatID, sp.Photo, sp.CaptionField, sp.ReplyToMessageID, sp.ReplyMarkup)
}
// SendAudio ...
type SendAudio struct {
Send *Send
Audio string
DurationField *int
PerformerField *string
TitleField *string
ReplyToMessageID *int
ReplyMarkup *ReplyMarkupInt
}
// Duration ...
func (sp *SendAudio) Duration(d int) *SendAudio {
sp.DurationField = &d
return sp
}
// Performer ...
func (sp *SendAudio) Performer(p string) *SendAudio {
sp.PerformerField = &p
return sp
}
// Title ...
func (sp *SendAudio) Title(d string) *SendAudio {
sp.TitleField = &d
return sp
}
// ReplyToMessage ...
func (sp *SendAudio) ReplyToMessage(rm int) *SendAudio {
sp.ReplyToMessageID = &rm
return sp
}
// Keyboard ...
func (sp *SendAudio) Keyboard(kb ReplyKeyboardMarkup) *SendAudio {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// KeyboardHide ...
func (sp *SendAudio) KeyboardHide(kb ReplyKeyboardHide) *SendAudio {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// ForceReply ...
func (sp *SendAudio) ForceReply(fr ForceReply) *SendAudio {
var rmi ReplyMarkupInt = fr
sp.ReplyMarkup = &rmi
return sp
}
// End ...
func (sp SendAudio) End() ResultWithMessage {
return sp.Send.Bot.SendAudio(sp.Send.ChatID,
sp.Audio,
sp.DurationField,
sp.PerformerField,
sp.TitleField,
sp.ReplyToMessageID,
sp.ReplyMarkup)
}
// SendVoice ...
type SendVoice struct {
Send *Send
Voice string
DurationField *int
ReplyToMessageID *int
ReplyMarkup *ReplyMarkupInt
}
// Duration ...
func (sp *SendVoice) Duration(d int) *SendVoice {
sp.DurationField = &d
return sp
}
// ReplyToMessage ...
func (sp *SendVoice) ReplyToMessage(rm int) *SendVoice {
sp.ReplyToMessageID = &rm
return sp
}
// Keyboard ...
func (sp *SendVoice) Keyboard(kb ReplyKeyboardMarkup) *SendVoice {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// KeyboardHide ...
func (sp *SendVoice) KeyboardHide(kb ReplyKeyboardHide) *SendVoice {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// ForceReply ...
func (sp *SendVoice) ForceReply(fr ForceReply) *SendVoice {
var rmi ReplyMarkupInt = fr
sp.ReplyMarkup = &rmi
return sp
}
// End ...
func (sp SendVoice) End() ResultWithMessage {
return sp.Send.Bot.SendVoice(sp.Send.ChatID, sp.Voice, sp.DurationField, sp.ReplyToMessageID, sp.ReplyMarkup)
}
// SendDocument ...
type SendDocument struct {
Send *Send
Document interface{}
ReplyToMessageID *int
ReplyMarkup *ReplyMarkupInt
}
// ReplyToMessage ...
func (sp *SendDocument) ReplyToMessage(rm int) *SendDocument {
sp.ReplyToMessageID = &rm
return sp
}
// Keyboard ...
func (sp *SendDocument) Keyboard(kb ReplyKeyboardMarkup) *SendDocument {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// KeyboardHide ...
func (sp *SendDocument) KeyboardHide(kb ReplyKeyboardHide) *SendDocument {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// ForceReply ...
func (sp *SendDocument) ForceReply(fr ForceReply) *SendDocument {
var rmi ReplyMarkupInt = fr
sp.ReplyMarkup = &rmi
return sp
}
// End ...
func (sp SendDocument) End() ResultWithMessage {
return sp.Send.Bot.SendDocument(sp.Send.ChatID, sp.Document, sp.ReplyToMessageID, sp.ReplyMarkup)
}
// SendSticker ...
type SendSticker struct {
Send *Send
Sticker interface{}
ReplyToMessageID *int
ReplyMarkup *ReplyMarkupInt
}
// ReplyToMessage ...
func (sp *SendSticker) ReplyToMessage(rm int) *SendSticker {
sp.ReplyToMessageID = &rm
return sp
}
// Keyboard ...
func (sp *SendSticker) Keyboard(kb ReplyKeyboardMarkup) *SendSticker {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// KeyboardHide ...
func (sp *SendSticker) KeyboardHide(kb ReplyKeyboardHide) *SendSticker {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// ForceReply ...
func (sp *SendSticker) ForceReply(fr ForceReply) *SendSticker {
var rmi ReplyMarkupInt = fr
sp.ReplyMarkup = &rmi
return sp
}
// End ...
func (sp SendSticker) End() ResultWithMessage {
return sp.Send.Bot.SendSticker(sp.Send.ChatID, sp.Sticker, sp.ReplyToMessageID, sp.ReplyMarkup)
}
// SendVideo ...
type SendVideo struct {
Send *Send
Video string
CaptionField *string
DurationField *int
ReplyToMessageID *int
ReplyMarkup *ReplyMarkupInt
}
// ReplyToMessage ...
func (sp *SendVideo) ReplyToMessage(rm int) *SendVideo {
sp.ReplyToMessageID = &rm
return sp
}
// Caption ...
func (sp *SendVideo) Caption(cap string) *SendVideo {
sp.CaptionField = &cap
return sp
}
// Duration ...
func (sp *SendVideo) Duration(dur int) *SendVideo {
sp.DurationField = &dur
return sp
}
// Keyboard ...
func (sp *SendVideo) Keyboard(kb ReplyKeyboardMarkup) *SendVideo {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// KeyboardHide ...
func (sp *SendVideo) KeyboardHide(kb ReplyKeyboardHide) *SendVideo {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// ForceReply ...
func (sp *SendVideo) ForceReply(fr ForceReply) *SendVideo {
var rmi ReplyMarkupInt = fr
sp.ReplyMarkup = &rmi
return sp
}
// End ...
func (sp SendVideo) End() ResultWithMessage {
return sp.Send.Bot.SendVideo(sp.Send.ChatID, sp.Video, sp.CaptionField, sp.DurationField, sp.ReplyToMessageID, sp.ReplyMarkup)
}
// SendLocation ...
type SendLocation struct {
Send *Send
Latitude float64
Longitude float64
ReplyToMessageID *int
ReplyMarkup *ReplyMarkupInt
}
// SetLatitude ...
func (sp *SendLocation) SetLatitude(lat float64) *SendLocation {
sp.Latitude = lat
return sp
}
// SetLongitude ...
func (sp *SendLocation) SetLongitude(long float64) *SendLocation {
sp.Longitude = long
return sp
}
// ReplyToMessage ...
func (sp *SendLocation) ReplyToMessage(rm int) *SendLocation {
sp.ReplyToMessageID = &rm
return sp
}
// Keyboard ...
func (sp *SendLocation) Keyboard(kb ReplyKeyboardMarkup) *SendLocation {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// KeyboardHide ...
func (sp *SendLocation) KeyboardHide(kb ReplyKeyboardHide) *SendLocation {
var rmi ReplyMarkupInt = kb
sp.ReplyMarkup = &rmi
return sp
}
// ForceReply ...
func (sp *SendLocation) ForceReply(fr ForceReply) *SendLocation {
var rmi ReplyMarkupInt = fr
sp.ReplyMarkup = &rmi
return sp
}
// End ...
func (sp SendLocation) End() ResultWithMessage {
return sp.Send.Bot.SendLocation(sp.Send.ChatID, sp.Latitude, sp.Longitude, sp.ReplyToMessageID, sp.ReplyMarkup)
}
// SendChatAction ...
type SendChatAction struct {
Send *Send
Action ChatAction
}
// SetAction ...
func (sca *SendChatAction) SetAction(act ChatAction) *SendChatAction {
sca.Action = act
return sca
}
// End ...
func (sca SendChatAction) End() {
sca.Send.Bot.SendChatAction(sca.Send.ChatID, sca.Action)
}
// SendGetFile ...
type SendGetFile struct {
Bot *TgBot
ID string
}
func (self SendGetFile) ToPath(path string) error {
body, err := self.ToReader()
if err != nil {
return err
}
defer body.Close()
bodyb, err := ioutil.ReadAll(body)
if err != nil {
return err
}
err = ioutil.WriteFile(path, bodyb, 0644)
if err != nil {
return err
}
return nil
}
func (self SendGetFile) ToReader() (io.ReadCloser, error) {
res := self.Bot.GetFile(self.ID)
if !res.Ok || res.Result == nil {
msg := ""
if res.Description != nil {
msg = *res.Description
}
return nil, errors.New(msg)
}
fpath := res.Result.Path
return self.Bot.DownloadFilePathReader(fpath)
}
func (sgf SendGetFile) End() {
sgf.Bot.GetFile(sgf.ID)
}