client requests
This commit is contained in:
parent
997dc1006a
commit
862b94d2c7
|
@ -57,19 +57,29 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
|
|||
|
||||
switch state.AuthorizationStateType() {
|
||||
case TypeAuthorizationStateWaitTdlibParameters:
|
||||
_, err := client.SetTdlibParameters(<-stateHandler.TdlibParameters)
|
||||
_, err := client.SetTdlibParameters(&SetTdlibParametersRequest{
|
||||
Parameters: <-stateHandler.TdlibParameters,
|
||||
})
|
||||
return err
|
||||
|
||||
case TypeAuthorizationStateWaitEncryptionKey:
|
||||
_, err := client.CheckDatabaseEncryptionKey(nil)
|
||||
_, err := client.CheckDatabaseEncryptionKey(&CheckDatabaseEncryptionKeyRequest{})
|
||||
return err
|
||||
|
||||
case TypeAuthorizationStateWaitPhoneNumber:
|
||||
_, err := client.SetAuthenticationPhoneNumber(<-stateHandler.PhoneNumber, false, false)
|
||||
_, err := client.SetAuthenticationPhoneNumber(&SetAuthenticationPhoneNumberRequest{
|
||||
PhoneNumber: <-stateHandler.PhoneNumber,
|
||||
AllowFlashCall: false,
|
||||
IsCurrentPhoneNumber: false,
|
||||
})
|
||||
return err
|
||||
|
||||
case TypeAuthorizationStateWaitCode:
|
||||
_, err := client.CheckAuthenticationCode(<-stateHandler.Code, <-stateHandler.FirstName, <-stateHandler.LastName)
|
||||
_, err := client.CheckAuthenticationCode(&CheckAuthenticationCodeRequest{
|
||||
Code: <-stateHandler.Code,
|
||||
FirstName: <-stateHandler.FirstName,
|
||||
LastName: <-stateHandler.LastName,
|
||||
})
|
||||
return err
|
||||
|
||||
case TypeAuthorizationStateWaitPassword:
|
||||
|
@ -162,15 +172,19 @@ func (stateHandler *botAuthorizer) Handle(client *Client, state AuthorizationSta
|
|||
|
||||
switch state.AuthorizationStateType() {
|
||||
case TypeAuthorizationStateWaitTdlibParameters:
|
||||
_, err := client.SetTdlibParameters(<-stateHandler.TdlibParameters)
|
||||
_, err := client.SetTdlibParameters(&SetTdlibParametersRequest{
|
||||
Parameters: <-stateHandler.TdlibParameters,
|
||||
})
|
||||
return err
|
||||
|
||||
case TypeAuthorizationStateWaitEncryptionKey:
|
||||
_, err := client.CheckDatabaseEncryptionKey(nil)
|
||||
_, err := client.CheckDatabaseEncryptionKey(&CheckDatabaseEncryptionKeyRequest{})
|
||||
return err
|
||||
|
||||
case TypeAuthorizationStateWaitPhoneNumber:
|
||||
_, err := client.CheckAuthenticationBotToken(<-stateHandler.Token)
|
||||
_, err := client.CheckAuthenticationBotToken(&CheckAuthenticationBotTokenRequest{
|
||||
Token: <-stateHandler.Token,
|
||||
})
|
||||
return err
|
||||
|
||||
case TypeAuthorizationStateWaitCode:
|
||||
|
|
4226
client/function.go
4226
client/function.go
File diff suppressed because it is too large
Load diff
|
@ -24,7 +24,13 @@ func chatHistory(tdlibClient *client.Client, messageChan chan *client.Message, e
|
|||
}()
|
||||
|
||||
for {
|
||||
messages, err := tdlibClient.GetChatHistory(chatId, fromMessageId, offset, limit, onlyLocal)
|
||||
messages, err := tdlibClient.GetChatHistory(&client.GetChatHistoryRequest{
|
||||
ChatId: chatId,
|
||||
FromMessageId: fromMessageId,
|
||||
Offset: offset,
|
||||
Limit: limit,
|
||||
OnlyLocal: onlyLocal,
|
||||
})
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
|
||||
|
|
|
@ -26,7 +26,11 @@ func chats(tdlibClient *client.Client, chatChan chan *client.Chat, errChan chan
|
|||
}()
|
||||
|
||||
for {
|
||||
chats, err := tdlibClient.GetChats(offsetOrder, offsetChatId, limit)
|
||||
chats, err := tdlibClient.GetChats(&client.GetChatsRequest{
|
||||
OffsetOrder: offsetOrder,
|
||||
OffsetChatId: offsetChatId,
|
||||
Limit: limit,
|
||||
})
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
|
||||
|
|
|
@ -26,7 +26,12 @@ func supergroupMembers(tdlibClient *client.Client, chatMemberChan chan *client.C
|
|||
var page int32 = 0
|
||||
|
||||
for {
|
||||
chatMembers, err := tdlibClient.GetSupergroupMembers(supergroupId, filter, page*limit+offset, limit)
|
||||
chatMembers, err := tdlibClient.GetSupergroupMembers(&client.GetSupergroupMembersRequest{
|
||||
SupergroupId: supergroupId,
|
||||
Filter: filter,
|
||||
Offset: page*limit + offset,
|
||||
Limit: limit,
|
||||
})
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package codegen
|
||||
|
||||
import (
|
||||
"github.com/zelenin/go-tdlib/tlparser"
|
||||
"fmt"
|
||||
"strings"
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/zelenin/go-tdlib/tlparser"
|
||||
)
|
||||
|
||||
func GenerateFunctions(schema *tlparser.Schema, packageName string) []byte {
|
||||
|
@ -19,29 +19,31 @@ func GenerateFunctions(schema *tlparser.Schema, packageName string) []byte {
|
|||
buf.WriteString("\n")
|
||||
|
||||
for _, function := range schema.Functions {
|
||||
tdlibFunction := TdlibFunction(function.Name, schema)
|
||||
tdlibFunctionReturn := TdlibFunctionReturn(function.Class, schema)
|
||||
|
||||
if len(function.Properties) > 0 {
|
||||
buf.WriteString("\n")
|
||||
buf.WriteString(fmt.Sprintf("type %sRequest struct { \n", tdlibFunction.ToGoName()))
|
||||
for _, property := range function.Properties {
|
||||
tdlibTypeProperty := TdlibTypeProperty(property.Name, property.Type, schema)
|
||||
|
||||
buf.WriteString(fmt.Sprintf(" // %s\n", property.Description))
|
||||
buf.WriteString(fmt.Sprintf(" %s %s `json:\"%s\"`\n", tdlibTypeProperty.ToGoName(), tdlibTypeProperty.ToGoType(), property.Name))
|
||||
}
|
||||
buf.WriteString("}\n")
|
||||
}
|
||||
|
||||
buf.WriteString("\n")
|
||||
buf.WriteString("// " + function.Description)
|
||||
buf.WriteString("\n")
|
||||
|
||||
requestArgument := ""
|
||||
if len(function.Properties) > 0 {
|
||||
buf.WriteString("//")
|
||||
buf.WriteString("\n")
|
||||
requestArgument = fmt.Sprintf("req *%sRequest", tdlibFunction.ToGoName())
|
||||
}
|
||||
|
||||
propertiesParts := []string{}
|
||||
for _, property := range function.Properties {
|
||||
tdlibFunctionProperty := TdlibFunctionProperty(property.Name, property.Type, schema)
|
||||
|
||||
buf.WriteString(fmt.Sprintf("// @param %s %s", tdlibFunctionProperty.ToGoName(), property.Description))
|
||||
buf.WriteString("\n")
|
||||
|
||||
propertiesParts = append(propertiesParts, tdlibFunctionProperty.ToGoName()+" "+tdlibFunctionProperty.ToGoType())
|
||||
}
|
||||
|
||||
tdlibFunction := TdlibFunction(function.Name, schema)
|
||||
tdlibFunctionReturn := TdlibFunctionReturn(function.Class, schema)
|
||||
|
||||
buf.WriteString(fmt.Sprintf("func (client *Client) %s(%s) (%s, error) {\n", tdlibFunction.ToGoName(), strings.Join(propertiesParts, ", "), tdlibFunctionReturn.ToGoReturn()))
|
||||
buf.WriteString(fmt.Sprintf("func (client *Client) %s(%s) (%s, error) {\n", tdlibFunction.ToGoName(), requestArgument, tdlibFunctionReturn.ToGoReturn()))
|
||||
|
||||
sendMethod := "Send"
|
||||
if function.IsSynchronous {
|
||||
|
@ -57,8 +59,9 @@ func GenerateFunctions(schema *tlparser.Schema, packageName string) []byte {
|
|||
`, sendMethod, function.Name))
|
||||
|
||||
for _, property := range function.Properties {
|
||||
tdlibFunctionProperty := TdlibFunctionProperty(property.Name, property.Type, schema)
|
||||
buf.WriteString(fmt.Sprintf(" \"%s\": %s,\n", property.Name, tdlibFunctionProperty.ToGoName()))
|
||||
tdlibTypeProperty := TdlibTypeProperty(property.Name, property.Type, schema)
|
||||
|
||||
buf.WriteString(fmt.Sprintf(" \"%s\": req.%s,\n", property.Name, tdlibTypeProperty.ToGoName()))
|
||||
}
|
||||
|
||||
buf.WriteString(` },
|
||||
|
|
Loading…
Reference in a new issue