From 70ecefe2c289efe71e66420d1ee749170b3c045e Mon Sep 17 00:00:00 2001 From: shoopea Date: Thu, 16 Jan 2020 22:39:48 +0800 Subject: [PATCH] test --- bot.go | 1 + def.go | 1 + job.go | 14 +++++++++++++- rules.go | 4 ++-- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/bot.go b/bot.go index 9115af4..8e006ce 100644 --- a/bot.go +++ b/bot.go @@ -966,6 +966,7 @@ func botGWithdraw(m *tb.Message) { p := JobPayloadGWithdraw{ MsgID64: int64(m.ID), ChatID64: m.Chat.ID, + UserID64: int64(m.Sender.ID), Status: 0, Validated: false, } diff --git a/def.go b/def.go index 6e7e37d..be3ce72 100644 --- a/def.go +++ b/def.go @@ -408,6 +408,7 @@ type JobPayloadGWithdrawItem struct { type JobPayloadGWithdraw struct { MsgID64 int64 `json:"msg_id"` ChatID64 int64 `json:"chat_id"` + UserID64 int64 `json:"user_id"` Items []JobPayloadGWithdrawItem `json:"items"` Status int64 `json:"status"` CleanupMsg []ChatWarsMessage `json:"cleanup_msg"` diff --git a/job.go b/job.go index 521cca1..74a9518 100644 --- a/job.go +++ b/job.go @@ -1587,9 +1587,21 @@ func jobGWithdraw(j Job) { c.Encrypt(out, in) ref := hex.EncodeToString(out) + user := bot.ChatByID(fmt.Sprintf("%d", p.UserID64)) + stock := make(string, 0) + for _, i := range p.Items { + if i.Available > i.Required { + stock = fmt.Sprintf("\n%d x %s", i.Required, i.Name) + } else { + stock = fmt.Sprintf("\n%d x %s", i.Available, i.Name) + } + } + + msg := fmt.Sprintf("To validate @%s withdrawal of%s\nClick /withdraw_%s", user.Username, stock, string(ref)) + cmd := TGCommand{ Type: commandReplyMsg, - Text: fmt.Sprintf("/withdraw_%s", string(ref)), + Text: msg, FromMsgID64: p.MsgID64, FromChatID64: p.ChatID64, } diff --git a/rules.go b/rules.go index 623182b..3ba639a 100644 --- a/rules.go +++ b/rules.go @@ -22,7 +22,7 @@ func resetMsgParsingRules() error { r := MessageParsingRule{ Priority: 9999, Description: "Withdrawal request", - Rule: "^To validate (@[A-Za-z0-9]*) withdrawal of\n([0-9]+ x .*\n)+(Click /withdraw_[a-zA-Z0-9]{22})$", + Rule: "^To validate (@[A-Za-z0-9]*) withdrawal of\n([0-9]+ x .*\n)+(Click /withdraw_[a-f0-9]{32})$", MsgTypeID64: cacheObjSubType[`msg_guild_gwithdraw_req`], ChatID64: cfg.Bot.Mainchat, SenderUserID64: 0, @@ -32,7 +32,7 @@ func resetMsgParsingRules() error { r = MessageParsingRule{ Priority: 9999, Description: "Withdrawal acknowledgment", - Rule: "^/withdraw_[a-zA-Z0-9]{22}$", + Rule: "^/withdraw_[a-f0-9]{32}$", MsgTypeID64: cacheObjSubType[`msg_guild_gwithdraw_ack`], ChatID64: cfg.Bot.Mainchat, SenderUserID64: 0,