Skip to content

Commit

Permalink
goformat
Browse files Browse the repository at this point in the history
  • Loading branch information
c0re100 committed Dec 3, 2021
1 parent 3c05c80 commit 00de8dd
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 73 deletions.
86 changes: 43 additions & 43 deletions login.go
Original file line number Diff line number Diff line change
@@ -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
}
}
}
60 changes: 30 additions & 30 deletions parser.go
Original file line number Diff line number Diff line change
@@ -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 ""
}

0 comments on commit 00de8dd

Please sign in to comment.