save eco/stats and add save trigger
This commit is contained in:
29
bot.go
29
bot.go
@@ -73,7 +73,9 @@ func (b *Bot) BotHandlers() {
|
||||
b.bot.Handle("/passwd", botPasswd)
|
||||
b.bot.Handle("/say", botSay)
|
||||
b.bot.Handle("/help", botHelp)
|
||||
|
||||
b.bot.Handle("/version", botVersion)
|
||||
b.bot.Handle("/save", botSave)
|
||||
|
||||
b.bot.Handle("/reset", botReset)
|
||||
b.bot.Handle("/ready", botReady)
|
||||
@@ -283,7 +285,9 @@ func botActuallyReset(m *tb.Message) {
|
||||
if time.Now().Sub(a.Time) > time.Minute {
|
||||
bot.SendChat(m.Chat.ID, "Request expired.")
|
||||
} else {
|
||||
cfg.Save("backup." + *configFlag)
|
||||
cfg.Game.Started = false
|
||||
cfg.Stats = make(map[uint8]map[string]*Stat)
|
||||
for _, cc := range cfg.Clients {
|
||||
cc.Ready = false
|
||||
cc.CompanyID = 255
|
||||
@@ -511,6 +515,31 @@ func botVersion(m *tb.Message) {
|
||||
return
|
||||
}
|
||||
|
||||
func botSave(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("^\\/save @(?P<Filename>[a-zA-Z0-9._]+)")
|
||||
|
||||
if !r.MatchString(m.Text) {
|
||||
bot.SendChat(m.Chat.ID, "Wrong usage.")
|
||||
return
|
||||
}
|
||||
|
||||
filename := r.ReplaceAllString(m.Text, "${Filename}")
|
||||
|
||||
err := cfg.Save(filename + ".json")
|
||||
logErrorDebug(err, "botSave : Config.Save(%s)", filename+".json")
|
||||
if err != nil {
|
||||
bot.SendChat(m.Chat.ID, fmt.Sprintf("Error : %s", err))
|
||||
} else {
|
||||
bot.SendChat(m.Chat.ID, "Saved.")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func botTransfer(m *tb.Message) {
|
||||
r := regexp.MustCompile("^\\/transfer @(?P<Username>[a-zA-Z0-9]+) (?P<Duration>[a-z0-9]+)")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user