gocwexp/main.go

75 lines
1.9 KiB
Go
Raw Normal View History

2019-12-29 03:45:12 +01:00
package main
import (
"flag"
"fmt"
"log"
"sync"
"time"
"gopkg.in/gcfg.v1"
"github.com/Arman92/go-tdlib"
)
var (
ownUserID64 = int64(0)
ownUserID32 = int32(0)
)
func main() {
tdlib.SetLogVerbosityLevel(1)
tdlib.SetFilePath("./errors.txt")
// Create new instance of client
client := tdlib.NewClient(tdlib.Config{
APIID: "187786",
APIHash: "e782045df67ba48e441ccb105da8fc85",
SystemLanguageCode: "en",
DeviceModel: "ChatWarsExport",
SystemVersion: "0.1",
ApplicationVersion: "0.1",
UseMessageDatabase: true,
UseFileDatabase: true,
UseChatInfoDatabase: true,
UseTestDataCenter: false,
DatabaseDirectory: "./tdlib-db",
FileDirectory: "./tdlib-files",
IgnoreFileNames: false,
})
for {
currentState, _ := client.Authorize()
if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateWaitPhoneNumberType {
fmt.Print("Enter phone: ")
var number string
fmt.Scanln(&number)
_, err := client.SendPhoneNumber(number)
logOnError(err, "Error sending phone number.")
} else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateWaitCodeType {
fmt.Print("Enter code: ")
var code string
fmt.Scanln(&code)
_, err := client.SendAuthCode(code)
logOnError(err, "Error sending auth code.")
} else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateWaitPasswordType {
fmt.Print("Enter Password: ")
var password string
fmt.Scanln(&password)
_, err := client.SendAuthPassword(password)
logOnError(err, "Error sending auth password.")
} else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateReadyType {
fmt.Println("Authorization Ready! Let's rock")
break
}
time.Sleep(1 * time.Second)
}
ownUserID32 = OwnUserID(client)
ownUserID64 = int64(OwnUserID(client))
getHistory(client, 408101137)
}