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"
)
var (
_ = bin .Buffer {}
_ = context .Background ()
_ = fmt .Stringer (nil )
_ = strings .Builder {}
_ = errors .Is
_ = multierr .AppendInto
_ = sort .Ints
_ = tdp .Format
_ = tgerr .Error {}
_ = tdjson .Encoder {}
)
type BotInfo struct {
Flags bin .Fields
UserID int64
Description string
DescriptionPhoto PhotoClass
DescriptionDocument DocumentClass
Commands []BotCommand
MenuButton BotMenuButtonClass
}
const BotInfoTypeID = 0x8f300b57
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
}
func (b *BotInfo ) String () string {
if b == nil {
return "BotInfo(nil)"
}
type Alias BotInfo
return fmt .Sprintf ("BotInfo%+v" , Alias (*b ))
}
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
}
}
func (*BotInfo ) TypeID () uint32 {
return BotInfoTypeID
}
func (*BotInfo ) TypeName () string {
return "botInfo"
}
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
}
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 )
}
}
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 )
}
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
}
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 )
}
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
}
func (b *BotInfo ) SetUserID (value int64 ) {
b .Flags .Set (0 )
b .UserID = value
}
func (b *BotInfo ) GetUserID () (value int64 , ok bool ) {
if b == nil {
return
}
if !b .Flags .Has (0 ) {
return value , false
}
return b .UserID , true
}
func (b *BotInfo ) SetDescription (value string ) {
b .Flags .Set (1 )
b .Description = value
}
func (b *BotInfo ) GetDescription () (value string , ok bool ) {
if b == nil {
return
}
if !b .Flags .Has (1 ) {
return value , false
}
return b .Description , true
}
func (b *BotInfo ) SetDescriptionPhoto (value PhotoClass ) {
b .Flags .Set (4 )
b .DescriptionPhoto = value
}
func (b *BotInfo ) GetDescriptionPhoto () (value PhotoClass , ok bool ) {
if b == nil {
return
}
if !b .Flags .Has (4 ) {
return value , false
}
return b .DescriptionPhoto , true
}
func (b *BotInfo ) SetDescriptionDocument (value DocumentClass ) {
b .Flags .Set (5 )
b .DescriptionDocument = value
}
func (b *BotInfo ) GetDescriptionDocument () (value DocumentClass , ok bool ) {
if b == nil {
return
}
if !b .Flags .Has (5 ) {
return value , false
}
return b .DescriptionDocument , true
}
func (b *BotInfo ) SetCommands (value []BotCommand ) {
b .Flags .Set (2 )
b .Commands = value
}
func (b *BotInfo ) GetCommands () (value []BotCommand , ok bool ) {
if b == nil {
return
}
if !b .Flags .Has (2 ) {
return value , false
}
return b .Commands , true
}
func (b *BotInfo ) SetMenuButton (value BotMenuButtonClass ) {
b .Flags .Set (3 )
b .MenuButton = value
}
func (b *BotInfo ) GetMenuButton () (value BotMenuButtonClass , ok bool ) {
if b == nil {
return
}
if !b .Flags .Has (3 ) {
return value , false
}
return b .MenuButton , true
}
func (b *BotInfo ) GetDescriptionPhotoAsNotEmpty () (*Photo , bool ) {
if value , ok := b .GetDescriptionPhoto (); ok {
return value .AsNotEmpty ()
}
return nil , false
}
func (b *BotInfo ) GetDescriptionDocumentAsNotEmpty () (*Document , bool ) {
if value , ok := b .GetDescriptionDocument (); ok {
return value .AsNotEmpty ()
}
return nil , false
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .