From 48155d8cd41c4d6994b5402742401d51abae4455 Mon Sep 17 00:00:00 2001 From: shoopea Date: Mon, 13 Jan 2020 16:03:01 +0800 Subject: [PATCH] test g withdraw update --- bot.go | 18 +++++++++++++- def.go | 4 +++- job.go | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 87 insertions(+), 11 deletions(-) diff --git a/bot.go b/bot.go index 1fb8d49..f9125b5 100644 --- a/bot.go +++ b/bot.go @@ -654,6 +654,7 @@ func botGStock(m *tb.Message) { FromChatID64: m.Chat.ID, } TGCmdQueue <- c + return } userID64 := clt.TGUserID64 clt.Mux.Unlock() @@ -929,6 +930,20 @@ func botGWithdraw(m *tb.Message) { return } + clt, err := getLockedIdleClient() + if err != nil { + c := TGCommand{ + Type: commandReplyMsg, + Text: "Busy, please retry later.", + FromMsgID64: int64(m.ID), + FromChatID64: m.Chat.ID, + } + TGCmdQueue <- c + return + } + userID64 := clt.TGUserID64 + clt.Mux.Unlock() + r := regexp.MustCompile("^(( )*[a-z0-9]+ [0-9]+( )*)+$") if r.MatchString(m.Payload) { rx := regexp.MustCompile("(?P[a-z0-9]+) (?P[0-9]+)") @@ -952,7 +967,8 @@ func botGWithdraw(m *tb.Message) { b, _ := json.Marshal(p) t := time.Now().UTC() - _, err := createJob(cacheObjSubType[`job_gwithdraw`], objJobPriority, int64(m.Chat.ID), 0, t, b) + // _, err := createJob(cacheObjSubType[`job_gwithdraw`], objJobPriority, userID64, 0, t, b) + _, err := createJob(cacheObjSubType[`job_gwithdraw`], objJobPriority, cfg.Bot.Admin, 0, t, b) // FIXME back to normal user if err != nil { c := TGCommand{ Type: commandReplyMsg, diff --git a/def.go b/def.go index bac2aae..6008e34 100644 --- a/def.go +++ b/def.go @@ -340,7 +340,9 @@ type JobPayloadMsgFwd struct { } type JobPayloadMsgDel struct { - ObjMsgID64 int64 `json:"obj_msg_id"` + ObjMsgID64 int64 `json:"obj_msg_id"` + Delay time.Duration `json:"delay"` + MsgTypeID64 int64 `json:"msg_type_id"` } type JobPayloadMsgRefresh struct { diff --git a/job.go b/job.go index f98bf89..103a548 100644 --- a/job.go +++ b/job.go @@ -1380,55 +1380,113 @@ func jobGWithdraw(j Job) { p.Status = p.Status | reqTab[cacheObjSubType[`item_other`]] } } - if p.Status&reqTab[cacheObjSubType[`item_res`]] == 0 { + if (p.Status & reqTab[cacheObjSubType[`item_res`]]) == 0 { p.Status = p.Status | doneTab[cacheObjSubType[`item_res`]] } - if p.Status&reqTab[cacheObjSubType[`item_alch`]] == 0 { + if (p.Status & reqTab[cacheObjSubType[`item_alch`]]) == 0 { p.Status = p.Status | doneTab[cacheObjSubType[`item_alch`]] } - if p.Status&reqTab[cacheObjSubType[`item_misc`]] == 0 { + if (p.Status & reqTab[cacheObjSubType[`item_misc`]]) == 0 { p.Status = p.Status | doneTab[cacheObjSubType[`item_misc`]] } - if p.Status&reqTab[cacheObjSubType[`item_recipe`]] == 0 { + if (p.Status & reqTab[cacheObjSubType[`item_recipe`]]) == 0 { p.Status = p.Status | doneTab[cacheObjSubType[`item_recipe`]] } - if p.Status&reqTab[cacheObjSubType[`item_part`]] == 0 { + if (p.Status & reqTab[cacheObjSubType[`item_part`]]) == 0 { p.Status = p.Status | doneTab[cacheObjSubType[`item_part`]] } - if p.Status&reqTab[cacheObjSubType[`item_other`]] == 0 { + if (p.Status & reqTab[cacheObjSubType[`item_other`]]) == 0 { p.Status = p.Status | doneTab[cacheObjSubType[`item_other`]] } } - b, _ := json.Marshal(p) - log.Printf("jobGWithdraw : %s\n", string(b)) - if (p.Status & reqTab[cacheObjSubType[`item_res`]]) == reqTab[cacheObjSubType[`item_res`]] { log.Printf("jobGWithdraw : Requesting res.\n") p.Status = p.Status &^ reqTab[cacheObjSubType[`item_res`]] p.Status = p.Status | doneTab[cacheObjSubType[`item_res`]] + b, _ := json.Marshal(p) + p2 := JobPayloadMsgDel{ + MsgTypeID64: cacheObjSubType[`msg_gstock_res_req`], + Delay: (10 * time.Second), + } + b2, _ := json.Marshal(p2) + createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute) + createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute) + clientSendCWMsg(`/g_stock_res`) } else if (p.Status & reqTab[cacheObjSubType[`item_alch`]]) == reqTab[cacheObjSubType[`item_alch`]] { log.Printf("jobGWithdraw : Requesting alch.\n") p.Status = p.Status &^ reqTab[cacheObjSubType[`item_alch`]] p.Status = p.Status | doneTab[cacheObjSubType[`item_alch`]] + + b, _ := json.Marshal(p) + p2 := JobPayloadMsgDel{ + MsgTypeID64: cacheObjSubType[`msg_gstock_alch_req`], + Delay: (10 * time.Second), + } + b2, _ := json.Marshal(p2) + createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute) + createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute) + clientSendCWMsg(`/g_stock_alch`) } else if (p.Status & reqTab[cacheObjSubType[`item_misc`]]) == reqTab[cacheObjSubType[`item_misc`]] { log.Printf("jobGWithdraw : Requesting misc.\n") p.Status = p.Status &^ reqTab[cacheObjSubType[`item_misc`]] p.Status = p.Status | doneTab[cacheObjSubType[`item_misc`]] + + b, _ := json.Marshal(p) + p2 := JobPayloadMsgDel{ + MsgTypeID64: cacheObjSubType[`msg_gstock_misc_req`], + Delay: (10 * time.Second), + } + b2, _ := json.Marshal(p2) + createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute) + createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute) + clientSendCWMsg(`/g_stock_misc`) } else if (p.Status & reqTab[cacheObjSubType[`item_recipe`]]) == reqTab[cacheObjSubType[`item_recipe`]] { log.Printf("jobGWithdraw : Requesting recipe.\n") p.Status = p.Status &^ reqTab[cacheObjSubType[`item_recipe`]] p.Status = p.Status | doneTab[cacheObjSubType[`item_recipe`]] + + b, _ := json.Marshal(p) + p2 := JobPayloadMsgDel{ + MsgTypeID64: cacheObjSubType[`msg_gstock_rec_req`], + Delay: (10 * time.Second), + } + b2, _ := json.Marshal(p2) + createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute) + createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute) + clientSendCWMsg(`/g_stock_rec`) } else if (p.Status & reqTab[cacheObjSubType[`item_part`]]) == reqTab[cacheObjSubType[`item_part`]] { log.Printf("jobGWithdraw : Requesting part.\n") p.Status = p.Status &^ reqTab[cacheObjSubType[`item_part`]] p.Status = p.Status | doneTab[cacheObjSubType[`item_part`]] + + b, _ := json.Marshal(p) + p2 := JobPayloadMsgDel{ + MsgTypeID64: cacheObjSubType[`msg_gstock_part_req`], + Delay: (10 * time.Second), + } + b2, _ := json.Marshal(p2) + createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute) + createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute) + clientSendCWMsg(`/g_stock_part`) } else if (p.Status & reqTab[cacheObjSubType[`item_other`]]) == reqTab[cacheObjSubType[`item_other`]] { log.Printf("jobGWithdraw : Requesting other.\n") p.Status = p.Status &^ reqTab[cacheObjSubType[`item_other`]] p.Status = p.Status | doneTab[cacheObjSubType[`item_other`]] + + b, _ := json.Marshal(p) + p2 := JobPayloadMsgDel{ + MsgTypeID64: cacheObjSubType[`msg_gstock_oth_req`], + Delay: (10 * time.Second), + } + b2, _ := json.Marshal(p2) + createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute) + createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute) + clientSendCWMsg(`/g_stock_other`) + } else { + log.Printf("jobGWithdraw : got all the info\n") } err = setJobDone(j.ID64)