revamp g withdraw
This commit is contained in:
parent
eb788b29f7
commit
8c3cae85f6
14
bot.go
14
bot.go
@ -931,12 +931,24 @@ func botGWithdraw(m *tb.Message) {
|
||||
|
||||
r := regexp.MustCompile("^(( )*[a-z0-9]+ [0-9]+( )*)+$")
|
||||
if r.MatchString(m.Payload) {
|
||||
rx := regexp.MustCompile("[a-z0-9]+ [0-9]+")
|
||||
p := JobPayloadGWithdraw{
|
||||
MsgID64: int64(m.ID),
|
||||
ChatID64: m.Chat.ID,
|
||||
Request: m.Payload,
|
||||
Status: 0,
|
||||
}
|
||||
items := []ChatWarsItems{}
|
||||
for _, l := range rx.FindAllStringSubmatch(m.Payload, -1) {
|
||||
i := l[1]
|
||||
q, _ := strconv.ParseInt(l[2], 10, 64)
|
||||
item := ChatWarsItems{
|
||||
Item: i,
|
||||
Quantity: q,
|
||||
}
|
||||
items = append(items, item)
|
||||
}
|
||||
p.Request = items
|
||||
|
||||
b, _ := json.Marshal(p)
|
||||
t := time.Now().UTC()
|
||||
_, err := createJob(cacheObjSubType[`job_gwithdraw`], objJobPriority, int64(m.Chat.ID), 0, t, b)
|
||||
|
3
def.go
3
def.go
@ -361,7 +361,8 @@ type JobPayloadGStock struct {
|
||||
type JobPayloadGWithdraw struct {
|
||||
MsgID64 int64 `json:"msg_id"`
|
||||
ChatID64 int64 `json:"chat_id"`
|
||||
Request string `json:"request"`
|
||||
Request []ChatWarsItems `json:"request"`
|
||||
Available []ChatWarsItems `json:"available"`
|
||||
Status int64 `json:"status"`
|
||||
}
|
||||
|
||||
|
53
job.go
53
job.go
@ -1272,19 +1272,46 @@ func jobGWithdraw(j Job) {
|
||||
err = json.Unmarshal(j.Payload, &p)
|
||||
logOnError(err, "jobGWithdraw : Unmarshal payload")
|
||||
|
||||
r := regexp.MustCompile("[a-z0-9]+ [0-9]+")
|
||||
for _, l := range r.FindAllStringSubmatch(p.Request, -1) {
|
||||
fmt.Printf("jobGWithdraw : %v\n", l)
|
||||
/*
|
||||
i := getObjItemID(``, l[1])
|
||||
q, _ := strconv.ParseInt(l[2], 10, 64)
|
||||
*/
|
||||
/*
|
||||
ChatWarsItems
|
||||
b, _ := json.Marshal(p)
|
||||
t := time.Now().UTC()
|
||||
_, err := createJob(cacheObjSubType[`job_gdeposit`], objJobPriority, int64(m.Chat.ID), 0, t, b)
|
||||
*/
|
||||
if p.Status == 0 {
|
||||
for i, item := range p.Request {
|
||||
id := getSilentObjItemID(item.Item, ``)
|
||||
if id != 0 {
|
||||
obj, _ := getObjItem(id)
|
||||
switch obj.ItemTypeID {
|
||||
case codeObjSubType[`item_res`]:
|
||||
p.Status = p.Status | 1
|
||||
case codeObjSubType[`item_alch`]:
|
||||
p.Status = p.Status | 2
|
||||
case codeObjSubType[`item_misc`]:
|
||||
p.Status = p.Status | 4
|
||||
case codeObjSubType[`item_recipe`]:
|
||||
p.Status = p.Status | 8
|
||||
case codeObjSubType[`item_part`]:
|
||||
p.Status = p.Status | 16
|
||||
case codeObjSubType[`item_other`]:
|
||||
p.Status = p.Status | 32
|
||||
default:
|
||||
log.Printf("jobGWithdraw : No handler for item type #%d.\n", obj.ItemTypeID)
|
||||
}
|
||||
} else if ok, _ := regexp.MatchString(`^u[0-9]+`, code); ok {
|
||||
p.Status = p.Status | 32
|
||||
}
|
||||
}
|
||||
}
|
||||
if p.Status < 64 {
|
||||
if (p.Status & 1) == 1 {
|
||||
log.Printf("jobGWithdraw : Requesting res.\n")
|
||||
} else if (p.Status & 2) == 2 {
|
||||
log.Printf("jobGWithdraw : Requesting alch.\n")
|
||||
} else if (p.Status & 4) == 4 {
|
||||
log.Printf("jobGWithdraw : Requesting misc.\n")
|
||||
} else if (p.Status & 8) == 8 {
|
||||
log.Printf("jobGWithdraw : Requesting recipe.\n")
|
||||
} else if (p.Status & 16) == 16 {
|
||||
log.Printf("jobGWithdraw : Requesting part.\n")
|
||||
} else if (p.Status & 32) == 32 {
|
||||
log.Printf("jobGWithdraw : Requesting other.\n")
|
||||
}
|
||||
}
|
||||
|
||||
err = setJobDone(j.ID64)
|
||||
|
Loading…
Reference in New Issue
Block a user