From 9e157a1945bd86a20b3cd3ed00c0652e2db8a98d Mon Sep 17 00:00:00 2001 From: shoopea Date: Sat, 4 May 2019 17:55:28 +0800 Subject: [PATCH] test --- main.go | 8 +++++--- td.go | 28 +++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 0b2b3a1..da40b56 100644 --- a/main.go +++ b/main.go @@ -30,8 +30,10 @@ type Config struct { } var ( - config = flag.String("config", "gocw2.cfg", "config file path") - history = flag.Bool("history", false, "initialize chat history") + config = flag.String("config", "gocw2.cfg", "config file path") + history = flag.Bool("history", false, "initialize chat history") + historyChatID64 = flag.int64("chat_id", nil, "chat to historize") + historySenderUserID64 = flag.int64("sender_user_id", nil, "sender_user_id to historize") cfg Config @@ -111,7 +113,7 @@ func main() { if *history { fmt.Printf("Retrieving chat.\n") - getHistory(client) + getHistory(client, historyChatID64, historySenderUserID64) return } diff --git a/td.go b/td.go index d8793cf..999c91e 100644 --- a/td.go +++ b/td.go @@ -67,13 +67,19 @@ func ListenCW(c *tdlib.Client) { } } -func getHistory(c *tdlib.Client) { +func getHistory(c *tdlib.Client, chatID64 int64, senderUserID64 int64) { var lastMsgID64 int64 = int64(math.MaxInt64) var msgCount int32 = 0 var lastMsgTime time.Time = time.Now() + if chatID64 == nil { + c := user_chtwrsbot + } else { + c = chatID64 + } + for lastMsgID64 >= 0 { - msgs, err := c.GetChatHistory(user_chtwrsbot, lastMsgID64, 0, 10, false) + msgs, err := c.GetChatHistory(c, lastMsgID64, 0, 10, false) if err != nil { if err.Error() == "timeout" { logOnError(err, "Waiting...") @@ -94,12 +100,24 @@ func getHistory(c *tdlib.Client) { ChatID64: msg.ChatID, Text: msg.Content.(*tdlib.MessageText).Text.Text, } + } else if msg.ForwardInfo.GetMessageForwardInfoEnum() == tdlib.MessageForwardedFromUserType { + m = ChatWarsMessage{ + SenderUserID64: int64(msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).SenderUserID), + Date: msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).Date, + ID64: msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).ForwardedFromMessageID, + ChatID64: msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).ForwardedFromChatID, + Text: msg.Content.(*tdlib.MessageText).Text.Text, + } + } else { + m = nil + } + if m != nil { MQCWMsgQueue <- m - if msg.ID < lastMsgID64 { - lastMsgID64 = msg.ID - lastMsgTime = time.Unix(int64(msg.Date), 0) + if m.ID64 < lastMsgID64 { + lastMsgID64 = m.ID64 + lastMsgTime = time.Unix(int64(m.Date), 0) } msgCount = msgCount + 1 }