diff --git a/login.go b/login.go index 68c3ed6..78e6eef 100644 --- a/login.go +++ b/login.go @@ -1,51 +1,51 @@ package main import ( - "fmt" - "syscall" + "fmt" + "syscall" - "github.com/c0re100/go-tdlib" - "golang.org/x/crypto/ssh/terminal" + "github.com/c0re100/go-tdlib" + "golang.org/x/crypto/ssh/terminal" ) func (tg *Client) login() { - for { - currentState, _ := tg.client.Authorize() - if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateWaitPhoneNumberType { - fmt.Print("Enter phone: ") - var number string - fmt.Scanln(&number) - _, err := tg.client.SendPhoneNumber(number) - if err != nil { - fmt.Printf("Error sending phone number: %v", err) - } - } else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateWaitCodeType { - fmt.Print("Enter code: ") - var code string - fmt.Scanln(&code) - _, err := tg.client.SendAuthCode(code) - if err != nil { - fmt.Printf("Error sending auth code : %v", err) - } - } else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateWaitPasswordType { - fmt.Print("Enter Password: ") - bytePassword, err := terminal.ReadPassword(int(syscall.Stdin)) - if err != nil { - fmt.Println(err) - } - _, err = tg.client.SendAuthPassword(string(bytePassword)) - if err != nil { - fmt.Printf("Error sending auth password: %v", err) - } - } else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateReadyType { - me, err := tg.client.GetMe() - if err != nil { - fmt.Println(err) - return - } - tg.clientId = me.Id - fmt.Println("Hello!", me.FirstName, me.LastName, "("+me.Username+")") - break - } - } + for { + currentState, _ := tg.client.Authorize() + if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateWaitPhoneNumberType { + fmt.Print("Enter phone: ") + var number string + fmt.Scanln(&number) + _, err := tg.client.SendPhoneNumber(number) + if err != nil { + fmt.Printf("Error sending phone number: %v", err) + } + } else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateWaitCodeType { + fmt.Print("Enter code: ") + var code string + fmt.Scanln(&code) + _, err := tg.client.SendAuthCode(code) + if err != nil { + fmt.Printf("Error sending auth code : %v", err) + } + } else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateWaitPasswordType { + fmt.Print("Enter Password: ") + bytePassword, err := terminal.ReadPassword(int(syscall.Stdin)) + if err != nil { + fmt.Println(err) + } + _, err = tg.client.SendAuthPassword(string(bytePassword)) + if err != nil { + fmt.Printf("Error sending auth password: %v", err) + } + } else if currentState.GetAuthorizationStateEnum() == tdlib.AuthorizationStateReadyType { + me, err := tg.client.GetMe() + if err != nil { + fmt.Println(err) + return + } + tg.clientId = me.Id + fmt.Println("Hello!", me.FirstName, me.LastName, "("+me.Username+")") + break + } + } } diff --git a/parser.go b/parser.go index 29a82dc..aebf9c0 100644 --- a/parser.go +++ b/parser.go @@ -1,41 +1,41 @@ package main import ( - "strings" + "strings" - "github.com/c0re100/go-tdlib" + "github.com/c0re100/go-tdlib" ) func CheckCommand(msgText string, entity []tdlib.TextEntity) string { - if msgText != "" { - if msgText[0] == '/' { - if len(entity) >= 1 { - if entity[0].Type.GetTextEntityTypeEnum() == "textEntityTypeBotCommand" { - if i := strings.Index(msgText[:entity[0].Length], "@"); i != -1 { - return msgText[:i] - } - return msgText[:entity[0].Length] - } - } - if len(msgText) > 1 { - if i := strings.Index(msgText, " "); i != -1 { - return msgText[:i] - } - if i := strings.Index(msgText, "@"); i != -1 { - return msgText[:i] - } - return msgText - } - } - } - return "" + if msgText != "" { + if msgText[0] == '/' { + if len(entity) >= 1 { + if entity[0].Type.GetTextEntityTypeEnum() == "textEntityTypeBotCommand" { + if i := strings.Index(msgText[:entity[0].Length], "@"); i != -1 { + return msgText[:i] + } + return msgText[:entity[0].Length] + } + } + if len(msgText) > 1 { + if i := strings.Index(msgText, " "); i != -1 { + return msgText[:i] + } + if i := strings.Index(msgText, "@"); i != -1 { + return msgText[:i] + } + return msgText + } + } + } + return "" } func CommandArgument(msgText string) string { - if msgText[0] == '/' { - if i := strings.Index(msgText, " "); i != -1 { - return msgText[i+1:] - } - } - return "" + if msgText[0] == '/' { + if i := strings.Index(msgText, " "); i != -1 { + return msgText[i+1:] + } + } + return "" }