diff --git a/main.go b/main.go index b804681..590fca0 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "log" + "time" "gopkg.in/gcfg.v1" @@ -11,12 +12,12 @@ import ( ) type ChatWarsMessage struct { - UserID64 int64 `json:"user_id"` - SenderUserID64 int64 `json:"sender_user_id"` - Date int32 `json:"date"` - ID64 int64 `json:"id"` - ChatID64 int64 `json:"chat_id"` - Text string `json:"text"` + UserID64 int64 `json:"user_id"` + SenderUserID64 int64 `json:"sender_user_id"` + Date time.Time `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 9e16793..a04e19d 100644 --- a/td.go +++ b/td.go @@ -37,12 +37,14 @@ func ListenCW(c *tdlib.Client) { m := ChatWarsMessage{ UserID64: ownUserID64, SenderUserID64: int64(updateMsg.Message.SenderUserID), - Date: updateMsg.Message.Date, ID64: updateMsg.Message.ID, ChatID64: updateMsg.Message.ChatID, Text: txt, } + i, err := strconv.ParseInt(updateMsg.Message.Date, 10, 64) + m.Date = time.Unix(i, 0) + MQCWMsgQueue <- m 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{ UserID64: ownUserID64, SenderUserID64: int64(msg.SenderUserID), - Date: msg.Date, ID64: msg.ID, ChatID64: msg.ChatID, Text: msg.Content.(*tdlib.MessageText).Text.Text, } + i, err := strconv.ParseInt(msg.Date, 10, 64) + m.Date = time.Unix(i, 0) } else { if msg.ForwardInfo.GetMessageForwardInfoEnum() == tdlib.MessageForwardedFromUserType { m = ChatWarsMessage{ UserID64: int64(msg.SenderUserID), SenderUserID64: int64(msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).SenderUserID), - Date: msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).Date, ID64: msg.ID, ChatID64: 0, 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 { m = ChatWarsMessage{ ID64: 0,