-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
tl_bot_info_gen.go
492 lines (451 loc) · 11.7 KB
/
tl_bot_info_gen.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
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// BotInfo represents TL type `botInfo#8f300b57`.
// Info about bots (available bot commands, etc)
//
// See https://core.telegram.org/constructor/botInfo for reference.
type BotInfo struct {
// Flags, see TL conditional fields¹
//
// Links:
// 1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
Flags bin.Fields
// ID of the bot
//
// Use SetUserID and GetUserID helpers.
UserID int64
// Description of the bot
//
// Use SetDescription and GetDescription helpers.
Description string
// Description photo
//
// Use SetDescriptionPhoto and GetDescriptionPhoto helpers.
DescriptionPhoto PhotoClass
// Description animation in MPEG4 format
//
// Use SetDescriptionDocument and GetDescriptionDocument helpers.
DescriptionDocument DocumentClass
// Bot commands that can be used in the chat
//
// Use SetCommands and GetCommands helpers.
Commands []BotCommand
// Indicates the action to execute when pressing the in-UI menu button for bots
//
// Use SetMenuButton and GetMenuButton helpers.
MenuButton BotMenuButtonClass
}
// BotInfoTypeID is TL type id of BotInfo.
const BotInfoTypeID = 0x8f300b57
// Ensuring interfaces in compile-time for BotInfo.
var (
_ bin.Encoder = &BotInfo{}
_ bin.Decoder = &BotInfo{}
_ bin.BareEncoder = &BotInfo{}
_ bin.BareDecoder = &BotInfo{}
)
func (b *BotInfo) Zero() bool {
if b == nil {
return true
}
if !(b.Flags.Zero()) {
return false
}
if !(b.UserID == 0) {
return false
}
if !(b.Description == "") {
return false
}
if !(b.DescriptionPhoto == nil) {
return false
}
if !(b.DescriptionDocument == nil) {
return false
}
if !(b.Commands == nil) {
return false
}
if !(b.MenuButton == nil) {
return false
}
return true
}
// String implements fmt.Stringer.
func (b *BotInfo) String() string {
if b == nil {
return "BotInfo(nil)"
}
type Alias BotInfo
return fmt.Sprintf("BotInfo%+v", Alias(*b))
}
// FillFrom fills BotInfo from given interface.
func (b *BotInfo) FillFrom(from interface {
GetUserID() (value int64, ok bool)
GetDescription() (value string, ok bool)
GetDescriptionPhoto() (value PhotoClass, ok bool)
GetDescriptionDocument() (value DocumentClass, ok bool)
GetCommands() (value []BotCommand, ok bool)
GetMenuButton() (value BotMenuButtonClass, ok bool)
}) {
if val, ok := from.GetUserID(); ok {
b.UserID = val
}
if val, ok := from.GetDescription(); ok {
b.Description = val
}
if val, ok := from.GetDescriptionPhoto(); ok {
b.DescriptionPhoto = val
}
if val, ok := from.GetDescriptionDocument(); ok {
b.DescriptionDocument = val
}
if val, ok := from.GetCommands(); ok {
b.Commands = val
}
if val, ok := from.GetMenuButton(); ok {
b.MenuButton = val
}
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*BotInfo) TypeID() uint32 {
return BotInfoTypeID
}
// TypeName returns name of type in TL schema.
func (*BotInfo) TypeName() string {
return "botInfo"
}
// TypeInfo returns info about TL type.
func (b *BotInfo) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "botInfo",
ID: BotInfoTypeID,
}
if b == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "UserID",
SchemaName: "user_id",
Null: !b.Flags.Has(0),
},
{
Name: "Description",
SchemaName: "description",
Null: !b.Flags.Has(1),
},
{
Name: "DescriptionPhoto",
SchemaName: "description_photo",
Null: !b.Flags.Has(4),
},
{
Name: "DescriptionDocument",
SchemaName: "description_document",
Null: !b.Flags.Has(5),
},
{
Name: "Commands",
SchemaName: "commands",
Null: !b.Flags.Has(2),
},
{
Name: "MenuButton",
SchemaName: "menu_button",
Null: !b.Flags.Has(3),
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (b *BotInfo) SetFlags() {
if !(b.UserID == 0) {
b.Flags.Set(0)
}
if !(b.Description == "") {
b.Flags.Set(1)
}
if !(b.DescriptionPhoto == nil) {
b.Flags.Set(4)
}
if !(b.DescriptionDocument == nil) {
b.Flags.Set(5)
}
if !(b.Commands == nil) {
b.Flags.Set(2)
}
if !(b.MenuButton == nil) {
b.Flags.Set(3)
}
}
// Encode implements bin.Encoder.
func (b *BotInfo) Encode(buf *bin.Buffer) error {
if b == nil {
return fmt.Errorf("can't encode botInfo#8f300b57 as nil")
}
buf.PutID(BotInfoTypeID)
return b.EncodeBare(buf)
}
// EncodeBare implements bin.BareEncoder.
func (b *BotInfo) EncodeBare(buf *bin.Buffer) error {
if b == nil {
return fmt.Errorf("can't encode botInfo#8f300b57 as nil")
}
b.SetFlags()
if err := b.Flags.Encode(buf); err != nil {
return fmt.Errorf("unable to encode botInfo#8f300b57: field flags: %w", err)
}
if b.Flags.Has(0) {
buf.PutLong(b.UserID)
}
if b.Flags.Has(1) {
buf.PutString(b.Description)
}
if b.Flags.Has(4) {
if b.DescriptionPhoto == nil {
return fmt.Errorf("unable to encode botInfo#8f300b57: field description_photo is nil")
}
if err := b.DescriptionPhoto.Encode(buf); err != nil {
return fmt.Errorf("unable to encode botInfo#8f300b57: field description_photo: %w", err)
}
}
if b.Flags.Has(5) {
if b.DescriptionDocument == nil {
return fmt.Errorf("unable to encode botInfo#8f300b57: field description_document is nil")
}
if err := b.DescriptionDocument.Encode(buf); err != nil {
return fmt.Errorf("unable to encode botInfo#8f300b57: field description_document: %w", err)
}
}
if b.Flags.Has(2) {
buf.PutVectorHeader(len(b.Commands))
for idx, v := range b.Commands {
if err := v.Encode(buf); err != nil {
return fmt.Errorf("unable to encode botInfo#8f300b57: field commands element with index %d: %w", idx, err)
}
}
}
if b.Flags.Has(3) {
if b.MenuButton == nil {
return fmt.Errorf("unable to encode botInfo#8f300b57: field menu_button is nil")
}
if err := b.MenuButton.Encode(buf); err != nil {
return fmt.Errorf("unable to encode botInfo#8f300b57: field menu_button: %w", err)
}
}
return nil
}
// Decode implements bin.Decoder.
func (b *BotInfo) Decode(buf *bin.Buffer) error {
if b == nil {
return fmt.Errorf("can't decode botInfo#8f300b57 to nil")
}
if err := buf.ConsumeID(BotInfoTypeID); err != nil {
return fmt.Errorf("unable to decode botInfo#8f300b57: %w", err)
}
return b.DecodeBare(buf)
}
// DecodeBare implements bin.BareDecoder.
func (b *BotInfo) DecodeBare(buf *bin.Buffer) error {
if b == nil {
return fmt.Errorf("can't decode botInfo#8f300b57 to nil")
}
{
if err := b.Flags.Decode(buf); err != nil {
return fmt.Errorf("unable to decode botInfo#8f300b57: field flags: %w", err)
}
}
if b.Flags.Has(0) {
value, err := buf.Long()
if err != nil {
return fmt.Errorf("unable to decode botInfo#8f300b57: field user_id: %w", err)
}
b.UserID = value
}
if b.Flags.Has(1) {
value, err := buf.String()
if err != nil {
return fmt.Errorf("unable to decode botInfo#8f300b57: field description: %w", err)
}
b.Description = value
}
if b.Flags.Has(4) {
value, err := DecodePhoto(buf)
if err != nil {
return fmt.Errorf("unable to decode botInfo#8f300b57: field description_photo: %w", err)
}
b.DescriptionPhoto = value
}
if b.Flags.Has(5) {
value, err := DecodeDocument(buf)
if err != nil {
return fmt.Errorf("unable to decode botInfo#8f300b57: field description_document: %w", err)
}
b.DescriptionDocument = value
}
if b.Flags.Has(2) {
headerLen, err := buf.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode botInfo#8f300b57: field commands: %w", err)
}
if headerLen > 0 {
b.Commands = make([]BotCommand, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
var value BotCommand
if err := value.Decode(buf); err != nil {
return fmt.Errorf("unable to decode botInfo#8f300b57: field commands: %w", err)
}
b.Commands = append(b.Commands, value)
}
}
if b.Flags.Has(3) {
value, err := DecodeBotMenuButton(buf)
if err != nil {
return fmt.Errorf("unable to decode botInfo#8f300b57: field menu_button: %w", err)
}
b.MenuButton = value
}
return nil
}
// SetUserID sets value of UserID conditional field.
func (b *BotInfo) SetUserID(value int64) {
b.Flags.Set(0)
b.UserID = value
}
// GetUserID returns value of UserID conditional field and
// boolean which is true if field was set.
func (b *BotInfo) GetUserID() (value int64, ok bool) {
if b == nil {
return
}
if !b.Flags.Has(0) {
return value, false
}
return b.UserID, true
}
// SetDescription sets value of Description conditional field.
func (b *BotInfo) SetDescription(value string) {
b.Flags.Set(1)
b.Description = value
}
// GetDescription returns value of Description conditional field and
// boolean which is true if field was set.
func (b *BotInfo) GetDescription() (value string, ok bool) {
if b == nil {
return
}
if !b.Flags.Has(1) {
return value, false
}
return b.Description, true
}
// SetDescriptionPhoto sets value of DescriptionPhoto conditional field.
func (b *BotInfo) SetDescriptionPhoto(value PhotoClass) {
b.Flags.Set(4)
b.DescriptionPhoto = value
}
// GetDescriptionPhoto returns value of DescriptionPhoto conditional field and
// boolean which is true if field was set.
func (b *BotInfo) GetDescriptionPhoto() (value PhotoClass, ok bool) {
if b == nil {
return
}
if !b.Flags.Has(4) {
return value, false
}
return b.DescriptionPhoto, true
}
// SetDescriptionDocument sets value of DescriptionDocument conditional field.
func (b *BotInfo) SetDescriptionDocument(value DocumentClass) {
b.Flags.Set(5)
b.DescriptionDocument = value
}
// GetDescriptionDocument returns value of DescriptionDocument conditional field and
// boolean which is true if field was set.
func (b *BotInfo) GetDescriptionDocument() (value DocumentClass, ok bool) {
if b == nil {
return
}
if !b.Flags.Has(5) {
return value, false
}
return b.DescriptionDocument, true
}
// SetCommands sets value of Commands conditional field.
func (b *BotInfo) SetCommands(value []BotCommand) {
b.Flags.Set(2)
b.Commands = value
}
// GetCommands returns value of Commands conditional field and
// boolean which is true if field was set.
func (b *BotInfo) GetCommands() (value []BotCommand, ok bool) {
if b == nil {
return
}
if !b.Flags.Has(2) {
return value, false
}
return b.Commands, true
}
// SetMenuButton sets value of MenuButton conditional field.
func (b *BotInfo) SetMenuButton(value BotMenuButtonClass) {
b.Flags.Set(3)
b.MenuButton = value
}
// GetMenuButton returns value of MenuButton conditional field and
// boolean which is true if field was set.
func (b *BotInfo) GetMenuButton() (value BotMenuButtonClass, ok bool) {
if b == nil {
return
}
if !b.Flags.Has(3) {
return value, false
}
return b.MenuButton, true
}
// GetDescriptionPhotoAsNotEmpty returns mapped value of DescriptionPhoto conditional field and
// boolean which is true if field was set.
func (b *BotInfo) GetDescriptionPhotoAsNotEmpty() (*Photo, bool) {
if value, ok := b.GetDescriptionPhoto(); ok {
return value.AsNotEmpty()
}
return nil, false
}
// GetDescriptionDocumentAsNotEmpty returns mapped value of DescriptionDocument conditional field and
// boolean which is true if field was set.
func (b *BotInfo) GetDescriptionDocumentAsNotEmpty() (*Document, bool) {
if value, ok := b.GetDescriptionDocument(); ok {
return value.AsNotEmpty()
}
return nil, false
}