This commit is contained in:
shoopea 2019-05-09 18:31:35 +08:00
parent ed938b2f4b
commit a7281f189b
2 changed files with 15 additions and 9 deletions

13
main.go
View File

@ -4,6 +4,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"log" "log"
"time"
"gopkg.in/gcfg.v1" "gopkg.in/gcfg.v1"
@ -11,12 +12,12 @@ import (
) )
type ChatWarsMessage struct { type ChatWarsMessage struct {
UserID64 int64 `json:"user_id"` UserID64 int64 `json:"user_id"`
SenderUserID64 int64 `json:"sender_user_id"` SenderUserID64 int64 `json:"sender_user_id"`
Date int32 `json:"date"` Date time.Time `json:"date"`
ID64 int64 `json:"id"` ID64 int64 `json:"id"`
ChatID64 int64 `json:"chat_id"` ChatID64 int64 `json:"chat_id"`
Text string `json:"text"` Text string `json:"text"`
} }
const user_chtwrsbot = 408101137 const user_chtwrsbot = 408101137

11
td.go
View File

@ -37,12 +37,14 @@ func ListenCW(c *tdlib.Client) {
m := ChatWarsMessage{ m := ChatWarsMessage{
UserID64: ownUserID64, UserID64: ownUserID64,
SenderUserID64: int64(updateMsg.Message.SenderUserID), SenderUserID64: int64(updateMsg.Message.SenderUserID),
Date: updateMsg.Message.Date,
ID64: updateMsg.Message.ID, ID64: updateMsg.Message.ID,
ChatID64: updateMsg.Message.ChatID, ChatID64: updateMsg.Message.ChatID,
Text: txt, Text: txt,
} }
i, err := strconv.ParseInt(updateMsg.Message.Date, 10, 64)
m.Date = time.Unix(i, 0)
MQCWMsgQueue <- m MQCWMsgQueue <- m
fmt.Printf("[%d-%02d-%02d %02d:%02d:%02d-00:00]", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second()) fmt.Printf("[%d-%02d-%02d %02d:%02d:%02d-00:00]", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
@ -115,21 +117,24 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) {
m = ChatWarsMessage{ m = ChatWarsMessage{
UserID64: ownUserID64, UserID64: ownUserID64,
SenderUserID64: int64(msg.SenderUserID), SenderUserID64: int64(msg.SenderUserID),
Date: msg.Date,
ID64: msg.ID, ID64: msg.ID,
ChatID64: msg.ChatID, ChatID64: msg.ChatID,
Text: msg.Content.(*tdlib.MessageText).Text.Text, Text: msg.Content.(*tdlib.MessageText).Text.Text,
} }
i, err := strconv.ParseInt(msg.Date, 10, 64)
m.Date = time.Unix(i, 0)
} else { } else {
if msg.ForwardInfo.GetMessageForwardInfoEnum() == tdlib.MessageForwardedFromUserType { if msg.ForwardInfo.GetMessageForwardInfoEnum() == tdlib.MessageForwardedFromUserType {
m = ChatWarsMessage{ m = ChatWarsMessage{
UserID64: int64(msg.SenderUserID), UserID64: int64(msg.SenderUserID),
SenderUserID64: int64(msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).SenderUserID), SenderUserID64: int64(msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).SenderUserID),
Date: msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).Date,
ID64: msg.ID, ID64: msg.ID,
ChatID64: 0, ChatID64: 0,
Text: msg.Content.(*tdlib.MessageText).Text.Text, Text: msg.Content.(*tdlib.MessageText).Text.Text,
} }
i, err := strconv.ParseInt(msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).Date, 10, 64)
m.Date = time.Unix(i, 0)
} else { } else {
m = ChatWarsMessage{ m = ChatWarsMessage{
ID64: 0, ID64: 0,