Add logout command
This commit is contained in:
parent
c22008d991
commit
eeba07eeb0
|
@ -1,7 +1,12 @@
|
||||||
package telegram
|
package telegram
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"dev.narayana.im/narayana/telegabber/xmpp/gateway"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const notEnoughArguments string = "Not enough arguments"
|
const notEnoughArguments string = "Not enough arguments"
|
||||||
|
@ -9,7 +14,7 @@ const telegramNotInitialized string = "Telegram connection is not initialized ye
|
||||||
|
|
||||||
var transportCommands = map[string]command{
|
var transportCommands = map[string]command{
|
||||||
"login": command{"phone", "sign in"},
|
"login": command{"phone", "sign in"},
|
||||||
//"logout": command{"", "sign out"},
|
"logout": command{"", "sign out"},
|
||||||
"code": command{"", "check one-time code"},
|
"code": command{"", "check one-time code"},
|
||||||
"password": command{"", "check 2fa password"},
|
"password": command{"", "check 2fa password"},
|
||||||
//"setusername": command{"", "update @username"},
|
//"setusername": command{"", "update @username"},
|
||||||
|
@ -120,14 +125,34 @@ func (c *Client) ProcessTransportCommand(cmdline string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch cmd {
|
switch cmd {
|
||||||
|
// sign in
|
||||||
case "login":
|
case "login":
|
||||||
c.authorizer.PhoneNumber <- args[0]
|
c.authorizer.PhoneNumber <- args[0]
|
||||||
c.Session.Login = args[0]
|
c.Session.Login = args[0]
|
||||||
|
// check auth code
|
||||||
case "code":
|
case "code":
|
||||||
c.authorizer.Code <- args[0]
|
c.authorizer.Code <- args[0]
|
||||||
|
// check auth password
|
||||||
case "password":
|
case "password":
|
||||||
c.authorizer.Password <- args[0]
|
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":
|
case "help":
|
||||||
return helpString(helpTypeTransport)
|
return helpString(helpTypeTransport)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue