// Code generated by gotdgen, DO NOT EDIT. package tg import ( "context" "errors" "fmt" "sort" "strings" "go.uber.org/multierr" "go.mau.fi/mautrix-telegram/pkg/gotd/bin" "go.mau.fi/mautrix-telegram/pkg/gotd/tdjson" "go.mau.fi/mautrix-telegram/pkg/gotd/tdp" "go.mau.fi/mautrix-telegram/pkg/gotd/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{} ) // HelpPromoDataEmpty represents TL type `help.promoDataEmpty#98f6ac75`. // No PSA/MTProxy info is available // // See https://core.telegram.org/constructor/help.promoDataEmpty for reference. type HelpPromoDataEmpty struct { // Re-fetch PSA/MTProxy info after the specified number of seconds Expires int } // HelpPromoDataEmptyTypeID is TL type id of HelpPromoDataEmpty. const HelpPromoDataEmptyTypeID = 0x98f6ac75 // construct implements constructor of HelpPromoDataClass. func (p HelpPromoDataEmpty) construct() HelpPromoDataClass { return &p } // Ensuring interfaces in compile-time for HelpPromoDataEmpty. var ( _ bin.Encoder = &HelpPromoDataEmpty{} _ bin.Decoder = &HelpPromoDataEmpty{} _ bin.BareEncoder = &HelpPromoDataEmpty{} _ bin.BareDecoder = &HelpPromoDataEmpty{} _ HelpPromoDataClass = &HelpPromoDataEmpty{} ) func (p *HelpPromoDataEmpty) Zero() bool { if p == nil { return true } if !(p.Expires == 0) { return false } return true } // String implements fmt.Stringer. func (p *HelpPromoDataEmpty) String() string { if p == nil { return "HelpPromoDataEmpty(nil)" } type Alias HelpPromoDataEmpty return fmt.Sprintf("HelpPromoDataEmpty%+v", Alias(*p)) } // FillFrom fills HelpPromoDataEmpty from given interface. func (p *HelpPromoDataEmpty) FillFrom(from interface { GetExpires() (value int) }) { p.Expires = from.GetExpires() } // TypeID returns type id in TL schema. // // See https://core.telegram.org/mtproto/TL-tl#remarks. func (*HelpPromoDataEmpty) TypeID() uint32 { return HelpPromoDataEmptyTypeID } // TypeName returns name of type in TL schema. func (*HelpPromoDataEmpty) TypeName() string { return "help.promoDataEmpty" } // TypeInfo returns info about TL type. func (p *HelpPromoDataEmpty) TypeInfo() tdp.Type { typ := tdp.Type{ Name: "help.promoDataEmpty", ID: HelpPromoDataEmptyTypeID, } if p == nil { typ.Null = true return typ } typ.Fields = []tdp.Field{ { Name: "Expires", SchemaName: "expires", }, } return typ } // Encode implements bin.Encoder. func (p *HelpPromoDataEmpty) Encode(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't encode help.promoDataEmpty#98f6ac75 as nil") } b.PutID(HelpPromoDataEmptyTypeID) return p.EncodeBare(b) } // EncodeBare implements bin.BareEncoder. func (p *HelpPromoDataEmpty) EncodeBare(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't encode help.promoDataEmpty#98f6ac75 as nil") } b.PutInt(p.Expires) return nil } // Decode implements bin.Decoder. func (p *HelpPromoDataEmpty) Decode(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't decode help.promoDataEmpty#98f6ac75 to nil") } if err := b.ConsumeID(HelpPromoDataEmptyTypeID); err != nil { return fmt.Errorf("unable to decode help.promoDataEmpty#98f6ac75: %w", err) } return p.DecodeBare(b) } // DecodeBare implements bin.BareDecoder. func (p *HelpPromoDataEmpty) DecodeBare(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't decode help.promoDataEmpty#98f6ac75 to nil") } { value, err := b.Int() if err != nil { return fmt.Errorf("unable to decode help.promoDataEmpty#98f6ac75: field expires: %w", err) } p.Expires = value } return nil } // GetExpires returns value of Expires field. func (p *HelpPromoDataEmpty) GetExpires() (value int) { if p == nil { return } return p.Expires } // HelpPromoData represents TL type `help.promoData#8a4d87a`. // MTProxy/Public Service Announcement information // // See https://core.telegram.org/constructor/help.promoData for reference. type HelpPromoData struct { // Flags, see TL conditional fields¹ // // Links: // 1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields Flags bin.Fields // MTProxy-related channel Proxy bool // Expiry of PSA/MTProxy info Expires int // MTProxy/PSA peer // // Use SetPeer and GetPeer helpers. Peer PeerClass // PSA type // // Use SetPsaType and GetPsaType helpers. PsaType string // PSA message // // Use SetPsaMessage and GetPsaMessage helpers. PsaMessage string // PendingSuggestions field of HelpPromoData. PendingSuggestions []string // DismissedSuggestions field of HelpPromoData. DismissedSuggestions []string // CustomPendingSuggestion field of HelpPromoData. // // Use SetCustomPendingSuggestion and GetCustomPendingSuggestion helpers. CustomPendingSuggestion PendingSuggestion // Chat info Chats []ChatClass // User info Users []UserClass } // HelpPromoDataTypeID is TL type id of HelpPromoData. const HelpPromoDataTypeID = 0x8a4d87a // construct implements constructor of HelpPromoDataClass. func (p HelpPromoData) construct() HelpPromoDataClass { return &p } // Ensuring interfaces in compile-time for HelpPromoData. var ( _ bin.Encoder = &HelpPromoData{} _ bin.Decoder = &HelpPromoData{} _ bin.BareEncoder = &HelpPromoData{} _ bin.BareDecoder = &HelpPromoData{} _ HelpPromoDataClass = &HelpPromoData{} ) func (p *HelpPromoData) Zero() bool { if p == nil { return true } if !(p.Flags.Zero()) { return false } if !(p.Proxy == false) { return false } if !(p.Expires == 0) { return false } if !(p.Peer == nil) { return false } if !(p.PsaType == "") { return false } if !(p.PsaMessage == "") { return false } if !(p.PendingSuggestions == nil) { return false } if !(p.DismissedSuggestions == nil) { return false } if !(p.CustomPendingSuggestion.Zero()) { return false } if !(p.Chats == nil) { return false } if !(p.Users == nil) { return false } return true } // String implements fmt.Stringer. func (p *HelpPromoData) String() string { if p == nil { return "HelpPromoData(nil)" } type Alias HelpPromoData return fmt.Sprintf("HelpPromoData%+v", Alias(*p)) } // FillFrom fills HelpPromoData from given interface. func (p *HelpPromoData) FillFrom(from interface { GetProxy() (value bool) GetExpires() (value int) GetPeer() (value PeerClass, ok bool) GetPsaType() (value string, ok bool) GetPsaMessage() (value string, ok bool) GetPendingSuggestions() (value []string) GetDismissedSuggestions() (value []string) GetCustomPendingSuggestion() (value PendingSuggestion, ok bool) GetChats() (value []ChatClass) GetUsers() (value []UserClass) }) { p.Proxy = from.GetProxy() p.Expires = from.GetExpires() if val, ok := from.GetPeer(); ok { p.Peer = val } if val, ok := from.GetPsaType(); ok { p.PsaType = val } if val, ok := from.GetPsaMessage(); ok { p.PsaMessage = val } p.PendingSuggestions = from.GetPendingSuggestions() p.DismissedSuggestions = from.GetDismissedSuggestions() if val, ok := from.GetCustomPendingSuggestion(); ok { p.CustomPendingSuggestion = val } p.Chats = from.GetChats() p.Users = from.GetUsers() } // TypeID returns type id in TL schema. // // See https://core.telegram.org/mtproto/TL-tl#remarks. func (*HelpPromoData) TypeID() uint32 { return HelpPromoDataTypeID } // TypeName returns name of type in TL schema. func (*HelpPromoData) TypeName() string { return "help.promoData" } // TypeInfo returns info about TL type. func (p *HelpPromoData) TypeInfo() tdp.Type { typ := tdp.Type{ Name: "help.promoData", ID: HelpPromoDataTypeID, } if p == nil { typ.Null = true return typ } typ.Fields = []tdp.Field{ { Name: "Proxy", SchemaName: "proxy", Null: !p.Flags.Has(0), }, { Name: "Expires", SchemaName: "expires", }, { Name: "Peer", SchemaName: "peer", Null: !p.Flags.Has(3), }, { Name: "PsaType", SchemaName: "psa_type", Null: !p.Flags.Has(1), }, { Name: "PsaMessage", SchemaName: "psa_message", Null: !p.Flags.Has(2), }, { Name: "PendingSuggestions", SchemaName: "pending_suggestions", }, { Name: "DismissedSuggestions", SchemaName: "dismissed_suggestions", }, { Name: "CustomPendingSuggestion", SchemaName: "custom_pending_suggestion", Null: !p.Flags.Has(4), }, { Name: "Chats", SchemaName: "chats", }, { Name: "Users", SchemaName: "users", }, } return typ } // SetFlags sets flags for non-zero fields. func (p *HelpPromoData) SetFlags() { if !(p.Proxy == false) { p.Flags.Set(0) } if !(p.Peer == nil) { p.Flags.Set(3) } if !(p.PsaType == "") { p.Flags.Set(1) } if !(p.PsaMessage == "") { p.Flags.Set(2) } if !(p.CustomPendingSuggestion.Zero()) { p.Flags.Set(4) } } // Encode implements bin.Encoder. func (p *HelpPromoData) Encode(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't encode help.promoData#8a4d87a as nil") } b.PutID(HelpPromoDataTypeID) return p.EncodeBare(b) } // EncodeBare implements bin.BareEncoder. func (p *HelpPromoData) EncodeBare(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't encode help.promoData#8a4d87a as nil") } p.SetFlags() if err := p.Flags.Encode(b); err != nil { return fmt.Errorf("unable to encode help.promoData#8a4d87a: field flags: %w", err) } b.PutInt(p.Expires) if p.Flags.Has(3) { if p.Peer == nil { return fmt.Errorf("unable to encode help.promoData#8a4d87a: field peer is nil") } if err := p.Peer.Encode(b); err != nil { return fmt.Errorf("unable to encode help.promoData#8a4d87a: field peer: %w", err) } } if p.Flags.Has(1) { b.PutString(p.PsaType) } if p.Flags.Has(2) { b.PutString(p.PsaMessage) } b.PutVectorHeader(len(p.PendingSuggestions)) for _, v := range p.PendingSuggestions { b.PutString(v) } b.PutVectorHeader(len(p.DismissedSuggestions)) for _, v := range p.DismissedSuggestions { b.PutString(v) } if p.Flags.Has(4) { if err := p.CustomPendingSuggestion.Encode(b); err != nil { return fmt.Errorf("unable to encode help.promoData#8a4d87a: field custom_pending_suggestion: %w", err) } } b.PutVectorHeader(len(p.Chats)) for idx, v := range p.Chats { if v == nil { return fmt.Errorf("unable to encode help.promoData#8a4d87a: field chats element with index %d is nil", idx) } if err := v.Encode(b); err != nil { return fmt.Errorf("unable to encode help.promoData#8a4d87a: field chats element with index %d: %w", idx, err) } } b.PutVectorHeader(len(p.Users)) for idx, v := range p.Users { if v == nil { return fmt.Errorf("unable to encode help.promoData#8a4d87a: field users element with index %d is nil", idx) } if err := v.Encode(b); err != nil { return fmt.Errorf("unable to encode help.promoData#8a4d87a: field users element with index %d: %w", idx, err) } } return nil } // Decode implements bin.Decoder. func (p *HelpPromoData) Decode(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't decode help.promoData#8a4d87a to nil") } if err := b.ConsumeID(HelpPromoDataTypeID); err != nil { return fmt.Errorf("unable to decode help.promoData#8a4d87a: %w", err) } return p.DecodeBare(b) } // DecodeBare implements bin.BareDecoder. func (p *HelpPromoData) DecodeBare(b *bin.Buffer) error { if p == nil { return fmt.Errorf("can't decode help.promoData#8a4d87a to nil") } { if err := p.Flags.Decode(b); err != nil { return fmt.Errorf("unable to decode help.promoData#8a4d87a: field flags: %w", err) } } p.Proxy = p.Flags.Has(0) { value, err := b.Int() if err != nil { return fmt.Errorf("unable to decode help.promoData#8a4d87a: field expires: %w", err) } p.Expires = value } if p.Flags.Has(3) { value, err := DecodePeer(b) if err != nil { return fmt.Errorf("unable to decode help.promoData#8a4d87a: field peer: %w", err) } p.Peer = value } if p.Flags.Has(1) { value, err := b.String() if err != nil { return fmt.Errorf("unable to decode help.promoData#8a4d87a: field psa_type: %w", err) } p.PsaType = value } if p.Flags.Has(2) { value, err := b.String() if err != nil { return fmt.Errorf("unable to decode help.promoData#8a4d87a: field psa_message: %w", err) } p.PsaMessage = value } { headerLen, err := b.VectorHeader() if err != nil { return fmt.Errorf("unable to decode help.promoData#8a4d87a: field pending_suggestions: %w", err) } if headerLen > 0 { p.PendingSuggestions = make([]string, 0, headerLen%bin.PreallocateLimit) } for idx := 0; idx < headerLen; idx++ { value, err := b.String() if err != nil { return fmt.Errorf("unable to decode help.promoData#8a4d87a: field pending_suggestions: %w", err) } p.PendingSuggestions = append(p.PendingSuggestions, value) } } { headerLen, err := b.VectorHeader() if err != nil { return fmt.Errorf("unable to decode help.promoData#8a4d87a: field dismissed_suggestions: %w", err) } if headerLen > 0 { p.DismissedSuggestions = make([]string, 0, headerLen%bin.PreallocateLimit) } for idx := 0; idx < headerLen; idx++ { value, err := b.String() if err != nil { return fmt.Errorf("unable to decode help.promoData#8a4d87a: field dismissed_suggestions: %w", err) } p.DismissedSuggestions = append(p.DismissedSuggestions, value) } } if p.Flags.Has(4) { if err := p.CustomPendingSuggestion.Decode(b); err != nil { return fmt.Errorf("unable to decode help.promoData#8a4d87a: field custom_pending_suggestion: %w", err) } } { headerLen, err := b.VectorHeader() if err != nil { return fmt.Errorf("unable to decode help.promoData#8a4d87a: field chats: %w", err) } if headerLen > 0 { p.Chats = make([]ChatClass, 0, headerLen%bin.PreallocateLimit) } for idx := 0; idx < headerLen; idx++ { value, err := DecodeChat(b) if err != nil { return fmt.Errorf("unable to decode help.promoData#8a4d87a: field chats: %w", err) } p.Chats = append(p.Chats, value) } } { headerLen, err := b.VectorHeader() if err != nil { return fmt.Errorf("unable to decode help.promoData#8a4d87a: field users: %w", err) } if headerLen > 0 { p.Users = make([]UserClass, 0, headerLen%bin.PreallocateLimit) } for idx := 0; idx < headerLen; idx++ { value, err := DecodeUser(b) if err != nil { return fmt.Errorf("unable to decode help.promoData#8a4d87a: field users: %w", err) } p.Users = append(p.Users, value) } } return nil } // SetProxy sets value of Proxy conditional field. func (p *HelpPromoData) SetProxy(value bool) { if value { p.Flags.Set(0) p.Proxy = true } else { p.Flags.Unset(0) p.Proxy = false } } // GetProxy returns value of Proxy conditional field. func (p *HelpPromoData) GetProxy() (value bool) { if p == nil { return } return p.Flags.Has(0) } // GetExpires returns value of Expires field. func (p *HelpPromoData) GetExpires() (value int) { if p == nil { return } return p.Expires } // SetPeer sets value of Peer conditional field. func (p *HelpPromoData) SetPeer(value PeerClass) { p.Flags.Set(3) p.Peer = value } // GetPeer returns value of Peer conditional field and // boolean which is true if field was set. func (p *HelpPromoData) GetPeer() (value PeerClass, ok bool) { if p == nil { return } if !p.Flags.Has(3) { return value, false } return p.Peer, true } // SetPsaType sets value of PsaType conditional field. func (p *HelpPromoData) SetPsaType(value string) { p.Flags.Set(1) p.PsaType = value } // GetPsaType returns value of PsaType conditional field and // boolean which is true if field was set. func (p *HelpPromoData) GetPsaType() (value string, ok bool) { if p == nil { return } if !p.Flags.Has(1) { return value, false } return p.PsaType, true } // SetPsaMessage sets value of PsaMessage conditional field. func (p *HelpPromoData) SetPsaMessage(value string) { p.Flags.Set(2) p.PsaMessage = value } // GetPsaMessage returns value of PsaMessage conditional field and // boolean which is true if field was set. func (p *HelpPromoData) GetPsaMessage() (value string, ok bool) { if p == nil { return } if !p.Flags.Has(2) { return value, false } return p.PsaMessage, true } // GetPendingSuggestions returns value of PendingSuggestions field. func (p *HelpPromoData) GetPendingSuggestions() (value []string) { if p == nil { return } return p.PendingSuggestions } // GetDismissedSuggestions returns value of DismissedSuggestions field. func (p *HelpPromoData) GetDismissedSuggestions() (value []string) { if p == nil { return } return p.DismissedSuggestions } // SetCustomPendingSuggestion sets value of CustomPendingSuggestion conditional field. func (p *HelpPromoData) SetCustomPendingSuggestion(value PendingSuggestion) { p.Flags.Set(4) p.CustomPendingSuggestion = value } // GetCustomPendingSuggestion returns value of CustomPendingSuggestion conditional field and // boolean which is true if field was set. func (p *HelpPromoData) GetCustomPendingSuggestion() (value PendingSuggestion, ok bool) { if p == nil { return } if !p.Flags.Has(4) { return value, false } return p.CustomPendingSuggestion, true } // GetChats returns value of Chats field. func (p *HelpPromoData) GetChats() (value []ChatClass) { if p == nil { return } return p.Chats } // GetUsers returns value of Users field. func (p *HelpPromoData) GetUsers() (value []UserClass) { if p == nil { return } return p.Users } // MapChats returns field Chats wrapped in ChatClassArray helper. func (p *HelpPromoData) MapChats() (value ChatClassArray) { return ChatClassArray(p.Chats) } // MapUsers returns field Users wrapped in UserClassArray helper. func (p *HelpPromoData) MapUsers() (value UserClassArray) { return UserClassArray(p.Users) } // HelpPromoDataClassName is schema name of HelpPromoDataClass. const HelpPromoDataClassName = "help.PromoData" // HelpPromoDataClass represents help.PromoData generic type. // // See https://core.telegram.org/type/help.PromoData for reference. // // Example: // // g, err := tg.DecodeHelpPromoData(buf) // if err != nil { // panic(err) // } // switch v := g.(type) { // case *tg.HelpPromoDataEmpty: // help.promoDataEmpty#98f6ac75 // case *tg.HelpPromoData: // help.promoData#8a4d87a // default: panic(v) // } type HelpPromoDataClass interface { bin.Encoder bin.Decoder bin.BareEncoder bin.BareDecoder construct() HelpPromoDataClass // TypeID returns type id in TL schema. // // See https://core.telegram.org/mtproto/TL-tl#remarks. TypeID() uint32 // TypeName returns name of type in TL schema. TypeName() string // String implements fmt.Stringer. String() string // Zero returns true if current object has a zero value. Zero() bool // Re-fetch PSA/MTProxy info after the specified number of seconds GetExpires() (value int) // AsNotEmpty tries to map HelpPromoDataClass to HelpPromoData. AsNotEmpty() (*HelpPromoData, bool) } // AsNotEmpty tries to map HelpPromoDataEmpty to HelpPromoData. func (p *HelpPromoDataEmpty) AsNotEmpty() (*HelpPromoData, bool) { return nil, false } // AsNotEmpty tries to map HelpPromoData to HelpPromoData. func (p *HelpPromoData) AsNotEmpty() (*HelpPromoData, bool) { return p, true } // DecodeHelpPromoData implements binary de-serialization for HelpPromoDataClass. func DecodeHelpPromoData(buf *bin.Buffer) (HelpPromoDataClass, error) { id, err := buf.PeekID() if err != nil { return nil, err } switch id { case HelpPromoDataEmptyTypeID: // Decoding help.promoDataEmpty#98f6ac75. v := HelpPromoDataEmpty{} if err := v.Decode(buf); err != nil { return nil, fmt.Errorf("unable to decode HelpPromoDataClass: %w", err) } return &v, nil case HelpPromoDataTypeID: // Decoding help.promoData#8a4d87a. v := HelpPromoData{} if err := v.Decode(buf); err != nil { return nil, fmt.Errorf("unable to decode HelpPromoDataClass: %w", err) } return &v, nil default: return nil, fmt.Errorf("unable to decode HelpPromoDataClass: %w", bin.NewUnexpectedID(id)) } } // HelpPromoData boxes the HelpPromoDataClass providing a helper. type HelpPromoDataBox struct { PromoData HelpPromoDataClass } // Decode implements bin.Decoder for HelpPromoDataBox. func (b *HelpPromoDataBox) Decode(buf *bin.Buffer) error { if b == nil { return fmt.Errorf("unable to decode HelpPromoDataBox to nil") } v, err := DecodeHelpPromoData(buf) if err != nil { return fmt.Errorf("unable to decode boxed value: %w", err) } b.PromoData = v return nil } // Encode implements bin.Encode for HelpPromoDataBox. func (b *HelpPromoDataBox) Encode(buf *bin.Buffer) error { if b == nil || b.PromoData == nil { return fmt.Errorf("unable to encode HelpPromoDataClass as nil") } return b.PromoData.Encode(buf) }