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 BotsSetBotCommandsRequest struct {
Scope BotCommandScopeClass
LangCode string
Commands []BotCommand
}
const BotsSetBotCommandsRequestTypeID = 0x517165a
var (
_ bin .Encoder = &BotsSetBotCommandsRequest {}
_ bin .Decoder = &BotsSetBotCommandsRequest {}
_ bin .BareEncoder = &BotsSetBotCommandsRequest {}
_ bin .BareDecoder = &BotsSetBotCommandsRequest {}
)
func (s *BotsSetBotCommandsRequest ) Zero () bool {
if s == nil {
return true
}
if !(s .Scope == nil ) {
return false
}
if !(s .LangCode == "" ) {
return false
}
if !(s .Commands == nil ) {
return false
}
return true
}
func (s *BotsSetBotCommandsRequest ) String () string {
if s == nil {
return "BotsSetBotCommandsRequest(nil)"
}
type Alias BotsSetBotCommandsRequest
return fmt .Sprintf ("BotsSetBotCommandsRequest%+v" , Alias (*s ))
}
func (s *BotsSetBotCommandsRequest ) FillFrom (from interface {
GetScope () (value BotCommandScopeClass )
GetLangCode () (value string )
GetCommands () (value []BotCommand )
}) {
s .Scope = from .GetScope ()
s .LangCode = from .GetLangCode ()
s .Commands = from .GetCommands ()
}
func (*BotsSetBotCommandsRequest ) TypeID () uint32 {
return BotsSetBotCommandsRequestTypeID
}
func (*BotsSetBotCommandsRequest ) TypeName () string {
return "bots.setBotCommands"
}
func (s *BotsSetBotCommandsRequest ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "bots.setBotCommands" ,
ID : BotsSetBotCommandsRequestTypeID ,
}
if s == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Scope" ,
SchemaName : "scope" ,
},
{
Name : "LangCode" ,
SchemaName : "lang_code" ,
},
{
Name : "Commands" ,
SchemaName : "commands" ,
},
}
return typ
}
func (s *BotsSetBotCommandsRequest ) Encode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode bots.setBotCommands#517165a as nil" )
}
b .PutID (BotsSetBotCommandsRequestTypeID )
return s .EncodeBare (b )
}
func (s *BotsSetBotCommandsRequest ) EncodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode bots.setBotCommands#517165a as nil" )
}
if s .Scope == nil {
return fmt .Errorf ("unable to encode bots.setBotCommands#517165a: field scope is nil" )
}
if err := s .Scope .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode bots.setBotCommands#517165a: field scope: %w" , err )
}
b .PutString (s .LangCode )
b .PutVectorHeader (len (s .Commands ))
for idx , v := range s .Commands {
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode bots.setBotCommands#517165a: field commands element with index %d: %w" , idx , err )
}
}
return nil
}
func (s *BotsSetBotCommandsRequest ) Decode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode bots.setBotCommands#517165a to nil" )
}
if err := b .ConsumeID (BotsSetBotCommandsRequestTypeID ); err != nil {
return fmt .Errorf ("unable to decode bots.setBotCommands#517165a: %w" , err )
}
return s .DecodeBare (b )
}
func (s *BotsSetBotCommandsRequest ) DecodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode bots.setBotCommands#517165a to nil" )
}
{
value , err := DecodeBotCommandScope (b )
if err != nil {
return fmt .Errorf ("unable to decode bots.setBotCommands#517165a: field scope: %w" , err )
}
s .Scope = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode bots.setBotCommands#517165a: field lang_code: %w" , err )
}
s .LangCode = value
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode bots.setBotCommands#517165a: field commands: %w" , err )
}
if headerLen > 0 {
s .Commands = make ([]BotCommand , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
var value BotCommand
if err := value .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode bots.setBotCommands#517165a: field commands: %w" , err )
}
s .Commands = append (s .Commands , value )
}
}
return nil
}
func (s *BotsSetBotCommandsRequest ) GetScope () (value BotCommandScopeClass ) {
if s == nil {
return
}
return s .Scope
}
func (s *BotsSetBotCommandsRequest ) GetLangCode () (value string ) {
if s == nil {
return
}
return s .LangCode
}
func (s *BotsSetBotCommandsRequest ) GetCommands () (value []BotCommand ) {
if s == nil {
return
}
return s .Commands
}
func (c *Client ) BotsSetBotCommands (ctx context .Context , request *BotsSetBotCommandsRequest ) (bool , error ) {
var result BoolBox
if err := c .rpc .Invoke (ctx , request , &result ); err != nil {
return false , err
}
_ , ok := result .Bool .(*BoolTrue )
return ok , nil
}
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 .