From 7d38a0329b56b4633fa25d64384426c3dde3d5df Mon Sep 17 00:00:00 2001 From: shoopea Date: Sat, 1 Feb 2020 15:25:33 +0800 Subject: [PATCH] fix --- bot.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ def.go | 2 -- workers.go | 9 +-------- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/bot.go b/bot.go index 3e8c4be..379737d 100644 --- a/bot.go +++ b/bot.go @@ -771,6 +771,52 @@ func botCraftItem(m *ChatWarsMessage, r *regexp.Regexp) { return } +func botCraftAll(m *ChatWarsMessage, r *regexp.Regexp) { + clt, err := getLockedIdleClient() + if err != nil { + c := TGCommand{ + Type: commandReplyMsg, + Text: "Busy, please retry later.", + FromMsgID64: m.ID64, + FromChatID64: m.ChatID64, + } + TGCmdQueue <- c + return + } + userID64 := clt.TGUserID64 + clt.Mux.Unlock() + + p := JobPayloadCraftAll{ + MsgID64: m.ID64, + ChatID64: m.ChatID64, + Status: 0, + } + + b, _ := json.Marshal(p) + t := time.Now().UTC().Add(1 * time.Second) + _, err = createJob(cacheObjSubType[`job_craft_all`], objJobPriority, userID64, 0, t, b) + + if err != nil { + c := TGCommand{ + Type: commandReplyMsg, + Text: fmt.Sprintf("%s", err), + FromMsgID64: m.ID64, + FromChatID64: m.ChatID64, + } + TGCmdQueue <- c + } else { + c := TGCommand{ + Type: commandReplyMsg, + Text: "Craft all coming", + FromMsgID64: m.ID64, + FromChatID64: m.ChatID64, + } + TGCmdQueue <- c + } + + return +} + func botSaveRes(m *tb.Message) { if !m.Private() { return diff --git a/def.go b/def.go index f3f5828..d5e801c 100644 --- a/def.go +++ b/def.go @@ -493,7 +493,6 @@ type JobPayloadVaultItemStatus struct { type JobPayloadCraftItem struct { MsgID64 int64 `json:"msg_id"` ChatID64 int64 `json:"chat_id"` - UserID64 int64 `json:"user_id"` ObjItemID64 int64 `json:"item_id"` Quantity int64 `json:"quantity"` Status int64 `json:"status"` @@ -503,7 +502,6 @@ type JobPayloadCraftItem struct { type JobPayloadCraftAll struct { MsgID64 int64 `json:"msg_id"` ChatID64 int64 `json:"chat_id"` - UserID64 int64 `json:"user_id"` Status int64 `json:"status"` VaultJobID64 int64 `json:"vault_job_id"` } diff --git a/workers.go b/workers.go index 2144de8..3c528e8 100644 --- a/workers.go +++ b/workers.go @@ -513,14 +513,7 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) { case cacheObjSubType[`msg_bot_craft_item`]: botCraftItem(m, rule.re) case cacheObjSubType[`msg_bot_craft_all`]: - c := TGCommand{ - Type: commandReplyMsg, - Text: `Not implemented yet`, - FromMsgID64: m.ID64, - FromChatID64: m.ChatID64, - ParseMode: cmdParseModeHTML, - } - TGCmdQueue <- c + botCraftAll(m, rule.re) default: //log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Unknwon message type in rule %d : %d (%d)\n%s\n", msgParsingRules[i].ID, msgParsingRules[i].MsgTypeID64, objId, m.Text) }