aboutsummaryrefslogtreecommitdiff
path: root/telegram/commands.go
diff options
context:
space:
mode:
Diffstat (limited to 'telegram/commands.go')
-rw-r--r--telegram/commands.go52
1 files changed, 21 insertions, 31 deletions
diff --git a/telegram/commands.go b/telegram/commands.go
index 0c83945..b4920d4 100644
--- a/telegram/commands.go
+++ b/telegram/commands.go
@@ -15,7 +15,8 @@ import (
)
const notEnoughArguments string = "Not enough arguments"
-const telegramNotInitialized string = "Telegram connection is not initialized yet"
+const TelegramNotInitialized string = "Telegram connection is not initialized yet"
+const TelegramAuthDone string = "Authorization is done already"
const notOnline string = "Not online"
var permissionsAdmin = client.ChatAdministratorRights{
@@ -244,40 +245,29 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) string
}
if cmd == "login" {
- wasSessionLoginEmpty := c.Session.Login == ""
- c.Session.Login = args[0]
-
- if wasSessionLoginEmpty && c.authorizer == nil {
- go func() {
- err := c.Connect(resource)
- if err != nil {
- log.Error(errors.Wrap(err, "TDlib connection failure"))
- }
- }()
- // a quirk for authorizer to become ready. If it's still not,
- // nothing bad: the command just needs to be resent again
- time.Sleep(1e5)
+ err := c.TryLogin(resource, args[0])
+ if err != nil {
+ return err.Error()
}
- }
- if c.authorizer == nil {
- return telegramNotInitialized
- }
+ c.authorizer.PhoneNumber <- args[0]
+ } else {
+ if c.authorizer == nil {
+ return TelegramNotInitialized
+ }
- if c.authorizer.isClosed {
- return "Authorization is done already"
- }
+ if c.authorizer.isClosed {
+ return TelegramAuthDone
+ }
- switch cmd {
- // sign in
- case "login":
- c.authorizer.PhoneNumber <- args[0]
- // check auth code
- case "code":
- c.authorizer.Code <- args[0]
- // check auth password
- case "password":
- c.authorizer.Password <- args[0]
+ switch cmd {
+ // check auth code
+ case "code":
+ c.authorizer.Code <- args[0]
+ // check auth password
+ case "password":
+ c.authorizer.Password <- args[0]
+ }
}
// sign out
case "logout":