From 584ac25c3637107bbc9967786ccdc390fcc5e754 Mon Sep 17 00:00:00 2001 From: shoopea Date: Wed, 10 Nov 2021 12:56:53 +0800 Subject: [PATCH] add passwd --- bot.go | 21 +++++++++++++++++++++ config.go | 1 + version.go | 8 ++++---- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/bot.go b/bot.go index 2caf03f..66c2e77 100644 --- a/bot.go +++ b/bot.go @@ -59,6 +59,7 @@ func (b *Bot) BotHandlers() { b.bot.Handle("/players", botPlayers) b.bot.Handle("/give", botGive) b.bot.Handle("/take", botTake) + b.bot.Handle("/passwd", botPasswd) b.bot.Handle(tb.OnPhoto, botPhoto) b.bot.Handle(tb.OnChannelPost, botChannelPost) @@ -181,6 +182,26 @@ func botTake(m *tb.Message) { PrintText(m) } +func botPasswd(m *tb.Message) { + cc, ok := cfg.Clients[m.Sender.ID] + if !ok { + bot.SendChat(m.Chat.ID, "User not registered.") + return + } + r := regexp.MustCompile("^\\/register( )+(?P[.^\\ ]+)$") + if r.MatchString(m.Text) { + // we have a parameter + passwd := r.ReplaceAllString(m.Text, "${Passwd}") + cc.Passwd = passwd + bot.SendUser(int64(m.Sender.ID), fmt.Sprintf("Passwd set to \"%s\"", passwd)) + err := bot.bot.Delete(m) + logErrorDebug(err, "botPasswd : Delete") + } else { + bot.SendChat(m.Chat.ID, "No passwd provided") + } + return +} + func botDeregister(m *tb.Message) { cc, ok := cfg.Clients[m.Sender.ID] if !ok { diff --git a/config.go b/config.go index 133d971..6d6b103 100644 --- a/config.go +++ b/config.go @@ -35,6 +35,7 @@ type GameConfig struct { type ClientConfig struct { UserID int `json:"user_id"` Username string `json:"username"` + Passwd string `json:"passwd"` Online bool `json:"online"` TimeLeft time.Duration `json:"time_left"` CompanyID uint8 `json:"company_id` diff --git a/version.go b/version.go index f55cfbf..4aa0c99 100644 --- a/version.go +++ b/version.go @@ -1,6 +1,6 @@ // Code generated by version.sh (@generated) DO NOT EDIT. package main -var githash = "a100fb6" -var buildstamp = "2021-11-09_09:44:42" -var commits = "176" -var version = "a100fb6-b176 - 2021-11-09_09:44:42" +var githash = "8d58018" +var buildstamp = "2021-11-10_04:56:39" +var commits = "177" +var version = "8d58018-b177 - 2021-11-10_04:56:39"