diff --git a/bot.go b/bot.go index 6f4a350..e37d87f 100644 --- a/bot.go +++ b/bot.go @@ -1012,6 +1012,38 @@ func botRefreshMsg(m *ChatWarsMessage, r *regexp.Regexp) { return } +func botVaultVal(m *ChatWarsMessage) { + p := JobPayloadVaultVal{ + MsgID64: m.ID64, + ChatID64: m.ChatID64, + Status: 0, + } + + b, _ := json.Marshal(p) + t := time.Now().UTC().Add(1 * time.Second) + _, err := createJob(cacheObjSubType[`job_alch_all`], objJobPriority, m.TGSenderUserID64, 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: "Vault val coming", + FromMsgID64: m.ID64, + FromChatID64: m.ChatID64, + } + TGCmdQueue <- c + } + + return +} + func botAlchAll(m *ChatWarsMessage) { p := JobPayloadAlchAll{ diff --git a/data/code_obj_sub_type.json b/data/code_obj_sub_type.json index e1d0e29..61850d7 100644 --- a/data/code_obj_sub_type.json +++ b/data/code_obj_sub_type.json @@ -739,6 +739,11 @@ "name": "Skill too low", "obj_type": "msg" }, + { + "intl_id": "msg_bot_vault_val", + "name": "Vault valuation", + "obj_type": "msg" + }, { "intl_id": "job_pillage", "name": "Pillage job", @@ -874,6 +879,11 @@ "name": "Check vault resource limit", "obj_type": "job" }, + { + "intl_id": "job_vault_val", + "name": "Check vault valuation", + "obj_type": "job" + }, { "intl_id": "item_res", "name": "Resource", diff --git a/def.go b/def.go index 04773bd..b327078 100644 --- a/def.go +++ b/def.go @@ -606,6 +606,13 @@ type JobPayloadCheckVaultLimit struct { VaultPostJobID64 int64 `json:"vault_post_job_id` } +type JobPayloadVaultVal struct { + MsgID64 int64 `json:"msg_id"` + ChatID64 int64 `json:"chat_id"` + Status int64 `json:"status"` + VaultJobID64 int64 `json:"vault_job_id` +} + type JobPayloadGetVault struct { Status int64 `json:"status"` JobCallbackID64 int64 `json:"job_callback_id"` diff --git a/job.go b/job.go index 2629e83..b405abe 100644 --- a/job.go +++ b/job.go @@ -2604,6 +2604,62 @@ func jobCheckVaultLimit(j Job) { } +func jobVaultVal(j Job) { + var ( + p JobPayloadVaultVal + p2 JobPayloadGetVault + ) + + err := setJobStart(j.ID64) + logOnError(err, "jobVaultVal : setJobStart") + + err = json.Unmarshal(j.Payload, &p) + logOnError(err, "jobVaultVal : Unmarshal payload") + + if p.Status == 0 { + p2.JobCallbackID64 = j.ID64 + p2.ItemTypeList = make([]int64, 1) + p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_other`]) + p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_rec`]) + p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_part`]) + + b, err = json.Marshal(p2) + logOnError(err, "jobVaultVal : Marshal(p2)") + + jobID64, err := createJob(cacheObjSubType[`job_get_vault`], objJobPriority, j.UserID64, 0, time.Now().UTC(), b) + + p.Status = 1 + p.VaultJobID64 = jobID64 + + b, err = json.Marshal(p) + logOnError(err, "jobVaultVal : Marshal(p)") + + err = setJobPayloadJSON(j.ID64, p) + logOnError(err, "jobVaultVal : setJobPayloadJSON(p)") + + rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC()) + return + } + + b = getJobPayload(p.VaultJobID64) + err = json.Unmarshal(b, &p2) + logOnError(err, "jobVaultVal : Unmarshal(p2)") + + c := TGCommand{ + Type: commandReplyMsg, + Text: "out", + ToMsgID64: p.MsgID64, + ToChatID64: p.ChatID64, + ParseMode: cmdParseModeHTML, + } + TGCmdQueue <- c + + err = setJobDone(j.ID64) + logOnError(err, "jobVaultVal : setJobDone") + + return +} + func jobShops(j Job) { var p JobPayloadShops diff --git a/msg.go b/msg.go index 760cc71..9b71107 100644 --- a/msg.go +++ b/msg.go @@ -360,7 +360,6 @@ func parseSubTypeMessageGStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*Cha if rq.MatchString(l[1]) { item.Quality = rq.ReplaceAllString(l[1], "${Quality}") } - log.Printf("Item : %s - %s : %s\n", item.Code, item.Name, item.Quality) stock = append(stock, item) } } @@ -389,7 +388,6 @@ func parseSubTypeMessageGStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*Cha default: item.Quality = `` } - log.Printf("Item : %s - %s : %s\n", item.Code, item.Name, item.Quality) stock = append(stock, item) } } diff --git a/rules.go b/rules.go index 5e16def..c54690d 100644 --- a/rules.go +++ b/rules.go @@ -229,6 +229,17 @@ func resetMsgParsingRules() error { } rules2 = append(rules2, r) + r = MessageParsingRule{ + Priority: 9999, + Description: "Vault valuation", + Rule: "^/vault_val$", + MsgTypeID64: cacheObjSubType[`msg_bot_vault_val`], + ChatID64: chats[id], + SenderUserID64: users[id], + BotCommand: true, + } + rules2 = append(rules2, r) + } // chats diff --git a/workers.go b/workers.go index b8a36d0..ad40757 100644 --- a/workers.go +++ b/workers.go @@ -584,6 +584,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) { _, err := parseSubTypeMessageAlchStockAck(m, rule.re) logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_alch_stock_ack`]") case cacheObjSubType[`msg_skill_too_low`]: + case cacheObjSubType[`msg_vault_val`]: + botVaultVal(m) case cacheObjSubType[`msg_refresh_cmd`]: botRefreshMsg(m, rule.re) default: @@ -697,6 +699,8 @@ func JobWorker(id int, jobs <-chan Job) { jobShopsSlave(j) case cacheObjSubType[`job_alch_all`]: jobAlchAll(j) + case cacheObjSubType[`job_vault_val`]: + jobVaultVal(j) default: log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID64) }