-
-
Notifications
You must be signed in to change notification settings - Fork 116
/
tl_attach_menu_bot_gen.go
382 lines (351 loc) · 8.89 KB
/
tl_attach_menu_bot_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
// 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{}
)
// AttachMenuBot represents TL type `attachMenuBot#c8aa2cd2`.
// Represents a bot web app that can be launched from the attachment menu »¹
//
// Links:
// 1. https://core.telegram.org/api/bots/attach
//
// See https://core.telegram.org/constructor/attachMenuBot for reference.
type AttachMenuBot struct {
// Flags, see TL conditional fields¹
//
// Links:
// 1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
Flags bin.Fields
// Whether this bot attachment menu entry should be shown in the attachment menu (toggle
// using messages.toggleBotInAttachMenu¹)
//
// Links:
// 1) https://core.telegram.org/method/messages.toggleBotInAttachMenu
Inactive bool
// True, if the bot supports the "settings_button_pressed" event »¹
//
// Links:
// 1) https://core.telegram.org/api/bots/webapps#settings_button_pressed
HasSettings bool
// Bot ID
BotID int64
// Attachment menu item name
ShortName string
// List of peer types where this attachment should be shown
PeerTypes []AttachMenuPeerTypeClass
// Attachment menu icon
Icons []AttachMenuBotIcon
}
// AttachMenuBotTypeID is TL type id of AttachMenuBot.
const AttachMenuBotTypeID = 0xc8aa2cd2
// Ensuring interfaces in compile-time for AttachMenuBot.
var (
_ bin.Encoder = &AttachMenuBot{}
_ bin.Decoder = &AttachMenuBot{}
_ bin.BareEncoder = &AttachMenuBot{}
_ bin.BareDecoder = &AttachMenuBot{}
)
func (a *AttachMenuBot) Zero() bool {
if a == nil {
return true
}
if !(a.Flags.Zero()) {
return false
}
if !(a.Inactive == false) {
return false
}
if !(a.HasSettings == false) {
return false
}
if !(a.BotID == 0) {
return false
}
if !(a.ShortName == "") {
return false
}
if !(a.PeerTypes == nil) {
return false
}
if !(a.Icons == nil) {
return false
}
return true
}
// String implements fmt.Stringer.
func (a *AttachMenuBot) String() string {
if a == nil {
return "AttachMenuBot(nil)"
}
type Alias AttachMenuBot
return fmt.Sprintf("AttachMenuBot%+v", Alias(*a))
}
// FillFrom fills AttachMenuBot from given interface.
func (a *AttachMenuBot) FillFrom(from interface {
GetInactive() (value bool)
GetHasSettings() (value bool)
GetBotID() (value int64)
GetShortName() (value string)
GetPeerTypes() (value []AttachMenuPeerTypeClass)
GetIcons() (value []AttachMenuBotIcon)
}) {
a.Inactive = from.GetInactive()
a.HasSettings = from.GetHasSettings()
a.BotID = from.GetBotID()
a.ShortName = from.GetShortName()
a.PeerTypes = from.GetPeerTypes()
a.Icons = from.GetIcons()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*AttachMenuBot) TypeID() uint32 {
return AttachMenuBotTypeID
}
// TypeName returns name of type in TL schema.
func (*AttachMenuBot) TypeName() string {
return "attachMenuBot"
}
// TypeInfo returns info about TL type.
func (a *AttachMenuBot) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "attachMenuBot",
ID: AttachMenuBotTypeID,
}
if a == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Inactive",
SchemaName: "inactive",
Null: !a.Flags.Has(0),
},
{
Name: "HasSettings",
SchemaName: "has_settings",
Null: !a.Flags.Has(1),
},
{
Name: "BotID",
SchemaName: "bot_id",
},
{
Name: "ShortName",
SchemaName: "short_name",
},
{
Name: "PeerTypes",
SchemaName: "peer_types",
},
{
Name: "Icons",
SchemaName: "icons",
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (a *AttachMenuBot) SetFlags() {
if !(a.Inactive == false) {
a.Flags.Set(0)
}
if !(a.HasSettings == false) {
a.Flags.Set(1)
}
}
// Encode implements bin.Encoder.
func (a *AttachMenuBot) Encode(b *bin.Buffer) error {
if a == nil {
return fmt.Errorf("can't encode attachMenuBot#c8aa2cd2 as nil")
}
b.PutID(AttachMenuBotTypeID)
return a.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (a *AttachMenuBot) EncodeBare(b *bin.Buffer) error {
if a == nil {
return fmt.Errorf("can't encode attachMenuBot#c8aa2cd2 as nil")
}
a.SetFlags()
if err := a.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode attachMenuBot#c8aa2cd2: field flags: %w", err)
}
b.PutLong(a.BotID)
b.PutString(a.ShortName)
b.PutVectorHeader(len(a.PeerTypes))
for idx, v := range a.PeerTypes {
if v == nil {
return fmt.Errorf("unable to encode attachMenuBot#c8aa2cd2: field peer_types element with index %d is nil", idx)
}
if err := v.Encode(b); err != nil {
return fmt.Errorf("unable to encode attachMenuBot#c8aa2cd2: field peer_types element with index %d: %w", idx, err)
}
}
b.PutVectorHeader(len(a.Icons))
for idx, v := range a.Icons {
if err := v.Encode(b); err != nil {
return fmt.Errorf("unable to encode attachMenuBot#c8aa2cd2: field icons element with index %d: %w", idx, err)
}
}
return nil
}
// Decode implements bin.Decoder.
func (a *AttachMenuBot) Decode(b *bin.Buffer) error {
if a == nil {
return fmt.Errorf("can't decode attachMenuBot#c8aa2cd2 to nil")
}
if err := b.ConsumeID(AttachMenuBotTypeID); err != nil {
return fmt.Errorf("unable to decode attachMenuBot#c8aa2cd2: %w", err)
}
return a.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (a *AttachMenuBot) DecodeBare(b *bin.Buffer) error {
if a == nil {
return fmt.Errorf("can't decode attachMenuBot#c8aa2cd2 to nil")
}
{
if err := a.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode attachMenuBot#c8aa2cd2: field flags: %w", err)
}
}
a.Inactive = a.Flags.Has(0)
a.HasSettings = a.Flags.Has(1)
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode attachMenuBot#c8aa2cd2: field bot_id: %w", err)
}
a.BotID = value
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode attachMenuBot#c8aa2cd2: field short_name: %w", err)
}
a.ShortName = value
}
{
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode attachMenuBot#c8aa2cd2: field peer_types: %w", err)
}
if headerLen > 0 {
a.PeerTypes = make([]AttachMenuPeerTypeClass, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
value, err := DecodeAttachMenuPeerType(b)
if err != nil {
return fmt.Errorf("unable to decode attachMenuBot#c8aa2cd2: field peer_types: %w", err)
}
a.PeerTypes = append(a.PeerTypes, value)
}
}
{
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode attachMenuBot#c8aa2cd2: field icons: %w", err)
}
if headerLen > 0 {
a.Icons = make([]AttachMenuBotIcon, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
var value AttachMenuBotIcon
if err := value.Decode(b); err != nil {
return fmt.Errorf("unable to decode attachMenuBot#c8aa2cd2: field icons: %w", err)
}
a.Icons = append(a.Icons, value)
}
}
return nil
}
// SetInactive sets value of Inactive conditional field.
func (a *AttachMenuBot) SetInactive(value bool) {
if value {
a.Flags.Set(0)
a.Inactive = true
} else {
a.Flags.Unset(0)
a.Inactive = false
}
}
// GetInactive returns value of Inactive conditional field.
func (a *AttachMenuBot) GetInactive() (value bool) {
if a == nil {
return
}
return a.Flags.Has(0)
}
// SetHasSettings sets value of HasSettings conditional field.
func (a *AttachMenuBot) SetHasSettings(value bool) {
if value {
a.Flags.Set(1)
a.HasSettings = true
} else {
a.Flags.Unset(1)
a.HasSettings = false
}
}
// GetHasSettings returns value of HasSettings conditional field.
func (a *AttachMenuBot) GetHasSettings() (value bool) {
if a == nil {
return
}
return a.Flags.Has(1)
}
// GetBotID returns value of BotID field.
func (a *AttachMenuBot) GetBotID() (value int64) {
if a == nil {
return
}
return a.BotID
}
// GetShortName returns value of ShortName field.
func (a *AttachMenuBot) GetShortName() (value string) {
if a == nil {
return
}
return a.ShortName
}
// GetPeerTypes returns value of PeerTypes field.
func (a *AttachMenuBot) GetPeerTypes() (value []AttachMenuPeerTypeClass) {
if a == nil {
return
}
return a.PeerTypes
}
// GetIcons returns value of Icons field.
func (a *AttachMenuBot) GetIcons() (value []AttachMenuBotIcon) {
if a == nil {
return
}
return a.Icons
}
// MapPeerTypes returns field PeerTypes wrapped in AttachMenuPeerTypeClassArray helper.
func (a *AttachMenuBot) MapPeerTypes() (value AttachMenuPeerTypeClassArray) {
return AttachMenuPeerTypeClassArray(a.PeerTypes)
}