-
-
Notifications
You must be signed in to change notification settings - Fork 121
/
tl_messages_export_chat_invite_gen.go
429 lines (393 loc) · 11 KB
/
tl_messages_export_chat_invite_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
// 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{}
)
// MessagesExportChatInviteRequest represents TL type `messages.exportChatInvite#a02ce5d5`.
// Export an invite link for a chat
//
// See https://core.telegram.org/method/messages.exportChatInvite for reference.
type MessagesExportChatInviteRequest struct {
// Flags, see TL conditional fields¹
//
// Links:
// 1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
Flags bin.Fields
// Legacy flag, reproducing legacy behavior of this method: if set, revokes all previous
// links before creating a new one. Kept for bot API BC, should not be used by modern
// clients.
LegacyRevokePermanent bool
// Whether admin confirmation is required before admitting each separate user into the
// chat
RequestNeeded bool
// Chat
Peer InputPeerClass
// Expiration date
//
// Use SetExpireDate and GetExpireDate helpers.
ExpireDate int
// Maximum number of users that can join using this link
//
// Use SetUsageLimit and GetUsageLimit helpers.
UsageLimit int
// Description of the invite link, visible only to administrators
//
// Use SetTitle and GetTitle helpers.
Title string
}
// MessagesExportChatInviteRequestTypeID is TL type id of MessagesExportChatInviteRequest.
const MessagesExportChatInviteRequestTypeID = 0xa02ce5d5
// Ensuring interfaces in compile-time for MessagesExportChatInviteRequest.
var (
_ bin.Encoder = &MessagesExportChatInviteRequest{}
_ bin.Decoder = &MessagesExportChatInviteRequest{}
_ bin.BareEncoder = &MessagesExportChatInviteRequest{}
_ bin.BareDecoder = &MessagesExportChatInviteRequest{}
)
func (e *MessagesExportChatInviteRequest) Zero() bool {
if e == nil {
return true
}
if !(e.Flags.Zero()) {
return false
}
if !(e.LegacyRevokePermanent == false) {
return false
}
if !(e.RequestNeeded == false) {
return false
}
if !(e.Peer == nil) {
return false
}
if !(e.ExpireDate == 0) {
return false
}
if !(e.UsageLimit == 0) {
return false
}
if !(e.Title == "") {
return false
}
return true
}
// String implements fmt.Stringer.
func (e *MessagesExportChatInviteRequest) String() string {
if e == nil {
return "MessagesExportChatInviteRequest(nil)"
}
type Alias MessagesExportChatInviteRequest
return fmt.Sprintf("MessagesExportChatInviteRequest%+v", Alias(*e))
}
// FillFrom fills MessagesExportChatInviteRequest from given interface.
func (e *MessagesExportChatInviteRequest) FillFrom(from interface {
GetLegacyRevokePermanent() (value bool)
GetRequestNeeded() (value bool)
GetPeer() (value InputPeerClass)
GetExpireDate() (value int, ok bool)
GetUsageLimit() (value int, ok bool)
GetTitle() (value string, ok bool)
}) {
e.LegacyRevokePermanent = from.GetLegacyRevokePermanent()
e.RequestNeeded = from.GetRequestNeeded()
e.Peer = from.GetPeer()
if val, ok := from.GetExpireDate(); ok {
e.ExpireDate = val
}
if val, ok := from.GetUsageLimit(); ok {
e.UsageLimit = val
}
if val, ok := from.GetTitle(); ok {
e.Title = val
}
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*MessagesExportChatInviteRequest) TypeID() uint32 {
return MessagesExportChatInviteRequestTypeID
}
// TypeName returns name of type in TL schema.
func (*MessagesExportChatInviteRequest) TypeName() string {
return "messages.exportChatInvite"
}
// TypeInfo returns info about TL type.
func (e *MessagesExportChatInviteRequest) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "messages.exportChatInvite",
ID: MessagesExportChatInviteRequestTypeID,
}
if e == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "LegacyRevokePermanent",
SchemaName: "legacy_revoke_permanent",
Null: !e.Flags.Has(2),
},
{
Name: "RequestNeeded",
SchemaName: "request_needed",
Null: !e.Flags.Has(3),
},
{
Name: "Peer",
SchemaName: "peer",
},
{
Name: "ExpireDate",
SchemaName: "expire_date",
Null: !e.Flags.Has(0),
},
{
Name: "UsageLimit",
SchemaName: "usage_limit",
Null: !e.Flags.Has(1),
},
{
Name: "Title",
SchemaName: "title",
Null: !e.Flags.Has(4),
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (e *MessagesExportChatInviteRequest) SetFlags() {
if !(e.LegacyRevokePermanent == false) {
e.Flags.Set(2)
}
if !(e.RequestNeeded == false) {
e.Flags.Set(3)
}
if !(e.ExpireDate == 0) {
e.Flags.Set(0)
}
if !(e.UsageLimit == 0) {
e.Flags.Set(1)
}
if !(e.Title == "") {
e.Flags.Set(4)
}
}
// Encode implements bin.Encoder.
func (e *MessagesExportChatInviteRequest) Encode(b *bin.Buffer) error {
if e == nil {
return fmt.Errorf("can't encode messages.exportChatInvite#a02ce5d5 as nil")
}
b.PutID(MessagesExportChatInviteRequestTypeID)
return e.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (e *MessagesExportChatInviteRequest) EncodeBare(b *bin.Buffer) error {
if e == nil {
return fmt.Errorf("can't encode messages.exportChatInvite#a02ce5d5 as nil")
}
e.SetFlags()
if err := e.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode messages.exportChatInvite#a02ce5d5: field flags: %w", err)
}
if e.Peer == nil {
return fmt.Errorf("unable to encode messages.exportChatInvite#a02ce5d5: field peer is nil")
}
if err := e.Peer.Encode(b); err != nil {
return fmt.Errorf("unable to encode messages.exportChatInvite#a02ce5d5: field peer: %w", err)
}
if e.Flags.Has(0) {
b.PutInt(e.ExpireDate)
}
if e.Flags.Has(1) {
b.PutInt(e.UsageLimit)
}
if e.Flags.Has(4) {
b.PutString(e.Title)
}
return nil
}
// Decode implements bin.Decoder.
func (e *MessagesExportChatInviteRequest) Decode(b *bin.Buffer) error {
if e == nil {
return fmt.Errorf("can't decode messages.exportChatInvite#a02ce5d5 to nil")
}
if err := b.ConsumeID(MessagesExportChatInviteRequestTypeID); err != nil {
return fmt.Errorf("unable to decode messages.exportChatInvite#a02ce5d5: %w", err)
}
return e.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (e *MessagesExportChatInviteRequest) DecodeBare(b *bin.Buffer) error {
if e == nil {
return fmt.Errorf("can't decode messages.exportChatInvite#a02ce5d5 to nil")
}
{
if err := e.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode messages.exportChatInvite#a02ce5d5: field flags: %w", err)
}
}
e.LegacyRevokePermanent = e.Flags.Has(2)
e.RequestNeeded = e.Flags.Has(3)
{
value, err := DecodeInputPeer(b)
if err != nil {
return fmt.Errorf("unable to decode messages.exportChatInvite#a02ce5d5: field peer: %w", err)
}
e.Peer = value
}
if e.Flags.Has(0) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode messages.exportChatInvite#a02ce5d5: field expire_date: %w", err)
}
e.ExpireDate = value
}
if e.Flags.Has(1) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode messages.exportChatInvite#a02ce5d5: field usage_limit: %w", err)
}
e.UsageLimit = value
}
if e.Flags.Has(4) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode messages.exportChatInvite#a02ce5d5: field title: %w", err)
}
e.Title = value
}
return nil
}
// SetLegacyRevokePermanent sets value of LegacyRevokePermanent conditional field.
func (e *MessagesExportChatInviteRequest) SetLegacyRevokePermanent(value bool) {
if value {
e.Flags.Set(2)
e.LegacyRevokePermanent = true
} else {
e.Flags.Unset(2)
e.LegacyRevokePermanent = false
}
}
// GetLegacyRevokePermanent returns value of LegacyRevokePermanent conditional field.
func (e *MessagesExportChatInviteRequest) GetLegacyRevokePermanent() (value bool) {
if e == nil {
return
}
return e.Flags.Has(2)
}
// SetRequestNeeded sets value of RequestNeeded conditional field.
func (e *MessagesExportChatInviteRequest) SetRequestNeeded(value bool) {
if value {
e.Flags.Set(3)
e.RequestNeeded = true
} else {
e.Flags.Unset(3)
e.RequestNeeded = false
}
}
// GetRequestNeeded returns value of RequestNeeded conditional field.
func (e *MessagesExportChatInviteRequest) GetRequestNeeded() (value bool) {
if e == nil {
return
}
return e.Flags.Has(3)
}
// GetPeer returns value of Peer field.
func (e *MessagesExportChatInviteRequest) GetPeer() (value InputPeerClass) {
if e == nil {
return
}
return e.Peer
}
// SetExpireDate sets value of ExpireDate conditional field.
func (e *MessagesExportChatInviteRequest) SetExpireDate(value int) {
e.Flags.Set(0)
e.ExpireDate = value
}
// GetExpireDate returns value of ExpireDate conditional field and
// boolean which is true if field was set.
func (e *MessagesExportChatInviteRequest) GetExpireDate() (value int, ok bool) {
if e == nil {
return
}
if !e.Flags.Has(0) {
return value, false
}
return e.ExpireDate, true
}
// SetUsageLimit sets value of UsageLimit conditional field.
func (e *MessagesExportChatInviteRequest) SetUsageLimit(value int) {
e.Flags.Set(1)
e.UsageLimit = value
}
// GetUsageLimit returns value of UsageLimit conditional field and
// boolean which is true if field was set.
func (e *MessagesExportChatInviteRequest) GetUsageLimit() (value int, ok bool) {
if e == nil {
return
}
if !e.Flags.Has(1) {
return value, false
}
return e.UsageLimit, true
}
// SetTitle sets value of Title conditional field.
func (e *MessagesExportChatInviteRequest) SetTitle(value string) {
e.Flags.Set(4)
e.Title = value
}
// GetTitle returns value of Title conditional field and
// boolean which is true if field was set.
func (e *MessagesExportChatInviteRequest) GetTitle() (value string, ok bool) {
if e == nil {
return
}
if !e.Flags.Has(4) {
return value, false
}
return e.Title, true
}
// MessagesExportChatInvite invokes method messages.exportChatInvite#a02ce5d5 returning error if any.
// Export an invite link for a chat
//
// Possible errors:
//
// 400 CHANNEL_PRIVATE: You haven't joined this channel/supergroup.
// 400 CHAT_ADMIN_REQUIRED: You must be an admin in this chat to do this.
// 400 CHAT_ID_INVALID: The provided chat id is invalid.
// 403 CHAT_WRITE_FORBIDDEN: You can't write in this chat.
// 400 EXPIRE_DATE_INVALID: The specified expiration date is invalid.
// 400 PEER_ID_INVALID: The provided peer id is invalid.
// 400 USAGE_LIMIT_INVALID: The specified usage limit is invalid.
//
// See https://core.telegram.org/method/messages.exportChatInvite for reference.
// Can be used by bots.
func (c *Client) MessagesExportChatInvite(ctx context.Context, request *MessagesExportChatInviteRequest) (ExportedChatInviteClass, error) {
var result ExportedChatInviteBox
if err := c.rpc.Invoke(ctx, request, &result); err != nil {
return nil, err
}
return result.ExportedChatInvite, nil
}