This commit is contained in:
shoopea 2019-05-25 22:36:14 +08:00
parent 50f07b6723
commit 5c7da6e1d2

58
bot.go
View File

@ -25,6 +25,9 @@ func BotHandlers(b *tb.Bot) {
b.Handle("/msg_rescan_all", botMsgRescanAll) b.Handle("/msg_rescan_all", botMsgRescanAll)
b.Handle("/msg_dump", botMsgDump) b.Handle("/msg_dump", botMsgDump)
b.Handle("/parse_rules", botListParsingRules)
b.Handle("/parse_rule", botListParsingRule)
b.Handle(tb.OnPhoto, botPhoto) b.Handle(tb.OnPhoto, botPhoto)
b.Handle(tb.OnChannelPost, botChannelPost) b.Handle(tb.OnChannelPost, botChannelPost)
b.Handle(tb.OnQuery, botQuery) b.Handle(tb.OnQuery, botQuery)
@ -202,3 +205,58 @@ func botMsgDump(m *tb.Message) {
return return
} }
func botListParsingRules(m *tb.Message) {
if !m.Private() {
return
}
for v, _ := range msgParsingRules {
s := fmt.Sprintf("[%d] %s\n", v.ID, v.Descn)
}
c := TGCommand{
Type: commandReplyMsg,
Text: s,
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
func botListParsingRule(m *tb.Message) {
r := regexp.MustCompile("^[0-9]+$")
if r.MatchString(m.Payload) {
i, _ := strconv.ParseInt(m.Payload, 10, 64)
for v, _ := range msgParsingRules {
if v.ID == i {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s\n", v.rule),
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
}
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("Could not find rule %s\n", m.Payload),
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("/parse_rule <id>\n"),
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
return
}