test /say

This commit is contained in:
shoopea
2021-11-13 13:44:57 +08:00
parent bb1a7d0062
commit 40a0b5e800
3 changed files with 67 additions and 4 deletions

22
bot.go
View File

@@ -72,6 +72,7 @@ func (b *Bot) BotHandlers() {
b.bot.Handle("/give", botGive)
b.bot.Handle("/take", botTake)
b.bot.Handle("/passwd", botPasswd)
b.bot.Handle("/say", botSay)
b.bot.Handle(tb.OnPhoto, botPhoto)
b.bot.Handle(tb.OnChannelPost, botChannelPost)
@@ -299,6 +300,27 @@ func botTake(m *tb.Message) {
bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s now has %s left.", uStr, cc.TimeLeft))
}
func botSay(m *tb.Message) {
r := regexp.MustCompile("^\\/say( )+(?P<Message>.+)$")
if !r.MatchString(m.Text) {
bot.SendChat(m.Chat.ID, "No message provided")
return
}
msg := r.ReplaceAllString(m.Text, "${Message}")
px := PacketAdminChat{
Packet: Packet{PType: AdminPacketAdminChat},
ActionType: AdminNetworkActionChat,
DestinationType: AdminDestinationTypeBroadcast,
DestinationID: 0,
Message: msg,
}
srv.Send(px.Bytes())
return
}
func botPasswd(m *tb.Message) {
cc, ok := cfg.Clients[m.Sender.ID]
if !ok {