From 109f38e470136649e33a2801d2797984679b33fe Mon Sep 17 00:00:00 2001 From: shoopea Date: Thu, 16 Jan 2020 23:34:21 +0800 Subject: [PATCH] test --- job.go | 73 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/job.go b/job.go index 5a02514..9c5f14b 100644 --- a/job.go +++ b/job.go @@ -1568,47 +1568,58 @@ func jobGWithdraw(j Job) { } */ - b, _ := json.Marshal(p) - id, err := createJob(cacheObjSubType[`job_gwithdraw`], objJobPriority, j.UserID64, 0, time.Unix(maxUnixTimestamp, 0).UTC(), b) - logOnError(err, "jobGWithdraw : createJob") - - sha256 := sha256.Sum256([]byte(cfg.Telegram.Token)) - sha128 := sha256[:aes.BlockSize] - c, err := aes.NewCipher(sha128) - - in := make([]byte, 0) - buf := make([]byte, 8) - binary.LittleEndian.PutUint64(buf, uint64(id)) - in = append(in, buf...) - binary.LittleEndian.PutUint64(buf, uint64(j.UserID64)) - in = append(in, buf...) - out := make([]byte, len(in)) - - c.Encrypt(out, in) - ref := hex.EncodeToString(out) - - b, err = json.Marshal(p) - fmt.Printf("jobGWithdraw : %s\n", string(b)) - var stock string for _, i := range p.Items { if i.Available > i.Required { stock = fmt.Sprintf("%s\n%d x %s", stock, i.Required, i.Name) - } else { + } else if i.Available > 0 { stock = fmt.Sprintf("%s\n%d x %s", stock, i.Available, i.Name) } } - msg := fmt.Sprintf("To validate @%s withdrawal of%s\nClick /withdraw_%s", p.User, stock, string(ref)) + if len(stock) > 0 { + b, _ := json.Marshal(p) + id, err := createJob(cacheObjSubType[`job_gwithdraw`], objJobPriority, j.UserID64, 0, time.Unix(maxUnixTimestamp, 0).UTC(), b) + logOnError(err, "jobGWithdraw : createJob") - cmd := TGCommand{ - Type: commandReplyMsg, - Text: msg, - FromMsgID64: p.MsgID64, - FromChatID64: p.ChatID64, - ParseMode: cmdParseModeHTML, + sha256 := sha256.Sum256([]byte(cfg.Telegram.Token)) + sha128 := sha256[:aes.BlockSize] + c, err := aes.NewCipher(sha128) + + in := make([]byte, 0) + buf := make([]byte, 8) + binary.LittleEndian.PutUint64(buf, uint64(id)) + in = append(in, buf...) + binary.LittleEndian.PutUint64(buf, uint64(j.UserID64)) + in = append(in, buf...) + out := make([]byte, len(in)) + + c.Encrypt(out, in) + ref := hex.EncodeToString(out) + + b, err = json.Marshal(p) + fmt.Printf("jobGWithdraw : %s\n", string(b)) + + msg := fmt.Sprintf("Click to validate @%s's withdrawal of%s\n/withdraw_%s", p.User, stock, string(ref)) + + cmd := TGCommand{ + Type: commandReplyMsg, + Text: msg, + FromMsgID64: p.MsgID64, + FromChatID64: p.ChatID64, + ParseMode: cmdParseModeHTML, + } + TGCmdQueue <- cmd + } else { + cmd := TGCommand{ + Type: commandReplyMsg, + Text: "No stock available whatsoever", + FromMsgID64: p.MsgID64, + FromChatID64: p.ChatID64, + ParseMode: cmdParseModeHTML, + } + TGCmdQueue <- cmd } - TGCmdQueue <- cmd } err = setJobDone(j.ID64)