From 564e0786b91274ebdc99ef0962cc6793458da71d Mon Sep 17 00:00:00 2001 From: shoopea Date: Tue, 28 Dec 2021 23:02:18 +0800 Subject: [PATCH] add remove --- bot.go | 21 +++++++++++++++++++++ version.go | 8 ++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/bot.go b/bot.go index 64b613c..e918966 100644 --- a/bot.go +++ b/bot.go @@ -97,6 +97,7 @@ func (b *Bot) BotHandlers() { b.bot.Handle("/ready", botReady) b.bot.Handle("/start", botStart) b.bot.Handle("/players", botPlayers) + b.bot.Handle("/remove", botRemove) b.bot.Handle("/give", botGive) b.bot.Handle("/take", botTake) @@ -514,6 +515,26 @@ func botPlayers(m *tb.Message) { 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[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) { d1 := time.Now().Sub(cfg.Game.StartDate) days := int(time.Duration(d1.Hours()) / 24) diff --git a/version.go b/version.go index b1efcf3..a8a9f70 100644 --- a/version.go +++ b/version.go @@ -1,6 +1,6 @@ // Code generated by version.sh (@generated) DO NOT EDIT. package main -var githash = "f21a8e5" -var buildstamp = "2021-12-12_06:30:54" -var commits = "257" -var version = "f21a8e5-b257 - 2021-12-12_06:30:54" +var githash = "86f2914" +var buildstamp = "2021-12-28_15:02:08" +var commits = "258" +var version = "86f2914-b258 - 2021-12-28_15:02:08"