test item vault

This commit is contained in:
shoopea 2019-10-13 15:20:23 +08:00
parent b81547876a
commit 3353f99731

48
bot.go
View File

@ -86,8 +86,10 @@ func botHello(m *tb.Message) (string, error) {
} }
func botChannelPost(m *tb.Message) { func botChannelPost(m *tb.Message) {
fmt.Println("botChannelPost :", m.Text)
PrintText(m) PrintText(m)
b, _ := json.Marshal(m)
log.Printf("botChannelPost : %s\n", string(b))
// channel posts only // channel posts only
} }
@ -97,7 +99,6 @@ func botQuery(q *tb.Query) {
} }
func botText(m *tb.Message) { func botText(m *tb.Message) {
fmt.Println("botText :", m.Text)
PrintText(m) PrintText(m)
b, _ := json.Marshal(m) b, _ := json.Marshal(m)
log.Printf("botText : %s\n", string(b)) log.Printf("botText : %s\n", string(b))
@ -727,6 +728,49 @@ func botVaultOther(m *tb.Message) {
} }
func botVaultItem(m *tb.Message) { func botVaultItem(m *tb.Message) {
if !(m.Private() || m.Chat.ID == cfg.Bot.Mainchat) {
return
}
p := JobPayloadVaultItemStatus{
ItemListID64: nil,
DepositChatID64: cfg.Bot.Depositchat,
UserID64: int64(m.Sender.ID),
}
r := regexp.MustCompile("([a-z][0-9]{2}[a-e]{0,1})")
for _, l := range re.FindAllStringSubmatch(m.Payload, -1) {
item := getObjItemID(l[1], ``)
if item != 0 {
p.ItemListID64 = append(p.ItemListID64, item)
}
}
if len(p.ItemListID64) > 0 {
b, _ := json.Marshal(p)
t := time.Now().UTC()
_, err := createJob(objSubTypeJobVaultItemStatus, objJobPriority, int64(m.Sender.ID), 0, t, b)
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s", err),
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: `/vault_item <code> ...`,
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
return
} }