This commit is contained in:
shoopea 2020-01-16 22:39:48 +08:00
parent 4dc6c88b57
commit 70ecefe2c2
4 changed files with 17 additions and 3 deletions

1
bot.go
View File

@ -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,
}

1
def.go
View File

@ -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"`

14
job.go
View File

@ -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,
}

View File

@ -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,