This commit is contained in:
shoopea 2019-05-15 10:28:06 +08:00
parent 72cf245064
commit 02ad65b1f2

28
td.go
View File

@ -9,21 +9,16 @@ 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
}
}
receiver := c.AddEventReceiver(&tdlib.UpdateNewMessage{}, eventFilter, 100)
for newMsg := range receiver.Chan {
@ -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