add remove

This commit is contained in:
shoopea 2021-12-28 23:02:18 +08:00
parent 86f29143fa
commit 564e0786b9
2 changed files with 25 additions and 4 deletions

21
bot.go
View File

@ -97,6 +97,7 @@ func (b *Bot) BotHandlers() {
b.bot.Handle("/ready", botReady) b.bot.Handle("/ready", botReady)
b.bot.Handle("/start", botStart) b.bot.Handle("/start", botStart)
b.bot.Handle("/players", botPlayers) b.bot.Handle("/players", botPlayers)
b.bot.Handle("/remove", botRemove)
b.bot.Handle("/give", botGive) b.bot.Handle("/give", botGive)
b.bot.Handle("/take", botTake) b.bot.Handle("/take", botTake)
@ -514,6 +515,26 @@ func botPlayers(m *tb.Message) {
return return
} }
func botRemove(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("^\\/remove (?P<Username>[a-zA-Z0-9]+)")
for _, cc := range cfg.Clients {
if cc.Username == r.ReplaceAllString(m.Text, "${Username}") {
delete(cfg.Clients, cc.UserID)
bot.SendChat(m.Chat.ID, fmt.Sprintf("%s deleted.", cc.Username))
return
}
}
bot.SendChat(m.Chat.ID, "No such player.")
return
}
func botPlayersStarted(m *tb.Message) { func botPlayersStarted(m *tb.Message) {
d1 := time.Now().Sub(cfg.Game.StartDate) d1 := time.Now().Sub(cfg.Game.StartDate)
days := int(time.Duration(d1.Hours()) / 24) days := int(time.Duration(d1.Hours()) / 24)

View File

@ -1,6 +1,6 @@
// Code generated by version.sh (@generated) DO NOT EDIT. // Code generated by version.sh (@generated) DO NOT EDIT.
package main package main
var githash = "f21a8e5" var githash = "86f2914"
var buildstamp = "2021-12-12_06:30:54" var buildstamp = "2021-12-28_15:02:08"
var commits = "257" var commits = "258"
var version = "f21a8e5-b257 - 2021-12-12_06:30:54" var version = "86f2914-b258 - 2021-12-28_15:02:08"