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

32
bot.go
View File

@ -25,13 +25,7 @@ func BotHandlers(b *tb.Bot) {
b.Send(m.Sender, s) b.Send(m.Sender, s)
} }
}) })
b.Handle("/msg_rescan_all", func(m *tb.Message) { b.Handle("/msg_rescan_all", botMsgRescanAll)
s, err := botMsgRescanAll(m)
logOnError(err, "/msg_rescan_all")
if err == nil {
b.Send(m.Sender, s)
}
})
b.Handle(tb.OnPhoto, botPhoto) b.Handle(tb.OnPhoto, botPhoto)
b.Handle(tb.OnChannelPost, botChannelPost) 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 return "/msg_rescan msg_id or /msg_rescan all", nil
} }
func botMsgRescanAll(m *tb.Message) (string, error) { func botMsgRescanAll(m *tb.Message) {
fmt.Println("botRescanMsgAll :", m.Text)
if !m.Private() { if !m.Private() {
fmt.Println("botRescanMsg : !m.Private()") return
return ``, nil
} }
p := JobPayloadRescanMsg{ 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), 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) b, _ := json.Marshal(p)
err := createJob(objSubTypeJobRescanMsg, objJobPriorityRescanAllMsg, int64(m.Sender.ID), time.Now(), b) err := createJob(objSubTypeJobRescanMsg, objJobPriorityRescanAllMsg, int64(m.Sender.ID), time.Now(), b)
logOnError(err, "botMsgRescan : createJob(objSubTypeJobRescanMsg)") logOnError(err, "botMsgRescan : createJob(objSubTypeJobRescanMsg)")
if err != nil { if err != nil {
return "Error scheduling the rescan for all msg", nil c := TGCommand{
Type: commandReplyMsg,
Text: "Error scheduling the rescan for all msg.",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
} else { } else {
return "Rescaning all msg scheduled", nil c := TGCommand{
Type: commandReplyMsg,
Text: "Rescaning all msg scheduled.",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
} }
return
} }