This commit is contained in:
shoopea 2020-05-08 16:02:18 +02:00
parent 8dae6e8e1d
commit 510926c11a
2 changed files with 74 additions and 1 deletions

57
bot.go
View File

@ -50,6 +50,8 @@ func BotHandlers(b *tb.Bot) {
b.Handle("/vault_other", botVaultOther)
b.Handle("/vault_item", botVaultItem)
b.Handle("/restart_job", botRestartJob)
b.Handle(tb.OnPhoto, botPhoto)
b.Handle(tb.OnChannelPost, botChannelPost)
b.Handle(tb.OnQuery, botQuery)
@ -820,7 +822,7 @@ func botShops(m *ChatWarsMessage) {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("Shops coming (ETA : %ds)", (len(cfg.Bot.Shops)/len(clts))*5),
Text: fmt.Sprintf("Shops coming (ETA : %ds)", (len(cfg.Bot.Shops)/len(clts))*8),
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
@ -1410,6 +1412,59 @@ func botTimer(m *tb.Message) {
return
}
func botRestartJob(m *tb.Message) {
if !m.Private() {
return
}
clt, ok := getLockedClient(m.Chat.ID, false)
if !ok {
c := TGCommand{
Type: commandReplyMsg,
Text: "Client not registered",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
clt.Mux.Unlock()
if len(m.Payload) > 0 {
jobID64, err := strconv.ParseInt(m.Payload, 10, 64)
if err != nil {
logOnError(err, "botRestartJob : ParseInt")
c := TGCommand{
Type: commandReplyMsg,
Text: "error",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
err := rescheduleJob(jobID64, 0, time.Now().UTC())
c := TGCommand{
Type: commandReplyMsg,
Text: "done",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
c := TGCommand{
Type: commandReplyMsg,
Text: "no Job ID",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
return
}
func botGetItemId(m *tb.Message) {
if len(m.Payload) > 0 {
objItemID64 := getObjItemID(``, m.Payload)

18
sql.go
View File

@ -623,6 +623,24 @@ func initDBViews() {
failOnError(err, "initDBViews : create view obj_shop_main_v")
log.Println("initDBViews : obj_shop_main_v created ...")
_, err = db.Exec(`CREATE VIEW obj_job_v AS
SELECT oj.obj_id
,o.obj_sub_type_id
,cost.intl_id COLLATE utf8mb4_unicode_ci AS obj_sub_type
,oj.is_done
,oj.in_work
,oj.trigger_id
,(SELECT costx.intl_id FROM code_obj_sub_type costx, obj ox WHERE ox.id = oj.trigger_id AND costx.id = ox.obj_sub_type_id) COLLATE utf8mb4_unicode_ci AS trigger_sub_type
,oj.inserted
,oj.ended
FROM obj o
,obj_job oj
,code_obj_sub_type cost
WHERE o.id = oj.obj_id
AND cost.id = o.obj_sub_type_id;`)
failOnError(err, "initDBViews : create view obj_job_v")
log.Println("initDBViews : obj_shop_main_v created ...")
log.Println("initDBViews : Views set up")
}