From c0649a560ded406fb036ab06f02d8b025ed7d55d Mon Sep 17 00:00:00 2001 From: shoopea Date: Sat, 4 May 2019 16:57:14 +0800 Subject: [PATCH] upd --- main.go | 9 ++++----- td.go | 39 +++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/main.go b/main.go index 1b45e74..0b2b3a1 100644 --- a/main.go +++ b/main.go @@ -11,12 +11,11 @@ import ( ) type ChatWarsMessage struct { - MsgID64 int64 `json:"msg_id"` - ChatID64 int64 `json:"chat_id"` SenderUserID64 int64 `json:"sender_user_id"` - UserID64 int64 `json:"user_id"` - MsgText string `json:"msg"` - MsgDate int32 `json:"date"` + Date int32 `json:"date"` + ID64 int64 `json:"id"` + ChatID64 int64 `json:"chat_id"` + Text string `json:"text"` } const user_chtwrsbot = 408101137 diff --git a/td.go b/td.go index 584bdf1..b41a56d 100644 --- a/td.go +++ b/td.go @@ -13,7 +13,8 @@ func ListenCW(c *tdlib.Client) { eventFilter := func(msg *tdlib.TdMessage) bool { updateMsg := (*msg).(*tdlib.UpdateNewMessage) chatID := updateMsg.Message.ChatID - if chatID == user_chtwrsbot { + forwardInfo := updateMsg.Message.ForwardInfo + if chatID == user_chtwrsbot && forwardInfo == nil { return true } return false @@ -34,11 +35,11 @@ func ListenCW(c *tdlib.Client) { t := time.Now() m := ChatWarsMessage{ - UserID64: ownUserID64, - ChatID64: updateMsg.Message.ChatID, - MsgDate: updateMsg.Message.Date, - MsgText: string(txt), - MsgID64: updateMsg.Message.ID, + SenderUserID64: updateMsg.Message.SenderUserID, + Date: updateMsg.Message.Date, + ID64: updateMsg.Message.ID, + ChatID64: updateMsg.Message.ChatID, + Text: txt, } MQCWMsgQueue <- m @@ -85,21 +86,23 @@ func getHistory(c *tdlib.Client) { for _, msg := range msgs.Messages { switch msg.Content.GetMessageContentEnum() { case tdlib.MessageTextType: - m := ChatWarsMessage{ - UserID64: int64(msg.SenderUserID), - ChatID64: msg.ChatID, - MsgDate: msg.Date, - MsgText: msg.Content.(*tdlib.MessageText).Text.Text, - MsgID64: msg.ID, - } + if msg.ForwardInfo == nil { + m := ChatWarsMessage{ + SenderUserID64: int64(msg.SenderUserID), + Date: msg.Date, + ID64: msg.ID, + ChatID64: msg.ChatID, + Text: msg.Content.(*tdlib.MessageText).Text.Text, + } - MQCWMsgQueue <- m + MQCWMsgQueue <- m - if msg.ID < lastMsgID64 { - lastMsgID64 = msg.ID - lastMsgTime = time.Unix(int64(msg.Date), 0) + if msg.ID < lastMsgID64 { + lastMsgID64 = msg.ID + lastMsgTime = time.Unix(int64(msg.Date), 0) + } + msgCount = msgCount + 1 } - msgCount = msgCount + 1 default: log.Printf("getHistory : no handler for %s\n", msg.Content.GetMessageContentEnum()) }