g_withdraw start

This commit is contained in:
shoopea 2019-10-04 18:38:03 +08:00
parent dbf8d57e31
commit 422fd7ac25
3 changed files with 41 additions and 17 deletions

27
bot.go
View File

@ -111,7 +111,8 @@ func botHelp(m *tb.Message) {
/backup_import <URL> - import message database from URL
/get_item_id <string> - identify item_id from string
/clients - list all connected clients
/g_deposit_all - deposit all res to vault`,
/g_deposit_all - deposit all res to vault
/g_withdraw <item> <qty> .. - withdraw items`,
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
@ -722,27 +723,19 @@ func botGWithdraw(m *tb.Message) {
if !m.Private() {
return
}
/*
r := regexp.MustCompile("^(( )*[a-z0-9]+ [0-9]+( )*)+$")
if r.MatchString(m.Payload) {
p := JobPayloadGWithdraw{
MsgID64: int64(m.ID),
ChatID64: m.Chat.ID,
Items: nil,
Request: m.Payload,
Status: 0,
}
*/
r := regexp.MustCompile("[a-z0-9]+ [0-9]+")
for _, l := range r.FindAllStringSubmatch(m.Payload, -1) {
fmt.Printf("%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(objSubTypeJobGDeposit, objJobPriority, int64(m.Chat.ID), 0, t, b)
*/
b, _ := json.Marshal(p)
t := time.Now().UTC()
_, err := createJob(objSubTypeJobGWithdraw, objJobPriority, int64(m.Chat.ID), 0, t, b)
}
if false {
c := TGCommand{

29
job.go
View File

@ -890,3 +890,32 @@ func jobGDeposit(j Job) {
logOnError(err, "jobGDeposit : setJobDone")
return
}
func jobGWithdraw(j Job) {
var p JobPayloadGWithdraw
err := setJobStart(j.ID64)
logOnError(err, "jobGWithdraw : setJobStart")
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(objSubTypeJobGDeposit, objJobPriority, int64(m.Chat.ID), 0, t, b)
*/
}
err = setJobDone(j.ID64)
logOnError(err, "jobGWithdraw : setJobDone")
return
}

View File

@ -548,6 +548,8 @@ func JobWorker(id int, jobs <-chan Job) {
jobGDeposit(j)
case objSubTypeJobGDepositForward:
jobGDepositForward(j)
case objSubTypeJobGWithdraw:
jobGWithdraw(j)
default:
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID)
}