add offline

This commit is contained in:
shoopea 2021-12-08 19:50:55 +08:00
parent d4b4094f44
commit 14f65a433b
2 changed files with 36 additions and 4 deletions

32
bot.go
View File

@ -88,6 +88,7 @@ func (b *Bot) BotHandlers() {
b.bot.Handle("/register", botRegister)
b.bot.Handle("/deregister", botDeregister)
b.bot.Handle("/delete", botDelete)
b.bot.Handle("/offline", botOffline)
b.bot.Handle("/companies", botCompanies)
b.bot.Handle("/clients", botClients)
@ -168,6 +169,37 @@ func botUnpause(m *tb.Message) {
return
}
func botOffline(m *tb.Message) {
if m.Sender.ID != int(cfg.Telegram.AdminID) {
bot.SendChat(m.Chat.ID, "Only the admin can use this command.")
return
}
r := regexp.MustCompile("^\\/give @(?P<Username>[a-zA-Z0-9]+)")
if !r.MatchString(m.Text) {
bot.SendChat(m.Chat.ID, "Wrong format.")
return
}
uStr := r.ReplaceAllString(m.Text, "${Username}")
var u int
for ccID, cc := range cfg.Clients {
if cc.Username == uStr {
u = ccID
}
}
if u == 0 {
bot.SendChat(m.Chat.ID, "No such user found.")
return
}
cc := cfg.Clients[u]
cc.Online = false
bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s is now offline.", uStr))
}
func botDelete(m *tb.Message) {
r := regexp.MustCompile("\\/delete (?P<CompanyID>[0-9]+)")
id := uint8(255)

View File

@ -1,6 +1,6 @@
// Code generated by version.sh (@generated) DO NOT EDIT.
package main
var githash = "954b6c7"
var buildstamp = "2021-12-06_14:40:54"
var commits = "237"
var version = "954b6c7-b237 - 2021-12-06_14:40:54"
var githash = "d4b4094"
var buildstamp = "2021-12-08_11:50:42"
var commits = "238"
var version = "d4b4094-b238 - 2021-12-08_11:50:42"