From 3353f9973128a2199ea01807c8328c4f9a95e2e1 Mon Sep 17 00:00:00 2001 From: shoopea Date: Sun, 13 Oct 2019 15:20:23 +0800 Subject: [PATCH] test item vault --- bot.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/bot.go b/bot.go index 5f27def..46fd9ae 100644 --- a/bot.go +++ b/bot.go @@ -86,8 +86,10 @@ func botHello(m *tb.Message) (string, error) { } func botChannelPost(m *tb.Message) { - fmt.Println("botChannelPost :", m.Text) PrintText(m) + b, _ := json.Marshal(m) + log.Printf("botChannelPost : %s\n", string(b)) + // channel posts only } @@ -97,7 +99,6 @@ func botQuery(q *tb.Query) { } func botText(m *tb.Message) { - fmt.Println("botText :", m.Text) PrintText(m) b, _ := json.Marshal(m) log.Printf("botText : %s\n", string(b)) @@ -727,6 +728,49 @@ func botVaultOther(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 ...`, + FromMsgID64: int64(m.ID), + FromChatID64: m.Chat.ID, + } + TGCmdQueue <- c + } + + return }