client requests

This commit is contained in:
Aleksandr Zelenin 2018-10-16 23:32:57 +03:00
parent 997dc1006a
commit 862b94d2c7
6 changed files with 2701 additions and 1619 deletions

View file

@ -57,19 +57,29 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
switch state.AuthorizationStateType() { switch state.AuthorizationStateType() {
case TypeAuthorizationStateWaitTdlibParameters: case TypeAuthorizationStateWaitTdlibParameters:
_, err := client.SetTdlibParameters(<-stateHandler.TdlibParameters) _, err := client.SetTdlibParameters(&SetTdlibParametersRequest{
Parameters: <-stateHandler.TdlibParameters,
})
return err return err
case TypeAuthorizationStateWaitEncryptionKey: case TypeAuthorizationStateWaitEncryptionKey:
_, err := client.CheckDatabaseEncryptionKey(nil) _, err := client.CheckDatabaseEncryptionKey(&CheckDatabaseEncryptionKeyRequest{})
return err return err
case TypeAuthorizationStateWaitPhoneNumber: case TypeAuthorizationStateWaitPhoneNumber:
_, err := client.SetAuthenticationPhoneNumber(<-stateHandler.PhoneNumber, false, false) _, err := client.SetAuthenticationPhoneNumber(&SetAuthenticationPhoneNumberRequest{
PhoneNumber: <-stateHandler.PhoneNumber,
AllowFlashCall: false,
IsCurrentPhoneNumber: false,
})
return err return err
case TypeAuthorizationStateWaitCode: 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 return err
case TypeAuthorizationStateWaitPassword: case TypeAuthorizationStateWaitPassword:
@ -162,15 +172,19 @@ func (stateHandler *botAuthorizer) Handle(client *Client, state AuthorizationSta
switch state.AuthorizationStateType() { switch state.AuthorizationStateType() {
case TypeAuthorizationStateWaitTdlibParameters: case TypeAuthorizationStateWaitTdlibParameters:
_, err := client.SetTdlibParameters(<-stateHandler.TdlibParameters) _, err := client.SetTdlibParameters(&SetTdlibParametersRequest{
Parameters: <-stateHandler.TdlibParameters,
})
return err return err
case TypeAuthorizationStateWaitEncryptionKey: case TypeAuthorizationStateWaitEncryptionKey:
_, err := client.CheckDatabaseEncryptionKey(nil) _, err := client.CheckDatabaseEncryptionKey(&CheckDatabaseEncryptionKeyRequest{})
return err return err
case TypeAuthorizationStateWaitPhoneNumber: case TypeAuthorizationStateWaitPhoneNumber:
_, err := client.CheckAuthenticationBotToken(<-stateHandler.Token) _, err := client.CheckAuthenticationBotToken(&CheckAuthenticationBotTokenRequest{
Token: <-stateHandler.Token,
})
return err return err
case TypeAuthorizationStateWaitCode: case TypeAuthorizationStateWaitCode:

File diff suppressed because it is too large Load diff

View file

@ -24,7 +24,13 @@ func chatHistory(tdlibClient *client.Client, messageChan chan *client.Message, e
}() }()
for { 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 { if err != nil {
errChan <- err errChan <- err

View file

@ -26,7 +26,11 @@ func chats(tdlibClient *client.Client, chatChan chan *client.Chat, errChan chan
}() }()
for { for {
chats, err := tdlibClient.GetChats(offsetOrder, offsetChatId, limit) chats, err := tdlibClient.GetChats(&client.GetChatsRequest{
OffsetOrder: offsetOrder,
OffsetChatId: offsetChatId,
Limit: limit,
})
if err != nil { if err != nil {
errChan <- err errChan <- err

View file

@ -26,7 +26,12 @@ func supergroupMembers(tdlibClient *client.Client, chatMemberChan chan *client.C
var page int32 = 0 var page int32 = 0
for { 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 { if err != nil {
errChan <- err errChan <- err

View file

@ -1,10 +1,10 @@
package codegen package codegen
import ( import (
"github.com/zelenin/go-tdlib/tlparser"
"fmt"
"strings"
"bytes" "bytes"
"fmt"
"github.com/zelenin/go-tdlib/tlparser"
) )
func GenerateFunctions(schema *tlparser.Schema, packageName string) []byte { func GenerateFunctions(schema *tlparser.Schema, packageName string) []byte {
@ -19,29 +19,31 @@ func GenerateFunctions(schema *tlparser.Schema, packageName string) []byte {
buf.WriteString("\n") buf.WriteString("\n")
for _, function := range schema.Functions { 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("\n")
buf.WriteString("// " + function.Description) buf.WriteString("// " + function.Description)
buf.WriteString("\n") buf.WriteString("\n")
requestArgument := ""
if len(function.Properties) > 0 { if len(function.Properties) > 0 {
buf.WriteString("//") requestArgument = fmt.Sprintf("req *%sRequest", tdlibFunction.ToGoName())
buf.WriteString("\n")
} }
propertiesParts := []string{} buf.WriteString(fmt.Sprintf("func (client *Client) %s(%s) (%s, error) {\n", tdlibFunction.ToGoName(), requestArgument, tdlibFunctionReturn.ToGoReturn()))
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()))
sendMethod := "Send" sendMethod := "Send"
if function.IsSynchronous { if function.IsSynchronous {
@ -57,8 +59,9 @@ func GenerateFunctions(schema *tlparser.Schema, packageName string) []byte {
`, sendMethod, function.Name)) `, sendMethod, function.Name))
for _, property := range function.Properties { for _, property := range function.Properties {
tdlibFunctionProperty := TdlibFunctionProperty(property.Name, property.Type, schema) tdlibTypeProperty := TdlibTypeProperty(property.Name, property.Type, schema)
buf.WriteString(fmt.Sprintf(" \"%s\": %s,\n", property.Name, tdlibFunctionProperty.ToGoName()))
buf.WriteString(fmt.Sprintf(" \"%s\": req.%s,\n", property.Name, tdlibTypeProperty.ToGoName()))
} }
buf.WriteString(` }, buf.WriteString(` },