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 {

View File

@ -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`

View File

@ -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"