update resource ack

This commit is contained in:
shoopea 2019-08-27 11:58:23 +08:00
parent f9a51b54a0
commit ae32a555f5
3 changed files with 19 additions and 9 deletions

13
job.go
View File

@ -734,7 +734,9 @@ func jobGDeposit(j Job) {
if p.Status == 0 { /* handle remaining resources to be stored */ if p.Status == 0 { /* handle remaining resources to be stored */
var res, misc, alch, craft, equip bool = false, false, false, false, false var res, misc, alch, craft, equip bool = false, false, false, false, false
log.Printf("jobGDeposit : Checking items (%d).\n", len(p.ResObjID64)) var delay time.Duration = 0 * time.Second
var b []byte
if len(p.ResObjID64) > 0 { if len(p.ResObjID64) > 0 {
for i := range p.ResObjID64 { for i := range p.ResObjID64 {
obj, err := getObjItem(p.ResObjID64[i]) obj, err := getObjItem(p.ResObjID64[i])
@ -760,43 +762,36 @@ func jobGDeposit(j Job) {
} }
} }
} }
log.Printf("jobGDeposit : Sending messages.\n")
var delay time.Duration = 10 * time.Second
var b []byte
if res || alch || misc || craft || equip { if res || alch || misc || craft || equip {
p.Status = 1 p.Status = 1
b, _ = json.Marshal(&p) b, _ = json.Marshal(&p)
} }
if res { if res {
log.Printf("jobGDeposit : Sending res.\n")
clientSendCWMsgDelay(p.ChatID64, `📦Resources`, delay) clientSendCWMsgDelay(p.ChatID64, `📦Resources`, delay)
err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, delay) err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, delay)
logOnError(err, "jobGDeposit : createJobCallback") logOnError(err, "jobGDeposit : createJobCallback")
delay = delay + 2*time.Second delay = delay + 2*time.Second
} }
if alch { if alch {
log.Printf("jobGDeposit : Sending alch.\n")
clientSendCWMsgDelay(p.ChatID64, `Alchemy`, delay) clientSendCWMsgDelay(p.ChatID64, `Alchemy`, delay)
err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, delay) err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, delay)
logOnError(err, "jobGDeposit : createJobCallback") logOnError(err, "jobGDeposit : createJobCallback")
delay = delay + 2*time.Second delay = delay + 2*time.Second
} }
if misc { if misc {
log.Printf("jobGDeposit : Sending misc.\n")
clientSendCWMsgDelay(p.ChatID64, `🗃Misc`, delay) clientSendCWMsgDelay(p.ChatID64, `🗃Misc`, delay)
err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, delay) err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, delay)
logOnError(err, "jobGDeposit : createJobCallback") logOnError(err, "jobGDeposit : createJobCallback")
delay = delay + 2*time.Second delay = delay + 2*time.Second
} }
if craft { if craft {
log.Printf("jobGDeposit : Sending craft.\n")
clientSendCWMsgDelay(p.ChatID64, `⚒Crafting`, delay) clientSendCWMsgDelay(p.ChatID64, `⚒Crafting`, delay)
err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, delay) err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, delay)
logOnError(err, "jobGDeposit : createJobCallback") logOnError(err, "jobGDeposit : createJobCallback")
delay = delay + 2*time.Second delay = delay + 2*time.Second
} }
if equip { if equip {
log.Printf("jobGDeposit : Sending equip.\n")
clientSendCWMsgDelay(p.ChatID64, `🏷Equipment`, delay) clientSendCWMsgDelay(p.ChatID64, `🏷Equipment`, delay)
err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, delay) err = createJobCallback(objSubTypeJobGDeposit, j.UserID64, objSubTypeMessageOrderbookAck, b, delay)
logOnError(err, "jobGDeposit : createJobCallback") logOnError(err, "jobGDeposit : createJobCallback")

12
msg.go
View File

@ -43,6 +43,18 @@ func parseSubTypeMessageStockAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWar
items = append(items, item) items = append(items, item)
} }
} }
re := regexp.MustCompile(`\n\/sg_[0-9]+ ([a-zA-Z ]+) \(([0-9]+)\)`)
for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Items}"), -1) {
i := getObjItemID(``, l[1])
q, _ := strconv.ParseInt(l[2], 10, 64)
if i != 0 {
item := ChatWarsItems{
ItemID64: i,
Quantity: q,
}
items = append(items, item)
}
}
cwm.Used, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Used}"), 10, 64) cwm.Used, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Used}"), 10, 64)
cwm.Available, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Available}"), 10, 64) cwm.Available, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Available}"), 10, 64)
cwm.Stock = items cwm.Stock = items

View File

@ -123,6 +123,9 @@ func resetMsgParsingRules() {
,(5000, ` + strconv.Itoa(objSubTypeMessageStockReq) + `, "Stock Req", "^/stock$") ,(5000, ` + strconv.Itoa(objSubTypeMessageStockReq) + `, "Stock Req", "^/stock$")
,(5000, ` + strconv.Itoa(objSubTypeMessageStockAck) + `, "Stock Ack", "^📦Storage \\((?P<Used>[0-9]+)\\/(?P<Available>[0-9]+)\\):` + ,(5000, ` + strconv.Itoa(objSubTypeMessageStockAck) + `, "Stock Ack", "^📦Storage \\((?P<Used>[0-9]+)\\/(?P<Available>[0-9]+)\\):` +
`(?P<Items>(\\n[a-zA-Z ]+ \\([0-9]+\\))*)$") `(?P<Items>(\\n[a-zA-Z ]+ \\([0-9]+\\))*)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageStockAck) + `, "Stock Ack", "^📦Storage \\((?P<Used>[0-9]+)\\/(?P<Available>[0-9]+)\\):` +
`Use \\/sg_\\{code\\} to trade some amount of resource for .* 💰 \\/pcs\\n` +
`(?P<Items>(\\n\\/sg_[0-9]+ [a-zA-Z ]+ \\([0-9]+\\))*)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageMiscReq) + `, "Misc Req", "^/misc$")` + /* ,(5000, ` + strconv.Itoa(objSubTypeMessageMiscReq) + `, "Misc Req", "^/misc$")` + /*
,(5000, ` + strconv.Itoa(objSubTypeMessageUnionWar) + `, "Union war report", "^(🏠Trade union news:\\n){0,1}` + ,(5000, ` + strconv.Itoa(objSubTypeMessageUnionWar) + `, "Union war report", "^(🏠Trade union news:\\n){0,1}` +
`(((?P<Union>[A-Z][a-z]+ [A-Z][a-z]+) was (?P<StatusUnion>(easily defended|defended successfully|breached.|easily breached.|closely breached.))( Attackers have pillaged union for (?P<Loot>[0-9]+) stock){0,1}:\\n` + `(((?P<Union>[A-Z][a-z]+ [A-Z][a-z]+) was (?P<StatusUnion>(easily defended|defended successfully|breached.|easily breached.|closely breached.))( Attackers have pillaged union for (?P<Loot>[0-9]+) stock){0,1}:\\n` +