aboutsummaryrefslogtreecommitdiff
path: root/telegram/commands.go
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2023-08-28 17:16:57 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2023-08-28 17:16:57 +0300
commit20994e29953dfc9c238f69d919912e0c26e36b97 (patch)
treec078032c172c2e49ea89ba35f2e0367de0da29ee /telegram/commands.go
parent8ba7596ab5b9cd731fb507f60da51c6acf1ef27f (diff)
In-Band Registration (XEP-0077)dev
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":