Revert "test"

This reverts commit 05cc83d5f7.
This commit is contained in:
shoopea 2019-05-11 16:50:56 +08:00
parent 05cc83d5f7
commit 8300d53ae2

40
td.go
View File

@ -35,13 +35,15 @@ func ListenCW(c *tdlib.Client) {
t := time.Now()
m := ChatWarsMessage{
UserID64: ownUserID64,
SenderUserID64: int64(updateMsg.Message.SenderUserID),
Date: updateMsg.Message.Date,
ID64: updateMsg.Message.ID,
ChatID64: updateMsg.Message.ChatID,
Text: txt,
}
m.Date = time.Unix(int64(updateMsg.Message.Date), 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())
@ -71,6 +73,7 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) {
var msgCount int32 = 0
var msgParsed int32 = 0
var lastParsedID64 int64 = int64(math.MaxInt64)
var loopCount int32 = 1
var lastParsedTime time.Time = time.Now()
var chat int64
var m ChatWarsMessage
@ -81,14 +84,27 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) {
chat = *chatID64
}
fmt.Printf("Exporting historic messages for chat %d from user %d ...\n", chat, *senderUserID64)
if *senderUserID64 != 0 {
userDetails, err := c.GetUser(int32(*senderUserID64))
failOnError(err, "getHistory : GetUser")
chatDetails, err := c.GetChat(chat)
failOnError(err, "getHistory : GetChat")
fmt.Printf("Exporting historic messages for chat %d (%s) from user %d (%s)...\n", chat, chatDetails.Title, *senderUserID64, userDetails.Username)
} else {
chatDetails, err := c.GetChat(chat)
failOnError(err, "getHistory : GetChat")
fmt.Printf("Exporting historic messages for chat %d (%s) ...\n", chat, chatDetails.Title)
}
for lastParsedID64 >= 0 {
msgs, err := c.GetChatHistory(chat, lastParsedID64, 0, 50, false)
for lastParsedID64 >= 0 && loopCount > 0 {
msgs, err := c.GetChatHistory(chat, lastParsedID64, 0, 33, false)
loopCount = 0
if err != nil {
if err.Error() == "timeout" {
logOnError(err, "Waiting...")
fmt.Printf("Waiting : %d messages retrieved out of %d dating back %s ...\n", msgCount, msgParsed, lastParsedTime.Format(time.RFC3339))
fmt.Printf("Timeout : %d messages retrieved out of %d dating back %s (%d) ...\n", msgCount, msgParsed, lastParsedTime.Format(time.RFC3339), lastParsedID64)
time.Sleep(5 * time.Second)
loopCount = 1
} else {
logOnError(err, "Cannot get history")
lastParsedID64 = -1
@ -101,21 +117,24 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) {
case tdlib.MessageTextType:
if msg.ForwardInfo == nil {
m = ChatWarsMessage{
UserID64: ownUserID64,
SenderUserID64: int64(msg.SenderUserID),
Date: msg.Date,
ID64: msg.ID,
ChatID64: msg.ChatID,
Text: msg.Content.(*tdlib.MessageText).Text.Text,
}
m.Date = time.Unix(int64(msg.Date), 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,
}
m.Date = time.Unix(int64(msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).Date), 0)
} else {
m = ChatWarsMessage{
ID64: 0,
@ -128,14 +147,15 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) {
msgCount = msgCount + 1
}
default:
log.Printf("getHistory : no handler for %s\n", msg.Content.GetMessageContentEnum())
log.Printf("getHistory(%d) : no handler for %s\n", msg.ID, msg.Content.GetMessageContentEnum())
}
if m.ID64 < lastParsedID64 {
lastParsedID64 = msg.ID
lastParsedTime = time.Unix(int64(m.Date), 0)
lastParsedTime = m.Date
loopCount = loopCount + 1
}
if msgParsed%1000 == 0 {
fmt.Printf("Waiting : %d messages retrieved out of %d dating back %s ...\n", msgCount, msgParsed, lastParsedTime.Format(time.RFC3339))
fmt.Printf("Waiting : %d messages retrieved out of %d dating back %s (%d) ...\n", msgCount, msgParsed, lastParsedTime.Format(time.RFC3339), lastParsedID64)
}
}