This commit is contained in:
shoopea 2019-05-04 16:57:14 +08:00
parent eaf5c6d4e9
commit c0649a560d
2 changed files with 25 additions and 23 deletions

View File

@ -11,12 +11,11 @@ import (
) )
type ChatWarsMessage struct { type ChatWarsMessage struct {
MsgID64 int64 `json:"msg_id"`
ChatID64 int64 `json:"chat_id"`
SenderUserID64 int64 `json:"sender_user_id"` SenderUserID64 int64 `json:"sender_user_id"`
UserID64 int64 `json:"user_id"` Date int32 `json:"date"`
MsgText string `json:"msg"` ID64 int64 `json:"id"`
MsgDate int32 `json:"date"` ChatID64 int64 `json:"chat_id"`
Text string `json:"text"`
} }
const user_chtwrsbot = 408101137 const user_chtwrsbot = 408101137

39
td.go
View File

@ -13,7 +13,8 @@ func ListenCW(c *tdlib.Client) {
eventFilter := func(msg *tdlib.TdMessage) bool { eventFilter := func(msg *tdlib.TdMessage) bool {
updateMsg := (*msg).(*tdlib.UpdateNewMessage) updateMsg := (*msg).(*tdlib.UpdateNewMessage)
chatID := updateMsg.Message.ChatID chatID := updateMsg.Message.ChatID
if chatID == user_chtwrsbot { forwardInfo := updateMsg.Message.ForwardInfo
if chatID == user_chtwrsbot && forwardInfo == nil {
return true return true
} }
return false return false
@ -34,11 +35,11 @@ func ListenCW(c *tdlib.Client) {
t := time.Now() t := time.Now()
m := ChatWarsMessage{ m := ChatWarsMessage{
UserID64: ownUserID64, SenderUserID64: updateMsg.Message.SenderUserID,
ChatID64: updateMsg.Message.ChatID, Date: updateMsg.Message.Date,
MsgDate: updateMsg.Message.Date, ID64: updateMsg.Message.ID,
MsgText: string(txt), ChatID64: updateMsg.Message.ChatID,
MsgID64: updateMsg.Message.ID, Text: txt,
} }
MQCWMsgQueue <- m MQCWMsgQueue <- m
@ -85,21 +86,23 @@ func getHistory(c *tdlib.Client) {
for _, msg := range msgs.Messages { for _, msg := range msgs.Messages {
switch msg.Content.GetMessageContentEnum() { switch msg.Content.GetMessageContentEnum() {
case tdlib.MessageTextType: case tdlib.MessageTextType:
m := ChatWarsMessage{ if msg.ForwardInfo == nil {
UserID64: int64(msg.SenderUserID), m := ChatWarsMessage{
ChatID64: msg.ChatID, SenderUserID64: int64(msg.SenderUserID),
MsgDate: msg.Date, Date: msg.Date,
MsgText: msg.Content.(*tdlib.MessageText).Text.Text, ID64: msg.ID,
MsgID64: msg.ID, ChatID64: msg.ChatID,
} Text: msg.Content.(*tdlib.MessageText).Text.Text,
}
MQCWMsgQueue <- m MQCWMsgQueue <- m
if msg.ID < lastMsgID64 { if msg.ID < lastMsgID64 {
lastMsgID64 = msg.ID lastMsgID64 = msg.ID
lastMsgTime = time.Unix(int64(msg.Date), 0) lastMsgTime = time.Unix(int64(msg.Date), 0)
}
msgCount = msgCount + 1
} }
msgCount = msgCount + 1
default: default:
log.Printf("getHistory : no handler for %s\n", msg.Content.GetMessageContentEnum()) log.Printf("getHistory : no handler for %s\n", msg.Content.GetMessageContentEnum())
} }