update tdlib 3870c29b158b75ca5e48e0eebd6b5c3a7994a000
This commit is contained in:
parent
063c3471b0
commit
bc2f985e62
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
|||
TAG := v1.8.0
|
||||
TAG := 3870c29b158b75ca5e48e0eebd6b5c3a7994a000
|
||||
|
||||
schema-update:
|
||||
curl https://raw.githubusercontent.com/tdlib/td/${TAG}/td/generate/scheme/td_api.tl 2>/dev/null > ./data/td_api.tl
|
||||
|
|
|
@ -8,6 +8,42 @@ import (
|
|||
|
||||
var ErrNotSupportedAuthorizationState = errors.New("not supported state")
|
||||
|
||||
// Contains parameters for TDLib initialization
|
||||
type TdlibParameters struct {
|
||||
// Pass true to use Telegram test environment instead of the production environment
|
||||
UseTestDc bool `json:"use_test_dc"`
|
||||
// The path to the directory for the persistent database; if empty, the current working directory will be used
|
||||
DatabaseDirectory string `json:"database_directory"`
|
||||
// The path to the directory for storing files; if empty, database_directory will be used
|
||||
FilesDirectory string `json:"files_directory"`
|
||||
// Encryption key for the database. If the encryption key is invalid, then an error with code 401 will be returned
|
||||
DatabaseEncryptionKey []byte `json:"database_encryption_key"`
|
||||
// Pass true to keep information about downloaded and uploaded files between application restarts
|
||||
UseFileDatabase bool `json:"use_file_database"`
|
||||
// Pass true to keep cache of users, basic groups, supergroups, channels and secret chats between restarts. Implies use_file_database
|
||||
UseChatInfoDatabase bool `json:"use_chat_info_database"`
|
||||
// Pass true to keep cache of chats and messages between restarts. Implies use_chat_info_database
|
||||
UseMessageDatabase bool `json:"use_message_database"`
|
||||
// Pass true to enable support for secret chats
|
||||
UseSecretChats bool `json:"use_secret_chats"`
|
||||
// Application identifier for Telegram API access, which can be obtained at https://my.telegram.org
|
||||
ApiId int32 `json:"api_id"`
|
||||
// Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.org
|
||||
ApiHash string `json:"api_hash"`
|
||||
// IETF language tag of the user's operating system language; must be non-empty
|
||||
SystemLanguageCode string `json:"system_language_code"`
|
||||
// Model of the device the application is being run on; must be non-empty
|
||||
DeviceModel string `json:"device_model"`
|
||||
// Version of the operating system the application is being run on. If empty, the version is automatically detected by TDLib
|
||||
SystemVersion string `json:"system_version"`
|
||||
// Application version; must be non-empty
|
||||
ApplicationVersion string `json:"application_version"`
|
||||
// Pass true to automatically delete old files in background
|
||||
EnableStorageOptimizer bool `json:"enable_storage_optimizer"`
|
||||
// Pass true to ignore original file names for downloaded files. Otherwise, downloaded files are saved under names as close as possible to the original name
|
||||
IgnoreFileNames bool `json:"ignore_file_names"`
|
||||
}
|
||||
|
||||
type AuthorizationStateHandler interface {
|
||||
Handle(client *Client, state AuthorizationState) error
|
||||
Close()
|
||||
|
@ -65,15 +101,27 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
|
|||
|
||||
switch state.AuthorizationStateType() {
|
||||
case TypeAuthorizationStateWaitTdlibParameters:
|
||||
p := <-stateHandler.TdlibParameters
|
||||
_, err := client.SetTdlibParameters(&SetTdlibParametersRequest{
|
||||
Parameters: <-stateHandler.TdlibParameters,
|
||||
UseTestDc: p.UseTestDc,
|
||||
DatabaseDirectory: p.DatabaseDirectory,
|
||||
FilesDirectory: p.FilesDirectory,
|
||||
DatabaseEncryptionKey: p.DatabaseEncryptionKey,
|
||||
UseFileDatabase: p.UseFileDatabase,
|
||||
UseChatInfoDatabase: p.UseChatInfoDatabase,
|
||||
UseMessageDatabase: p.UseMessageDatabase,
|
||||
UseSecretChats: p.UseSecretChats,
|
||||
ApiId: p.ApiId,
|
||||
ApiHash: p.ApiHash,
|
||||
SystemLanguageCode: p.SystemLanguageCode,
|
||||
DeviceModel: p.DeviceModel,
|
||||
SystemVersion: p.SystemVersion,
|
||||
ApplicationVersion: p.ApplicationVersion,
|
||||
EnableStorageOptimizer: p.EnableStorageOptimizer,
|
||||
IgnoreFileNames: p.IgnoreFileNames,
|
||||
})
|
||||
return err
|
||||
|
||||
case TypeAuthorizationStateWaitEncryptionKey:
|
||||
_, err := client.CheckDatabaseEncryptionKey(&CheckDatabaseEncryptionKeyRequest{})
|
||||
return err
|
||||
|
||||
case TypeAuthorizationStateWaitPhoneNumber:
|
||||
_, err := client.SetAuthenticationPhoneNumber(&SetAuthenticationPhoneNumberRequest{
|
||||
PhoneNumber: <-stateHandler.PhoneNumber,
|
||||
|
@ -85,12 +133,21 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
|
|||
})
|
||||
return err
|
||||
|
||||
case TypeAuthorizationStateWaitEmailAddress:
|
||||
return ErrNotSupportedAuthorizationState
|
||||
|
||||
case TypeAuthorizationStateWaitEmailCode:
|
||||
return ErrNotSupportedAuthorizationState
|
||||
|
||||
case TypeAuthorizationStateWaitCode:
|
||||
_, err := client.CheckAuthenticationCode(&CheckAuthenticationCodeRequest{
|
||||
Code: <-stateHandler.Code,
|
||||
})
|
||||
return err
|
||||
|
||||
case TypeAuthorizationStateWaitOtherDeviceConfirmation:
|
||||
return ErrNotSupportedAuthorizationState
|
||||
|
||||
case TypeAuthorizationStateWaitRegistration:
|
||||
return ErrNotSupportedAuthorizationState
|
||||
|
||||
|
@ -140,6 +197,12 @@ func CliInteractor(clientAuthorizer *clientAuthorizer) {
|
|||
|
||||
clientAuthorizer.PhoneNumber <- phoneNumber
|
||||
|
||||
case TypeAuthorizationStateWaitEmailAddress:
|
||||
return
|
||||
|
||||
case TypeAuthorizationStateWaitEmailCode:
|
||||
return
|
||||
|
||||
case TypeAuthorizationStateWaitCode:
|
||||
var code string
|
||||
|
||||
|
@ -148,6 +211,12 @@ func CliInteractor(clientAuthorizer *clientAuthorizer) {
|
|||
|
||||
clientAuthorizer.Code <- code
|
||||
|
||||
case TypeAuthorizationStateWaitOtherDeviceConfirmation:
|
||||
return
|
||||
|
||||
case TypeAuthorizationStateWaitRegistration:
|
||||
return
|
||||
|
||||
case TypeAuthorizationStateWaitPassword:
|
||||
fmt.Println("Enter password: ")
|
||||
var password string
|
||||
|
@ -185,15 +254,27 @@ func (stateHandler *botAuthorizer) Handle(client *Client, state AuthorizationSta
|
|||
|
||||
switch state.AuthorizationStateType() {
|
||||
case TypeAuthorizationStateWaitTdlibParameters:
|
||||
p := <-stateHandler.TdlibParameters
|
||||
_, err := client.SetTdlibParameters(&SetTdlibParametersRequest{
|
||||
Parameters: <-stateHandler.TdlibParameters,
|
||||
UseTestDc: p.UseTestDc,
|
||||
DatabaseDirectory: p.DatabaseDirectory,
|
||||
FilesDirectory: p.FilesDirectory,
|
||||
DatabaseEncryptionKey: p.DatabaseEncryptionKey,
|
||||
UseFileDatabase: p.UseFileDatabase,
|
||||
UseChatInfoDatabase: p.UseChatInfoDatabase,
|
||||
UseMessageDatabase: p.UseMessageDatabase,
|
||||
UseSecretChats: p.UseSecretChats,
|
||||
ApiId: p.ApiId,
|
||||
ApiHash: p.ApiHash,
|
||||
SystemLanguageCode: p.SystemLanguageCode,
|
||||
DeviceModel: p.DeviceModel,
|
||||
SystemVersion: p.SystemVersion,
|
||||
ApplicationVersion: p.ApplicationVersion,
|
||||
EnableStorageOptimizer: p.EnableStorageOptimizer,
|
||||
IgnoreFileNames: p.IgnoreFileNames,
|
||||
})
|
||||
return err
|
||||
|
||||
case TypeAuthorizationStateWaitEncryptionKey:
|
||||
_, err := client.CheckDatabaseEncryptionKey(&CheckDatabaseEncryptionKeyRequest{})
|
||||
return err
|
||||
|
||||
case TypeAuthorizationStateWaitPhoneNumber:
|
||||
_, err := client.CheckAuthenticationBotToken(&CheckAuthenticationBotTokenRequest{
|
||||
Token: <-stateHandler.Token,
|
||||
|
|
6662
client/function.go
6662
client/function.go
File diff suppressed because it is too large
Load diff
15762
client/type.go
15762
client/type.go
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
12930
data/td_api.json
12930
data/td_api.json
File diff suppressed because it is too large
Load diff
5713
data/td_api.tl
5713
data/td_api.tl
File diff suppressed because it is too large
Load diff
|
@ -91,17 +91,11 @@ func parseFunction(firstLine string, scanner *bufio.Scanner) *Function {
|
|||
}
|
||||
|
||||
func parseClass(firstLine string, scanner *bufio.Scanner) *Class {
|
||||
class := &Class{
|
||||
Name: "",
|
||||
Description: "",
|
||||
name, description, _, _, _ := parseEntity(firstLine, scanner)
|
||||
return &Class{
|
||||
Name: name,
|
||||
Description: description,
|
||||
}
|
||||
|
||||
classLineParts := strings.Split(firstLine, "@")
|
||||
|
||||
_, class.Name = parseProperty(classLineParts[1])
|
||||
_, class.Description = parseProperty(classLineParts[2])
|
||||
|
||||
return class
|
||||
}
|
||||
|
||||
func parseEntity(firstLine string, scanner *bufio.Scanner) (string, string, string, []*Property, bool) {
|
||||
|
@ -125,6 +119,9 @@ Loop:
|
|||
|
||||
default:
|
||||
bodyFields := strings.Fields(line)
|
||||
if len(bodyFields) == 0 {
|
||||
break Loop
|
||||
}
|
||||
name = bodyFields[0]
|
||||
|
||||
for _, rawProperty := range bodyFields[1 : len(bodyFields)-2] {
|
||||
|
@ -142,13 +139,17 @@ Loop:
|
|||
|
||||
rawProperties := strings.Split(propertiesLine, "@")
|
||||
for _, rawProperty := range rawProperties[1:] {
|
||||
name, value := parseProperty(rawProperty)
|
||||
propertyName, value := parseProperty(rawProperty)
|
||||
switch {
|
||||
case name == "description":
|
||||
case propertyName == "class":
|
||||
if name == "" {
|
||||
name = value
|
||||
}
|
||||
case propertyName == "description":
|
||||
description = value
|
||||
default:
|
||||
name = strings.TrimPrefix(name, "param_")
|
||||
property := getProperty(properties, name)
|
||||
propertyName = strings.TrimPrefix(propertyName, "param_")
|
||||
property := getProperty(properties, propertyName)
|
||||
property.Description = value
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue