-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
73 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "" | ||
} |