parent
05cc83d5f7
commit
8300d53ae2
40
td.go
40
td.go
@ -35,13 +35,15 @@ func ListenCW(c *tdlib.Client) {
|
|||||||
t := time.Now()
|
t := time.Now()
|
||||||
|
|
||||||
m := ChatWarsMessage{
|
m := ChatWarsMessage{
|
||||||
|
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,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.Date = time.Unix(int64(updateMsg.Message.Date), 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())
|
||||||
@ -71,6 +73,7 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) {
|
|||||||
var msgCount int32 = 0
|
var msgCount int32 = 0
|
||||||
var msgParsed int32 = 0
|
var msgParsed int32 = 0
|
||||||
var lastParsedID64 int64 = int64(math.MaxInt64)
|
var lastParsedID64 int64 = int64(math.MaxInt64)
|
||||||
|
var loopCount int32 = 1
|
||||||
var lastParsedTime time.Time = time.Now()
|
var lastParsedTime time.Time = time.Now()
|
||||||
var chat int64
|
var chat int64
|
||||||
var m ChatWarsMessage
|
var m ChatWarsMessage
|
||||||
@ -81,14 +84,27 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) {
|
|||||||
chat = *chatID64
|
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 {
|
for lastParsedID64 >= 0 && loopCount > 0 {
|
||||||
msgs, err := c.GetChatHistory(chat, lastParsedID64, 0, 50, false)
|
msgs, err := c.GetChatHistory(chat, lastParsedID64, 0, 33, false)
|
||||||
|
loopCount = 0
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "timeout" {
|
if err.Error() == "timeout" {
|
||||||
logOnError(err, "Waiting...")
|
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 {
|
} else {
|
||||||
logOnError(err, "Cannot get history")
|
logOnError(err, "Cannot get history")
|
||||||
lastParsedID64 = -1
|
lastParsedID64 = -1
|
||||||
@ -101,21 +117,24 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) {
|
|||||||
case tdlib.MessageTextType:
|
case tdlib.MessageTextType:
|
||||||
if msg.ForwardInfo == nil {
|
if msg.ForwardInfo == nil {
|
||||||
m = ChatWarsMessage{
|
m = ChatWarsMessage{
|
||||||
|
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,
|
||||||
}
|
}
|
||||||
|
m.Date = time.Unix(int64(msg.Date), 0)
|
||||||
} else {
|
} else {
|
||||||
if msg.ForwardInfo.GetMessageForwardInfoEnum() == tdlib.MessageForwardedFromUserType {
|
if msg.ForwardInfo.GetMessageForwardInfoEnum() == tdlib.MessageForwardedFromUserType {
|
||||||
m = ChatWarsMessage{
|
m = ChatWarsMessage{
|
||||||
|
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,
|
||||||
}
|
}
|
||||||
|
m.Date = time.Unix(int64(msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).Date), 0)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
m = ChatWarsMessage{
|
m = ChatWarsMessage{
|
||||||
ID64: 0,
|
ID64: 0,
|
||||||
@ -128,14 +147,15 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) {
|
|||||||
msgCount = msgCount + 1
|
msgCount = msgCount + 1
|
||||||
}
|
}
|
||||||
default:
|
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 {
|
if m.ID64 < lastParsedID64 {
|
||||||
lastParsedID64 = msg.ID
|
lastParsedID64 = msg.ID
|
||||||
lastParsedTime = time.Unix(int64(m.Date), 0)
|
lastParsedTime = m.Date
|
||||||
|
loopCount = loopCount + 1
|
||||||
}
|
}
|
||||||
if msgParsed%1000 == 0 {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user