From 05f49beb73727dd69b6b6d6019c8de048f0fd488 Mon Sep 17 00:00:00 2001 From: shoopea Date: Fri, 3 May 2019 18:17:05 +0800 Subject: [PATCH] upd --- main.go | 3 --- td.go | 52 ++++++++++++++++++++++++++++------------------------ 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/main.go b/main.go index d585964..e9bf94b 100644 --- a/main.go +++ b/main.go @@ -113,10 +113,7 @@ func main() { ownUserID32 = OwnUserID(client) ownUserID64 = int64(OwnUserID(client)) - log.Println("Plop ..") - if *history { - log.Println("Getting history ..") getHistory(client) } diff --git a/td.go b/td.go index 4653a55..02997d9 100644 --- a/td.go +++ b/td.go @@ -141,32 +141,36 @@ func getHistory(c *tdlib.Client) { lastMsgID64 = -1 } else { for _, msg := range msgs.Messages { + switch msg.Content { + case tdlib.MessageTextType: + m := ChatWarsMessage{ + UserID64: int64(msg.SenderUserID), + MsgDate: msg.Date, + MsgText: msg.Content.(*tdlib.MessageText).Text.Text, + MsgID64: msg.ID, + } + if msg.SenderUserID == ownUserID32 { + m.Direction = Outgoing + } else { + m.Direction = Incoming + } - m := ChatWarsMessage{ - UserID64: int64(msg.SenderUserID), - MsgDate: msg.Date, - MsgText: msg.Content.(*tdlib.MessageText).Text.Text, - MsgID64: msg.ID, - } - if msg.SenderUserID == ownUserID32 { - m.Direction = Outgoing - } else { - m.Direction = Incoming - } + b, _ := json.Marshal(m) - b, _ := json.Marshal(m) - - _ = ch.Publish( - "", // exchange - q.Name, // routing key - false, // mandatory - false, // immediate - amqp.Publishing{ - ContentType: "application/json", - Body: []byte(b), - }) - if msg.ID < lastMsgID64 { - lastMsgID64 = msg.ID + _ = ch.Publish( + "", // exchange + q.Name, // routing key + false, // mandatory + false, // immediate + amqp.Publishing{ + ContentType: "application/json", + Body: []byte(b), + }) + if msg.ID < lastMsgID64 { + lastMsgID64 = msg.ID + } + default: + log.Printf("getHistory : no handler for %s\n", msg.Content) } } }