This commit is contained in:
shoopea 2019-05-03 18:17:05 +08:00
parent da51179222
commit 05f49beb73
2 changed files with 28 additions and 27 deletions

View File

@ -113,10 +113,7 @@ func main() {
ownUserID32 = OwnUserID(client) ownUserID32 = OwnUserID(client)
ownUserID64 = int64(OwnUserID(client)) ownUserID64 = int64(OwnUserID(client))
log.Println("Plop ..")
if *history { if *history {
log.Println("Getting history ..")
getHistory(client) getHistory(client)
} }

52
td.go
View File

@ -141,32 +141,36 @@ func getHistory(c *tdlib.Client) {
lastMsgID64 = -1 lastMsgID64 = -1
} else { } else {
for _, msg := range msgs.Messages { 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{ b, _ := json.Marshal(m)
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) _ = ch.Publish(
"", // exchange
_ = ch.Publish( q.Name, // routing key
"", // exchange false, // mandatory
q.Name, // routing key false, // immediate
false, // mandatory amqp.Publishing{
false, // immediate ContentType: "application/json",
amqp.Publishing{ Body: []byte(b),
ContentType: "application/json", })
Body: []byte(b), if msg.ID < lastMsgID64 {
}) lastMsgID64 = msg.ID
if msg.ID < lastMsgID64 { }
lastMsgID64 = msg.ID default:
log.Printf("getHistory : no handler for %s\n", msg.Content)
} }
} }
} }