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 {
MsgID64 int64 `json:"msg_id"`
ChatID64 int64 `json:"chat_id"`
SenderUserID64 int64 `json:"sender_user_id"`
UserID64 int64 `json:"user_id"`
MsgText string `json:"msg"`
MsgDate int32 `json:"date"`
Date int32 `json:"date"`
ID64 int64 `json:"id"`
ChatID64 int64 `json:"chat_id"`
Text string `json:"text"`
}
const user_chtwrsbot = 408101137

39
td.go
View File

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