diff --git a/bot.go b/bot.go index 9c23af4..9bb16db 100644 --- a/bot.go +++ b/bot.go @@ -25,6 +25,9 @@ func BotHandlers(b *tb.Bot) { b.Handle("/msg_rescan_all", botMsgRescanAll) b.Handle("/msg_dump", botMsgDump) + b.Handle("/parse_rules", botListParsingRules) + b.Handle("/parse_rule", botListParsingRule) + b.Handle(tb.OnPhoto, botPhoto) b.Handle(tb.OnChannelPost, botChannelPost) b.Handle(tb.OnQuery, botQuery) @@ -202,3 +205,58 @@ func botMsgDump(m *tb.Message) { 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 \n"), + FromMsgID64: int64(m.ID), + FromChatID64: m.Chat.ID, + } + TGCmdQueue <- c + } + return +}