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 SponsoredMessage struct {
Flags bin .Fields
Recommended bool
ShowPeerPhoto bool
RandomID []byte
FromID PeerClass
ChatInvite ChatInviteClass
ChatInviteHash string
ChannelPost int
StartParam string
Webpage SponsoredWebPage
App BotAppClass
Message string
Entities []MessageEntityClass
ButtonText string
SponsorInfo string
AdditionalInfo string
}
const SponsoredMessageTypeID = 0xed5383f7
var (
_ bin .Encoder = &SponsoredMessage {}
_ bin .Decoder = &SponsoredMessage {}
_ bin .BareEncoder = &SponsoredMessage {}
_ bin .BareDecoder = &SponsoredMessage {}
)
func (s *SponsoredMessage ) Zero () bool {
if s == nil {
return true
}
if !(s .Flags .Zero ()) {
return false
}
if !(s .Recommended == false ) {
return false
}
if !(s .ShowPeerPhoto == false ) {
return false
}
if !(s .RandomID == nil ) {
return false
}
if !(s .FromID == nil ) {
return false
}
if !(s .ChatInvite == nil ) {
return false
}
if !(s .ChatInviteHash == "" ) {
return false
}
if !(s .ChannelPost == 0 ) {
return false
}
if !(s .StartParam == "" ) {
return false
}
if !(s .Webpage .Zero ()) {
return false
}
if !(s .App == nil ) {
return false
}
if !(s .Message == "" ) {
return false
}
if !(s .Entities == nil ) {
return false
}
if !(s .ButtonText == "" ) {
return false
}
if !(s .SponsorInfo == "" ) {
return false
}
if !(s .AdditionalInfo == "" ) {
return false
}
return true
}
func (s *SponsoredMessage ) String () string {
if s == nil {
return "SponsoredMessage(nil)"
}
type Alias SponsoredMessage
return fmt .Sprintf ("SponsoredMessage%+v" , Alias (*s ))
}
func (s *SponsoredMessage ) FillFrom (from interface {
GetRecommended () (value bool )
GetShowPeerPhoto () (value bool )
GetRandomID () (value []byte )
GetFromID () (value PeerClass , ok bool )
GetChatInvite () (value ChatInviteClass , ok bool )
GetChatInviteHash () (value string , ok bool )
GetChannelPost () (value int , ok bool )
GetStartParam () (value string , ok bool )
GetWebpage () (value SponsoredWebPage , ok bool )
GetApp () (value BotAppClass , ok bool )
GetMessage () (value string )
GetEntities () (value []MessageEntityClass , ok bool )
GetButtonText () (value string , ok bool )
GetSponsorInfo () (value string , ok bool )
GetAdditionalInfo () (value string , ok bool )
}) {
s .Recommended = from .GetRecommended ()
s .ShowPeerPhoto = from .GetShowPeerPhoto ()
s .RandomID = from .GetRandomID ()
if val , ok := from .GetFromID (); ok {
s .FromID = val
}
if val , ok := from .GetChatInvite (); ok {
s .ChatInvite = val
}
if val , ok := from .GetChatInviteHash (); ok {
s .ChatInviteHash = val
}
if val , ok := from .GetChannelPost (); ok {
s .ChannelPost = val
}
if val , ok := from .GetStartParam (); ok {
s .StartParam = val
}
if val , ok := from .GetWebpage (); ok {
s .Webpage = val
}
if val , ok := from .GetApp (); ok {
s .App = val
}
s .Message = from .GetMessage ()
if val , ok := from .GetEntities (); ok {
s .Entities = val
}
if val , ok := from .GetButtonText (); ok {
s .ButtonText = val
}
if val , ok := from .GetSponsorInfo (); ok {
s .SponsorInfo = val
}
if val , ok := from .GetAdditionalInfo (); ok {
s .AdditionalInfo = val
}
}
func (*SponsoredMessage ) TypeID () uint32 {
return SponsoredMessageTypeID
}
func (*SponsoredMessage ) TypeName () string {
return "sponsoredMessage"
}
func (s *SponsoredMessage ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "sponsoredMessage" ,
ID : SponsoredMessageTypeID ,
}
if s == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Recommended" ,
SchemaName : "recommended" ,
Null : !s .Flags .Has (5 ),
},
{
Name : "ShowPeerPhoto" ,
SchemaName : "show_peer_photo" ,
Null : !s .Flags .Has (6 ),
},
{
Name : "RandomID" ,
SchemaName : "random_id" ,
},
{
Name : "FromID" ,
SchemaName : "from_id" ,
Null : !s .Flags .Has (3 ),
},
{
Name : "ChatInvite" ,
SchemaName : "chat_invite" ,
Null : !s .Flags .Has (4 ),
},
{
Name : "ChatInviteHash" ,
SchemaName : "chat_invite_hash" ,
Null : !s .Flags .Has (4 ),
},
{
Name : "ChannelPost" ,
SchemaName : "channel_post" ,
Null : !s .Flags .Has (2 ),
},
{
Name : "StartParam" ,
SchemaName : "start_param" ,
Null : !s .Flags .Has (0 ),
},
{
Name : "Webpage" ,
SchemaName : "webpage" ,
Null : !s .Flags .Has (9 ),
},
{
Name : "App" ,
SchemaName : "app" ,
Null : !s .Flags .Has (10 ),
},
{
Name : "Message" ,
SchemaName : "message" ,
},
{
Name : "Entities" ,
SchemaName : "entities" ,
Null : !s .Flags .Has (1 ),
},
{
Name : "ButtonText" ,
SchemaName : "button_text" ,
Null : !s .Flags .Has (11 ),
},
{
Name : "SponsorInfo" ,
SchemaName : "sponsor_info" ,
Null : !s .Flags .Has (7 ),
},
{
Name : "AdditionalInfo" ,
SchemaName : "additional_info" ,
Null : !s .Flags .Has (8 ),
},
}
return typ
}
func (s *SponsoredMessage ) SetFlags () {
if !(s .Recommended == false ) {
s .Flags .Set (5 )
}
if !(s .ShowPeerPhoto == false ) {
s .Flags .Set (6 )
}
if !(s .FromID == nil ) {
s .Flags .Set (3 )
}
if !(s .ChatInvite == nil ) {
s .Flags .Set (4 )
}
if !(s .ChatInviteHash == "" ) {
s .Flags .Set (4 )
}
if !(s .ChannelPost == 0 ) {
s .Flags .Set (2 )
}
if !(s .StartParam == "" ) {
s .Flags .Set (0 )
}
if !(s .Webpage .Zero ()) {
s .Flags .Set (9 )
}
if !(s .App == nil ) {
s .Flags .Set (10 )
}
if !(s .Entities == nil ) {
s .Flags .Set (1 )
}
if !(s .ButtonText == "" ) {
s .Flags .Set (11 )
}
if !(s .SponsorInfo == "" ) {
s .Flags .Set (7 )
}
if !(s .AdditionalInfo == "" ) {
s .Flags .Set (8 )
}
}
func (s *SponsoredMessage ) Encode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode sponsoredMessage#ed5383f7 as nil" )
}
b .PutID (SponsoredMessageTypeID )
return s .EncodeBare (b )
}
func (s *SponsoredMessage ) EncodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode sponsoredMessage#ed5383f7 as nil" )
}
s .SetFlags ()
if err := s .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode sponsoredMessage#ed5383f7: field flags: %w" , err )
}
b .PutBytes (s .RandomID )
if s .Flags .Has (3 ) {
if s .FromID == nil {
return fmt .Errorf ("unable to encode sponsoredMessage#ed5383f7: field from_id is nil" )
}
if err := s .FromID .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode sponsoredMessage#ed5383f7: field from_id: %w" , err )
}
}
if s .Flags .Has (4 ) {
if s .ChatInvite == nil {
return fmt .Errorf ("unable to encode sponsoredMessage#ed5383f7: field chat_invite is nil" )
}
if err := s .ChatInvite .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode sponsoredMessage#ed5383f7: field chat_invite: %w" , err )
}
}
if s .Flags .Has (4 ) {
b .PutString (s .ChatInviteHash )
}
if s .Flags .Has (2 ) {
b .PutInt (s .ChannelPost )
}
if s .Flags .Has (0 ) {
b .PutString (s .StartParam )
}
if s .Flags .Has (9 ) {
if err := s .Webpage .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode sponsoredMessage#ed5383f7: field webpage: %w" , err )
}
}
if s .Flags .Has (10 ) {
if s .App == nil {
return fmt .Errorf ("unable to encode sponsoredMessage#ed5383f7: field app is nil" )
}
if err := s .App .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode sponsoredMessage#ed5383f7: field app: %w" , err )
}
}
b .PutString (s .Message )
if s .Flags .Has (1 ) {
b .PutVectorHeader (len (s .Entities ))
for idx , v := range s .Entities {
if v == nil {
return fmt .Errorf ("unable to encode sponsoredMessage#ed5383f7: field entities element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode sponsoredMessage#ed5383f7: field entities element with index %d: %w" , idx , err )
}
}
}
if s .Flags .Has (11 ) {
b .PutString (s .ButtonText )
}
if s .Flags .Has (7 ) {
b .PutString (s .SponsorInfo )
}
if s .Flags .Has (8 ) {
b .PutString (s .AdditionalInfo )
}
return nil
}
func (s *SponsoredMessage ) Decode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode sponsoredMessage#ed5383f7 to nil" )
}
if err := b .ConsumeID (SponsoredMessageTypeID ); err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: %w" , err )
}
return s .DecodeBare (b )
}
func (s *SponsoredMessage ) DecodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode sponsoredMessage#ed5383f7 to nil" )
}
{
if err := s .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: field flags: %w" , err )
}
}
s .Recommended = s .Flags .Has (5 )
s .ShowPeerPhoto = s .Flags .Has (6 )
{
value , err := b .Bytes ()
if err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: field random_id: %w" , err )
}
s .RandomID = value
}
if s .Flags .Has (3 ) {
value , err := DecodePeer (b )
if err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: field from_id: %w" , err )
}
s .FromID = value
}
if s .Flags .Has (4 ) {
value , err := DecodeChatInvite (b )
if err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: field chat_invite: %w" , err )
}
s .ChatInvite = value
}
if s .Flags .Has (4 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: field chat_invite_hash: %w" , err )
}
s .ChatInviteHash = value
}
if s .Flags .Has (2 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: field channel_post: %w" , err )
}
s .ChannelPost = value
}
if s .Flags .Has (0 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: field start_param: %w" , err )
}
s .StartParam = value
}
if s .Flags .Has (9 ) {
if err := s .Webpage .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: field webpage: %w" , err )
}
}
if s .Flags .Has (10 ) {
value , err := DecodeBotApp (b )
if err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: field app: %w" , err )
}
s .App = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: field message: %w" , err )
}
s .Message = value
}
if s .Flags .Has (1 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: field entities: %w" , err )
}
if headerLen > 0 {
s .Entities = make ([]MessageEntityClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeMessageEntity (b )
if err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: field entities: %w" , err )
}
s .Entities = append (s .Entities , value )
}
}
if s .Flags .Has (11 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: field button_text: %w" , err )
}
s .ButtonText = value
}
if s .Flags .Has (7 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: field sponsor_info: %w" , err )
}
s .SponsorInfo = value
}
if s .Flags .Has (8 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode sponsoredMessage#ed5383f7: field additional_info: %w" , err )
}
s .AdditionalInfo = value
}
return nil
}
func (s *SponsoredMessage ) SetRecommended (value bool ) {
if value {
s .Flags .Set (5 )
s .Recommended = true
} else {
s .Flags .Unset (5 )
s .Recommended = false
}
}
func (s *SponsoredMessage ) GetRecommended () (value bool ) {
if s == nil {
return
}
return s .Flags .Has (5 )
}
func (s *SponsoredMessage ) SetShowPeerPhoto (value bool ) {
if value {
s .Flags .Set (6 )
s .ShowPeerPhoto = true
} else {
s .Flags .Unset (6 )
s .ShowPeerPhoto = false
}
}
func (s *SponsoredMessage ) GetShowPeerPhoto () (value bool ) {
if s == nil {
return
}
return s .Flags .Has (6 )
}
func (s *SponsoredMessage ) GetRandomID () (value []byte ) {
if s == nil {
return
}
return s .RandomID
}
func (s *SponsoredMessage ) SetFromID (value PeerClass ) {
s .Flags .Set (3 )
s .FromID = value
}
func (s *SponsoredMessage ) GetFromID () (value PeerClass , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (3 ) {
return value , false
}
return s .FromID , true
}
func (s *SponsoredMessage ) SetChatInvite (value ChatInviteClass ) {
s .Flags .Set (4 )
s .ChatInvite = value
}
func (s *SponsoredMessage ) GetChatInvite () (value ChatInviteClass , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (4 ) {
return value , false
}
return s .ChatInvite , true
}
func (s *SponsoredMessage ) SetChatInviteHash (value string ) {
s .Flags .Set (4 )
s .ChatInviteHash = value
}
func (s *SponsoredMessage ) GetChatInviteHash () (value string , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (4 ) {
return value , false
}
return s .ChatInviteHash , true
}
func (s *SponsoredMessage ) SetChannelPost (value int ) {
s .Flags .Set (2 )
s .ChannelPost = value
}
func (s *SponsoredMessage ) GetChannelPost () (value int , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (2 ) {
return value , false
}
return s .ChannelPost , true
}
func (s *SponsoredMessage ) SetStartParam (value string ) {
s .Flags .Set (0 )
s .StartParam = value
}
func (s *SponsoredMessage ) GetStartParam () (value string , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (0 ) {
return value , false
}
return s .StartParam , true
}
func (s *SponsoredMessage ) SetWebpage (value SponsoredWebPage ) {
s .Flags .Set (9 )
s .Webpage = value
}
func (s *SponsoredMessage ) GetWebpage () (value SponsoredWebPage , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (9 ) {
return value , false
}
return s .Webpage , true
}
func (s *SponsoredMessage ) SetApp (value BotAppClass ) {
s .Flags .Set (10 )
s .App = value
}
func (s *SponsoredMessage ) GetApp () (value BotAppClass , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (10 ) {
return value , false
}
return s .App , true
}
func (s *SponsoredMessage ) GetMessage () (value string ) {
if s == nil {
return
}
return s .Message
}
func (s *SponsoredMessage ) SetEntities (value []MessageEntityClass ) {
s .Flags .Set (1 )
s .Entities = value
}
func (s *SponsoredMessage ) GetEntities () (value []MessageEntityClass , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (1 ) {
return value , false
}
return s .Entities , true
}
func (s *SponsoredMessage ) SetButtonText (value string ) {
s .Flags .Set (11 )
s .ButtonText = value
}
func (s *SponsoredMessage ) GetButtonText () (value string , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (11 ) {
return value , false
}
return s .ButtonText , true
}
func (s *SponsoredMessage ) SetSponsorInfo (value string ) {
s .Flags .Set (7 )
s .SponsorInfo = value
}
func (s *SponsoredMessage ) GetSponsorInfo () (value string , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (7 ) {
return value , false
}
return s .SponsorInfo , true
}
func (s *SponsoredMessage ) SetAdditionalInfo (value string ) {
s .Flags .Set (8 )
s .AdditionalInfo = value
}
func (s *SponsoredMessage ) GetAdditionalInfo () (value string , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (8 ) {
return value , false
}
return s .AdditionalInfo , true
}
func (s *SponsoredMessage ) GetAppAsModified () (*BotApp , bool ) {
if value , ok := s .GetApp (); ok {
return value .AsModified ()
}
return nil , false
}
func (s *SponsoredMessage ) MapEntities () (value MessageEntityClassArray , ok bool ) {
if !s .Flags .Has (1 ) {
return value , false
}
return MessageEntityClassArray (s .Entities ), true
}
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 .