Add logout command

calls
bodqhrohro 4 years ago
parent c22008d991
commit eeba07eeb0

@ -1,15 +1,20 @@
package telegram
import (
"strconv"
"strings"
"dev.narayana.im/narayana/telegabber/xmpp/gateway"
log "github.com/sirupsen/logrus"
)
const notEnoughArguments string = "Not enough arguments"
const telegramNotInitialized string = "Telegram connection is not initialized yet"
var transportCommands = map[string]command{
"login": command{"phone", "sign in"},
//"logout": command{"", "sign out"},
"login": command{"phone", "sign in"},
"logout": command{"", "sign out"},
"code": command{"", "check one-time code"},
"password": command{"", "check 2fa password"},
//"setusername": command{"", "update @username"},
@ -120,14 +125,34 @@ func (c *Client) ProcessTransportCommand(cmdline string) string {
}
switch cmd {
// sign in
case "login":
c.authorizer.PhoneNumber <- args[0]
c.Session.Login = args[0]
// check auth code
case "code":
c.authorizer.Code <- args[0]
// check auth password
case "password":
c.authorizer.Password <- args[0]
}
// sign out
case "logout":
_, err := c.client.LogOut()
if err != nil {
log.Errorf("Logout error: %v", err)
}
for id := range c.cache.chats {
gateway.SendPresence(
c.xmpp,
c.jid,
gateway.SPFrom(strconv.FormatInt(id, 10)),
gateway.SPType("unsubscribed"),
)
}
c.Session.Login = ""
case "help":
return helpString(helpTypeTransport)
}

Loading…
Cancel
Save