test vault val

This commit is contained in:
shoopea 2020-06-28 13:12:05 +02:00
parent c3b8a24dbe
commit 400a690b5c
7 changed files with 120 additions and 2 deletions

32
bot.go
View File

@ -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{

View File

@ -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",

7
def.go
View File

@ -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"`

56
job.go
View File

@ -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

2
msg.go
View File

@ -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)
}
}

View File

@ -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

View File

@ -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)
}