This commit is contained in:
shoopea
2021-11-10 13:41:37 +08:00
parent 4772cd7f71
commit e185eff578
3 changed files with 39 additions and 14 deletions

35
bot.go
View File

@@ -188,17 +188,32 @@ func botPasswd(m *tb.Message) {
bot.SendChat(m.Chat.ID, "User not registered.")
return
}
r := regexp.MustCompile("^\\/passwd( )+(?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")
if cc.CompanyID == 255 {
bot.SendChat(m.Chat.ID, "No company registered.")
return
}
co, ok := srv.Status.Companies[cc.CompanyID]
if !ok {
bot.SendChat(m.Chat.ID, "Registered company doesn't exist.")
cc.CompanyID = 255
return
}
r := regexp.MustCompile("^\\/passwd( )+(?P<Passwd>[^ ]+)$")
if !r.MatchString(m.Text) {
bot.SendChat(m.Chat.ID, "No passwd provided")
return
}
// we have a parameter
cc.Passwd = r.ReplaceAllString(m.Text, "${Passwd}")
err := bot.bot.Delete(m)
logErrorDebug(err, "botPasswd : Delete")
srv.SetPasswd(co.CompanyID, cc.Passwd)
bot.SendUser(int64(m.Sender.ID), fmt.Sprintf("Passwd set to \"%s\"", cc.Passwd))
return
}