From 02ad65b1f2c93248b39d38a6d91eb19e17f2d4ad Mon Sep 17 00:00:00 2001 From: shoopea Date: Wed, 15 May 2019 10:28:06 +0800 Subject: [PATCH] test --- td.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/td.go b/td.go index 05de93e..0e3fcf9 100644 --- a/td.go +++ b/td.go @@ -9,20 +9,15 @@ import ( "github.com/Arman92/go-tdlib" ) -func ListenCW(c *tdlib.Client) { +func ListenMe(c *tdlib.Client) { eventFilter := func(msg *tdlib.TdMessage) bool { updateMsg := (*msg).(*tdlib.UpdateNewMessage) - chatID := updateMsg.Message.ChatID - 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 { + senderUserID := updateMsg.Message.SenderUserID + if senderUserID == ownUserID32 { return true + } else { + return false } - - return false } receiver := c.AddEventReceiver(&tdlib.UpdateNewMessage{}, eventFilter, 100) @@ -33,7 +28,7 @@ func ListenCW(c *tdlib.Client) { func ListenMQ(c *tdlib.Client, msgs <-chan ChatWarsCommand) { for m := range msgs { - for now := time.Now(); lastOwnTDMsg.Add(time.Second) > now; { + for now := time.Now(); lastOwnTDMsg.Add(time.Second).After(now); { log.Printf("ListenMQ : channel busy, waiting before acting...\n") time.Sleep(time.Until(lastOwnTDMsg.Add(time.Second))) now = time.Now() @@ -43,11 +38,16 @@ func ListenMQ(c *tdlib.Client, msgs <-chan ChatWarsCommand) { } } -func ListenMe(c *tdlib.Client) { +func ListenCW(c *tdlib.Client) { eventFilter := func(msg *tdlib.TdMessage) bool { updateMsg := (*msg).(*tdlib.UpdateNewMessage) - senderUserID := updateMsg.Message.SenderUserID - if senderUserID == ownUserID32 { + chatID := updateMsg.Message.ChatID + 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