From 444d9116918666da4a7b83e69003af5d992c4779 Mon Sep 17 00:00:00 2001 From: shoopea Date: Sat, 12 Oct 2019 13:26:11 +0800 Subject: [PATCH] update config struct for listen --- gocw2.sample.cfg | 15 +++++++++++---- main.go | 17 ++++------------- td.go | 18 +++++++++--------- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/gocw2.sample.cfg b/gocw2.sample.cfg index ce48586..90fe216 100644 --- a/gocw2.sample.cfg +++ b/gocw2.sample.cfg @@ -5,8 +5,15 @@ host = localhost:5672 sendqueue = chatwars receivequeue = guest -[listen] -war = false -warmini = false -auctions = false +[listen "chatwars"] +chat = 408101137 +user = 0 + +[listen "war"] +chat = -1001108112459 +user = 0 + +[listen "auctions"] +chat = -1001209424945 +user = 0 \ No newline at end of file diff --git a/main.go b/main.go index 40eb55b..7419b7f 100644 --- a/main.go +++ b/main.go @@ -12,14 +12,6 @@ import ( "github.com/Arman92/go-tdlib" ) -const ( - user_chtwrsbot = 408101137 - chat_darkwing = -1001080526540 - chat_war = -1001108112459 - chat_war_mini = -1001277259728 - chat_auction = -1001209424945 -) - type Config struct { Rabbit struct { User string @@ -28,10 +20,9 @@ type Config struct { SendQueue string ReceiveQueue string } - Listen struct { - War bool - WarMini bool - Auctions bool + Listen map[string]*struct { + User int64 + Chat int64 } } @@ -134,7 +125,7 @@ func main() { lastOwnTDMsg = time.Now() lastOwnTDMsgMux.Unlock() - go ListenCW(client) + go ListenTG(client) go ListenMQ(client, MQTGCmdQueue) go ListenMe(client) diff --git a/td.go b/td.go index e57aac7..7f4c482 100644 --- a/td.go +++ b/td.go @@ -36,20 +36,20 @@ func ListenMQ(c *tdlib.Client, msgs <-chan TGCommand) { } } -func ListenCW(c *tdlib.Client) { +func ListenTG(c *tdlib.Client) { eventFilter := func(msg *tdlib.TdMessage) bool { updateMsg := (*msg).(*tdlib.UpdateNewMessage) chatID := updateMsg.Message.ChatID + userID := updateMsg.Message.SenderUserID forwardInfo := updateMsg.Message.ForwardInfo - if (chatID == user_chtwrsbot || - (chatID == chat_war && cfg.Listen.War) || - (chatID == chat_war_mini && cfg.Listen.WarMini) || - (chatID == chat_auction && cfg.Listen.Auctions)) && - forwardInfo == nil { - return true - } else { - return false + for k, v := range cfg.Listen { + if (v.Chat == chatID || v.Chat == 0) && + (v.User == userID || v.User == 0) && + forwardInfo == nil { + return true + } } + return false } receiver := c.AddEventReceiver(&tdlib.UpdateNewMessage{}, eventFilter, 100)