test g withdraw update

This commit is contained in:
shoopea 2020-01-13 16:03:01 +08:00
parent 3bf7a9d555
commit 48155d8cd4
3 changed files with 87 additions and 11 deletions

18
bot.go
View File

@ -654,6 +654,7 @@ func botGStock(m *tb.Message) {
FromChatID64: m.Chat.ID, FromChatID64: m.Chat.ID,
} }
TGCmdQueue <- c TGCmdQueue <- c
return
} }
userID64 := clt.TGUserID64 userID64 := clt.TGUserID64
clt.Mux.Unlock() clt.Mux.Unlock()
@ -929,6 +930,20 @@ func botGWithdraw(m *tb.Message) {
return 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]+( )*)+$") r := regexp.MustCompile("^(( )*[a-z0-9]+ [0-9]+( )*)+$")
if r.MatchString(m.Payload) { if r.MatchString(m.Payload) {
rx := regexp.MustCompile("(?P<Item>[a-z0-9]+) (?P<Quantity>[0-9]+)") rx := regexp.MustCompile("(?P<Item>[a-z0-9]+) (?P<Quantity>[0-9]+)")
@ -952,7 +967,8 @@ func botGWithdraw(m *tb.Message) {
b, _ := json.Marshal(p) b, _ := json.Marshal(p)
t := time.Now().UTC() 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 { if err != nil {
c := TGCommand{ c := TGCommand{
Type: commandReplyMsg, Type: commandReplyMsg,

4
def.go
View File

@ -340,7 +340,9 @@ type JobPayloadMsgFwd struct {
} }
type JobPayloadMsgDel 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 { type JobPayloadMsgRefresh struct {

76
job.go
View File

@ -1380,55 +1380,113 @@ func jobGWithdraw(j Job) {
p.Status = p.Status | reqTab[cacheObjSubType[`item_other`]] 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`]] 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`]] 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`]] 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`]] 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`]] 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`]] 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`]] { if (p.Status & reqTab[cacheObjSubType[`item_res`]]) == reqTab[cacheObjSubType[`item_res`]] {
log.Printf("jobGWithdraw : Requesting res.\n") log.Printf("jobGWithdraw : Requesting res.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_res`]] p.Status = p.Status &^ reqTab[cacheObjSubType[`item_res`]]
p.Status = p.Status | doneTab[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`]] { } else if (p.Status & reqTab[cacheObjSubType[`item_alch`]]) == reqTab[cacheObjSubType[`item_alch`]] {
log.Printf("jobGWithdraw : Requesting alch.\n") log.Printf("jobGWithdraw : Requesting alch.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_alch`]] p.Status = p.Status &^ reqTab[cacheObjSubType[`item_alch`]]
p.Status = p.Status | doneTab[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`]] { } else if (p.Status & reqTab[cacheObjSubType[`item_misc`]]) == reqTab[cacheObjSubType[`item_misc`]] {
log.Printf("jobGWithdraw : Requesting misc.\n") log.Printf("jobGWithdraw : Requesting misc.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_misc`]] p.Status = p.Status &^ reqTab[cacheObjSubType[`item_misc`]]
p.Status = p.Status | doneTab[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`]] { } else if (p.Status & reqTab[cacheObjSubType[`item_recipe`]]) == reqTab[cacheObjSubType[`item_recipe`]] {
log.Printf("jobGWithdraw : Requesting recipe.\n") log.Printf("jobGWithdraw : Requesting recipe.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_recipe`]] p.Status = p.Status &^ reqTab[cacheObjSubType[`item_recipe`]]
p.Status = p.Status | doneTab[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`]] { } else if (p.Status & reqTab[cacheObjSubType[`item_part`]]) == reqTab[cacheObjSubType[`item_part`]] {
log.Printf("jobGWithdraw : Requesting part.\n") log.Printf("jobGWithdraw : Requesting part.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_part`]] p.Status = p.Status &^ reqTab[cacheObjSubType[`item_part`]]
p.Status = p.Status | doneTab[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`]] { } else if (p.Status & reqTab[cacheObjSubType[`item_other`]]) == reqTab[cacheObjSubType[`item_other`]] {
log.Printf("jobGWithdraw : Requesting other.\n") log.Printf("jobGWithdraw : Requesting other.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_other`]] p.Status = p.Status &^ reqTab[cacheObjSubType[`item_other`]]
p.Status = p.Status | doneTab[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) err = setJobDone(j.ID64)