update g deposit
This commit is contained in:
parent
10c342f472
commit
574834b2b9
1
bot.go
1
bot.go
@ -639,6 +639,7 @@ func botGDepositAll(m *tb.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`01`, `Thread`))
|
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`01`, `Thread`))
|
||||||
|
/*
|
||||||
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`02`, `Stick`))
|
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`02`, `Stick`))
|
||||||
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`03`, `Pelt`))
|
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`03`, `Pelt`))
|
||||||
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`04`, `Bone`))
|
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`04`, `Bone`))
|
||||||
|
5
def.go
5
def.go
@ -274,11 +274,6 @@ type JobPayloadGDeposit struct {
|
|||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type JobPayloadGDepositForward struct {
|
|
||||||
ItemID64 int64 `json:"item_id"`
|
|
||||||
Quantity int64 `json:"quantity"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type JobPayloadSaveRes struct {
|
type JobPayloadSaveRes struct {
|
||||||
MsgID64 int64 `json:"msg_id"`
|
MsgID64 int64 `json:"msg_id"`
|
||||||
ChatID64 int64 `json:"chat_id"`
|
ChatID64 int64 `json:"chat_id"`
|
||||||
|
11
job.go
11
job.go
@ -737,18 +737,20 @@ func jobGDepositForward(j Job) {
|
|||||||
logOnError(err, "jobGDepositForward : getObjMsg")
|
logOnError(err, "jobGDepositForward : getObjMsg")
|
||||||
rule, err := getMsgParsingRule(msg)
|
rule, err := getMsgParsingRule(msg)
|
||||||
logOnError(err, "jobGDepositForward : getMsgParsingRule")
|
logOnError(err, "jobGDepositForward : getMsgParsingRule")
|
||||||
cwm, err := parseSubTypeMessageGDepositAck(msg, rule.re)
|
cwm, err := parseSubTypeMessageGDepositReq(msg, rule.re)
|
||||||
|
|
||||||
if cwm.ItemID64 == p.ItemID64 && cwm.Quantity == p.Quantity {
|
if cwm.ItemID64 == p.ItemID64 && cwm.Quantity == p.Quantity {
|
||||||
//log.Printf("jobGDepositForward : match (%d / %d).\n", cwm.ItemID64, cwm.Quantity)
|
//log.Printf("jobGDepositForward : match (%d / %d).\n", cwm.ItemID64, cwm.Quantity)
|
||||||
clientFwdCWMsg(j.UserID64, cwm.Msg.ID64, cwm.Msg.ChatID64, cfg.Bot.Depositchat)
|
gDepositForwardMux.Lock()
|
||||||
|
gDepositForwardMsg = append(gDepositForwardMsg, j.Trigger)
|
||||||
|
gDepositForwardMux.Unlock()
|
||||||
err = setJobDone(j.ID64)
|
err = setJobDone(j.ID64)
|
||||||
logOnError(err, "jobGDeposit : setJobDone")
|
logOnError(err, "jobGDeposit : setJobDone")
|
||||||
} else {
|
} else {
|
||||||
//log.Printf("jobGDepositForward : found (%d / %d), expected (%d / %d).\n", cwm.ItemID64, cwm.Quantity, p.ItemID64, p.Quantity)
|
//log.Printf("jobGDepositForward : found (%d / %d), expected (%d / %d).\n", cwm.ItemID64, cwm.Quantity, p.ItemID64, p.Quantity)
|
||||||
err = rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
|
err = rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
|
||||||
logOnError(err, "jobGDepositForward : rescheduleJob")
|
logOnError(err, "jobGDepositForward : rescheduleJob")
|
||||||
setJobCallback(j.ID64, j.UserID64, objSubTypeMessageGDepositAck)
|
setJobCallback(j.ID64, j.UserID64, objSubTypeMessageGDepositReq)
|
||||||
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -850,13 +852,14 @@ func jobGDeposit(j Job) {
|
|||||||
if cwm.Stock[stockIdx].ItemID64 == p.ResObjID64[resIdx] {
|
if cwm.Stock[stockIdx].ItemID64 == p.ResObjID64[resIdx] {
|
||||||
//log.Printf("jobGDeposit : objSubTypeMessageStockAck : Matching ItemID %d (%d).\n", p.ResObjID64[resIdx], cwm.Stock[stockIdx].Quantity)
|
//log.Printf("jobGDeposit : objSubTypeMessageStockAck : Matching ItemID %d (%d).\n", p.ResObjID64[resIdx], cwm.Stock[stockIdx].Quantity)
|
||||||
item, _ := getObjItem(p.ResObjID64[resIdx])
|
item, _ := getObjItem(p.ResObjID64[resIdx])
|
||||||
|
cwm.Stock[stockIdx].Quantity = 1 // FIXME REMOVE ONCE DEBUG IS OK
|
||||||
clientSendCWMsg(p.ChatID64, fmt.Sprintf("/g_deposit %s %d", item.Code, cwm.Stock[stockIdx].Quantity))
|
clientSendCWMsg(p.ChatID64, fmt.Sprintf("/g_deposit %s %d", item.Code, cwm.Stock[stockIdx].Quantity))
|
||||||
p2 := JobPayloadGDepositForward{
|
p2 := JobPayloadGDepositForward{
|
||||||
ItemID64: p.ResObjID64[resIdx],
|
ItemID64: p.ResObjID64[resIdx],
|
||||||
Quantity: cwm.Stock[stockIdx].Quantity,
|
Quantity: cwm.Stock[stockIdx].Quantity,
|
||||||
}
|
}
|
||||||
b2, _ := json.Marshal(p2)
|
b2, _ := json.Marshal(p2)
|
||||||
err = createJobCallback(objSubTypeJobGDepositForward, j.UserID64, objSubTypeMessageGDepositAck, b2, time.Duration(1*time.Minute))
|
err = createJobCallback(objSubTypeJobGDepositForward, j.UserID64, objSubTypeMessageGDepositReq, b2, time.Duration(1*time.Minute))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
main.go
3
main.go
@ -68,6 +68,9 @@ var (
|
|||||||
|
|
||||||
callbacks map[int64]map[int64][]int64
|
callbacks map[int64]map[int64][]int64
|
||||||
muxCallbacks sync.Mutex
|
muxCallbacks sync.Mutex
|
||||||
|
|
||||||
|
gDepositForwardMux sync.Mutex
|
||||||
|
gDepositForwardMsg []int64
|
||||||
)
|
)
|
||||||
|
|
||||||
func PrintText(m *tb.Message) {
|
func PrintText(m *tb.Message) {
|
||||||
|
30
msg.go
30
msg.go
@ -23,12 +23,42 @@ func getMsgParsingRule(m *ChatWarsMessage) (*MessageParsingRule, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseSubTypeMessageGDepositReq(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageGDepositReq, error) {
|
||||||
|
cwm := ChatWarsMessageGDepositReq{}
|
||||||
|
|
||||||
|
cwm.ItemID64 = getObjItemID(r.ReplaceAllString(m.Text, "${Item}"), ``) // FIXME, handle uXXX items ?
|
||||||
|
cwm.Quantity, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Quantity}"), 10, 64)
|
||||||
|
|
||||||
|
cwm.Msg = m
|
||||||
|
return &cwm, nil
|
||||||
|
}
|
||||||
|
|
||||||
func parseSubTypeMessageGDepositAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageGDepositAck, error) {
|
func parseSubTypeMessageGDepositAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageGDepositAck, error) {
|
||||||
cwm := ChatWarsMessageGDepositAck{}
|
cwm := ChatWarsMessageGDepositAck{}
|
||||||
|
|
||||||
cwm.ItemID64 = getObjItemID(``, r.ReplaceAllString(m.Text, "${Item}"))
|
cwm.ItemID64 = getObjItemID(``, r.ReplaceAllString(m.Text, "${Item}"))
|
||||||
cwm.Quantity, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Quantity}"), 10, 64)
|
cwm.Quantity, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Quantity}"), 10, 64)
|
||||||
|
|
||||||
|
gDepositForwardMux.Lock()
|
||||||
|
for i := range gDepositForwardMsg {
|
||||||
|
msg, err := getObjMsg(gDepositForwardMsg[i])
|
||||||
|
logOnError(err, "parseSubTypeMessageGDepositAck : gDepositForwardMsg")
|
||||||
|
if err == nil && m.TGUserID64 == msg.TGUserID64 {
|
||||||
|
rule, err := getMsgParsingRule(msg)
|
||||||
|
logOnError(err, "parseSubTypeMessageGDepositAck : getMsgParsingRule")
|
||||||
|
cwmreq, err := parseSubTypeMessageGDepositReq(msg, rule.re)
|
||||||
|
logOnError(err, "parseSubTypeMessageGDepositAck : parseSubTypeMessageGDepositReq")
|
||||||
|
if err == nil && cwmreq.ItemID64 == cwm.ItemID64 && cwmreq.Quantity == cwm.Quantity {
|
||||||
|
clientFwdCWMsg(msg.TGUserID64, m.ID64, m.ChatID64, cfg.Bot.Depositchat)
|
||||||
|
gDepositForwardMsg[i] = gDepositForwardMsg[len(gDepositForwardMsg)-1]
|
||||||
|
gDepositForwardMsg = gDepositForwardMsg[:len(gDepositForwardMsg)-1]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gDepositForwardMux.Unlock()
|
||||||
|
|
||||||
cwm.Msg = m
|
cwm.Msg = m
|
||||||
return &cwm, nil
|
return &cwm, nil
|
||||||
}
|
}
|
||||||
|
@ -531,8 +531,6 @@ func JobWorker(id int, jobs <-chan Job) {
|
|||||||
jobGStock(j)
|
jobGStock(j)
|
||||||
case objSubTypeJobGDeposit:
|
case objSubTypeJobGDeposit:
|
||||||
jobGDeposit(j)
|
jobGDeposit(j)
|
||||||
case objSubTypeJobGDepositForward:
|
|
||||||
jobGDepositForward(j)
|
|
||||||
default:
|
default:
|
||||||
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID)
|
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user