test get stash

This commit is contained in:
shoopea 2020-06-19 21:28:59 +02:00
parent e027d759b4
commit b4f1c7dd86
6 changed files with 114 additions and 0 deletions

64
bot.go
View File

@ -1073,6 +1073,70 @@ func botCraftAll(m *ChatWarsMessage, r *regexp.Regexp) {
return return
} }
func botGetStash(m *ChatWarsMessage, r *regexp.Regexp) {
if hasUnfinishedJob(cacheObjSubType[`job_get_stash`]) {
c := TGCommand{
Type: commandReplyMsg,
Text: "Get Stash is already running",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
return
}
p := JobPayloadGetStash{
MsgID64: m.ID64,
ChatID64: m.ChatID64,
ClientCount: 0,
}
busy := time.Now().UTC()
muxClients.RLock()
for _, c := range clients {
if c.Active {
p.ClientCount++
p.ClientID64 = append(p.ClientID64, c.TGUserID64)
if c.CWBusyUntil > busy {
busy = c.CWBusyUntil
}
}
}
muxClients.RUnlock()
b, _ := json.Marshal(p)
t := time.Now().UTC().Add(1 * time.Second)
_, err = createJob(cacheObjSubType[`job_get_stash`], 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 if busy.After(time.Now().UTC()) {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("Clients busy, delayed for %v.", busy.Sub(time.Now().UTC())),
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "Stash coming.",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
}
return
}
func botSaveRes(m *tb.Message) { func botSaveRes(m *tb.Message) {
if !m.Private() { if !m.Private() {
return return

View File

@ -649,6 +649,11 @@
"name": "Craft check for all items", "name": "Craft check for all items",
"obj_type": "msg" "obj_type": "msg"
}, },
{
"intl_id": "msg_bot_get_stash",
"name": "List exchange deals on hold",
"obj_type": "msg"
},
{ {
"intl_id": "msg_bot_shops", "intl_id": "msg_bot_shops",
"name": "Check all shops", "name": "Check all shops",
@ -839,6 +844,11 @@
"name": "Craft all items summary job", "name": "Craft all items summary job",
"obj_type": "job" "obj_type": "job"
}, },
{
"intl_id": "job_get_stash",
"name": "Get Stash job",
"obj_type": "job"
},
{ {
"intl_id": "job_alch_all", "intl_id": "job_alch_all",
"name": "Craft all items in stock job", "name": "Craft all items in stock job",

7
def.go
View File

@ -624,6 +624,13 @@ type JobPayloadShopsSlave struct {
Slaves int64 `json:"slaves"` Slaves int64 `json:"slaves"`
} }
type JobPayloadGetStash struct {
ClientID64 []int64 `json:"clients_id"`
ClientCount int64 `json:"client_count"`
Stock []ChatWarsItems `json:"stock"`
CleanupMsg []ChatWarsMessage `json:"cleanup_msg"`
}
const ( const (
userID64ChtWrsBot = 408101137 userID64ChtWrsBot = 408101137

18
job.go
View File

@ -2069,6 +2069,24 @@ func jobCraftItem(j Job) {
} }
func jobGetStash(j Job) {
var (
p JobPayloadGetStash
)
err := setJobStart(j.ID64)
logOnError(err, "jobGetStash : setJobStart")
err = json.Unmarshal(j.Payload, &p)
logOnError(err, "jobGetStash : Unmarshal payload")
err = setJobDone(j.ID64)
logOnError(err, "jobGetStash : setJobDone")
return
}
func jobAlchAll(j Job) { func jobAlchAll(j Job) {
var ( var (
p JobPayloadAlchAll p JobPayloadAlchAll

View File

@ -191,6 +191,17 @@ func resetMsgParsingRules() error {
SenderUserID64: users[id], SenderUserID64: users[id],
} }
rules2 = append(rules2, r) rules2 = append(rules2, r)
r = MessageParsingRule{
Priority: 9999,
Description: "List exchange deals on hold",
Rule: "^/stash$",
MsgTypeID64: cacheObjSubType[`msg_bot_get_stash`],
ChatID64: chats[id],
SenderUserID64: users[id],
}
rules2 = append(rules2, r)
} }
// chats // chats

View File

@ -530,6 +530,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
botCraftItem(m, rule.re) botCraftItem(m, rule.re)
case cacheObjSubType[`msg_bot_craft_all`]: case cacheObjSubType[`msg_bot_craft_all`]:
botCraftAll(m, rule.re) botCraftAll(m, rule.re)
case cacheObjSubType[`msg_bot_get_stash`]:
botGetStash(m, rule.re)
case cacheObjSubType[`msg_tributes_stats_req`]: case cacheObjSubType[`msg_tributes_stats_req`]:
case cacheObjSubType[`msg_tributes_stats_ack`]: case cacheObjSubType[`msg_tributes_stats_ack`]:
cwm, err := parseSubTypeMessageTributesStatsAck(m, rule.re) cwm, err := parseSubTypeMessageTributesStatsAck(m, rule.re)
@ -665,6 +667,8 @@ func JobWorker(id int, jobs <-chan Job) {
jobGetVault(j) jobGetVault(j)
case cacheObjSubType[`job_craft_item`]: case cacheObjSubType[`job_craft_item`]:
jobCraftItem(j) jobCraftItem(j)
case cacheObjSubType[`job_get_stash`]:
jobGetStash(j)
case cacheObjSubType[`job_craft_all`]: case cacheObjSubType[`job_craft_all`]:
jobCraftAll(j) jobCraftAll(j)
case cacheObjSubType[`job_check_vault_limit`]: case cacheObjSubType[`job_check_vault_limit`]: