add passwd

This commit is contained in:
shoopea
2021-11-10 12:56:53 +08:00
parent 8d580181bf
commit 584ac25c36
3 changed files with 26 additions and 4 deletions

21
bot.go
View File

@@ -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<Passwd>[.^\\ ]+)$")
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 {