test shops new format

This commit is contained in:
shoopea 2020-02-07 15:20:52 +08:00
parent abd437ba60
commit 643126333f
2 changed files with 40 additions and 6 deletions

45
job.go
View File

@ -2206,23 +2206,56 @@ func jobShops(j Job) {
err = json.Unmarshal(j.Payload, &p)
logOnError(err, "jobShops : Unmarshal payload")
out := fmt.Sprintf("Shop summary:\n")
l := make([]int64, 0)
for _, m := range p.Msgs {
rule, err := getMsgParsingRule(&m)
logOnError(err, "jobShopsSlave : getMsgParsingRule")
if rule.MsgTypeID64 == cacheObjSubType[`msg_shop_main_ack`] {
cwm, err := parseSubTypeMessageShopMainAck(&m, rule.re)
l = append(l, m.ObjID64)
}
}
query := fmt.Sprintf(`SELECT omsm.obj_id id
FROM obj_msg_shop_main omsm
WHERE omsm.obj_id in (%d`+strings.Repeat(", %d", len(l)-1)+`)
ORDER BY COALESCE(omsm.guru, 'ZZZ') ASC
,omsm.open DESC
,omsm.mana DESC;`, l...)
ids := getSQLListID64(query)
guru := `ZZZ`
out := fmt.Sprintf("Shop summary:\n")
for _, id := range ids {
o, err := getObjMsg(id)
rule, err := getMsgParsingRule(o)
logOnError(err, "jobShopsSlave : getMsgParsingRule")
if rule.MsgTypeID64 == cacheObjSubType[`msg_shop_main_ack`] {
cwm, err := parseSubTypeMessageShopMainAck(o, rule.re)
logOnError(err, "jobShops : parseSubTypeMessageShopMainAck")
if cwm.Guru != guru {
guru = cwm.Guru
out = fmt.Sprintf("%s - %s\n", guru)
}
if cwm.Open {
out = fmt.Sprintf("%s ✔️", out)
out = fmt.Sprintf("%s ✔️", out)
} else {
out = fmt.Sprintf("%s ❌", out)
out = fmt.Sprintf("%s ❌", out)
}
c := getObjCastle(cwm.CastleID64)
out = fmt.Sprintf("%s%s", out, c.Logo)
out = fmt.Sprintf("%s<a href=\"https://t.me/share/url?url=/ws_%s\">%s</a>", out, cwm.Link, cwm.User)
out = fmt.Sprintf("%s [%d/%d]\n", out, cwm.Mana, cwm.ManaTotal)
out = fmt.Sprintf("%s [%d : %d]", out, cwm.Mana, cwm.ManaTotal)
if cwm.Mana < cwm.ManaTotal {
d := ((cwm.ManaTotal - cwm.Mana) / ((cwm.ManaTotal / 250) + 1)) * time.Minute
out = fmt.Sprintf("%s %s\n", out, d.String())
} else {
out = fmt.Sprintf("%s\n", out)
}
}
}
for _, m := range p.Msgs {
clientDelTGMsg(m.TGUserID64, m.ID64, m.ChatID64)
}
@ -2301,7 +2334,7 @@ func jobShopsSlave(j Job) {
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC()) // reschedule so that it gets picked up by shop main ack callback
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_shop_main_req`])
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_shop_main_ack`])
clientSendCWMsgDelay(j.UserID64, fmt.Sprintf("/ws_%s", p.Shops[0]), 6*time.Second)
clientSendCWMsgDelay(j.UserID64, fmt.Sprintf("/ws_%s", p.Shops[0]), 4*time.Second)
return
}

1
obj.go
View File

@ -534,6 +534,7 @@ func loadObjCastle() error {
c.Name = name
cacheObjCastle.Store(logo, *c)
cacheObjCastle.Store(name, *c)
cacheObjCastle.Store(id, *c)
}
return nil