This commit is contained in:
shoopea 2019-05-16 11:35:37 +08:00
parent c908780c96
commit c3b0a88a9f

34
bot.go
View File

@ -25,13 +25,7 @@ func BotHandlers(b *tb.Bot) {
b.Send(m.Sender, s)
}
})
b.Handle("/msg_rescan_all", func(m *tb.Message) {
s, err := botMsgRescanAll(m)
logOnError(err, "/msg_rescan_all")
if err == nil {
b.Send(m.Sender, s)
}
})
b.Handle("/msg_rescan_all", botMsgRescanAll)
b.Handle(tb.OnPhoto, botPhoto)
b.Handle(tb.OnChannelPost, botChannelPost)
@ -118,11 +112,9 @@ func botMsgRescan(m *tb.Message) (string, error) {
return "/msg_rescan msg_id or /msg_rescan all", nil
}
func botMsgRescanAll(m *tb.Message) (string, error) {
fmt.Println("botRescanMsgAll :", m.Text)
func botMsgRescanAll(m *tb.Message) {
if !m.Private() {
fmt.Println("botRescanMsg : !m.Private()")
return ``, nil
return
}
p := JobPayloadRescanMsg{
Query: fmt.Sprintf("SELECT o.id FROM obj o WHERE o.obj_type_id = %d AND o.obj_sub_type_id = %d;", objTypeMessage, objSubTypeMessageUnknown),
@ -132,9 +124,23 @@ func botMsgRescanAll(m *tb.Message) (string, error) {
b, _ := json.Marshal(p)
err := createJob(objSubTypeJobRescanMsg, objJobPriorityRescanAllMsg, int64(m.Sender.ID), time.Now(), b)
logOnError(err, "botMsgRescan : createJob(objSubTypeJobRescanMsg)")
if err != nil {
return "Error scheduling the rescan for all msg", nil
} else {
return "Rescaning all msg scheduled", nil
c := TGCommand{
Type: commandReplyMsg,
Text: "Error scheduling the rescan for all msg.",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "Rescaning all msg scheduled.",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
return
}