test
This commit is contained in:
parent
f66a73f5f7
commit
05cc83d5f7
40
td.go
40
td.go
@ -35,15 +35,13 @@ 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())
|
||||||
@ -73,7 +71,6 @@ 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
|
||||||
@ -84,27 +81,14 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) {
|
|||||||
chat = *chatID64
|
chat = *chatID64
|
||||||
}
|
}
|
||||||
|
|
||||||
if *senderUserID64 != 0 {
|
fmt.Printf("Exporting historic messages for chat %d from user %d ...\n", chat, *senderUserID64)
|
||||||
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 && loopCount > 0 {
|
for lastParsedID64 >= 0 {
|
||||||
msgs, err := c.GetChatHistory(chat, lastParsedID64, 0, 33, false)
|
msgs, err := c.GetChatHistory(chat, lastParsedID64, 0, 50, 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("Timeout : %d messages retrieved out of %d dating back %s (%d) ...\n", msgCount, msgParsed, lastParsedTime.Format(time.RFC3339), lastParsedID64)
|
fmt.Printf("Waiting : %d messages retrieved out of %d dating back %s ...\n", msgCount, msgParsed, lastParsedTime.Format(time.RFC3339))
|
||||||
time.Sleep(5 * time.Second)
|
|
||||||
loopCount = 1
|
|
||||||
} else {
|
} else {
|
||||||
logOnError(err, "Cannot get history")
|
logOnError(err, "Cannot get history")
|
||||||
lastParsedID64 = -1
|
lastParsedID64 = -1
|
||||||
@ -117,24 +101,21 @@ 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,
|
||||||
@ -147,15 +128,14 @@ func getHistory(c *tdlib.Client, chatID64 *int64, senderUserID64 *int64) {
|
|||||||
msgCount = msgCount + 1
|
msgCount = msgCount + 1
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log.Printf("getHistory(%d) : no handler for %s\n", msg.ID, msg.Content.GetMessageContentEnum())
|
log.Printf("getHistory : no handler for %s\n", msg.Content.GetMessageContentEnum())
|
||||||
}
|
}
|
||||||
if m.ID64 < lastParsedID64 {
|
if m.ID64 < lastParsedID64 {
|
||||||
lastParsedID64 = msg.ID
|
lastParsedID64 = msg.ID
|
||||||
lastParsedTime = m.Date
|
lastParsedTime = time.Unix(int64(m.Date), 0)
|
||||||
loopCount = loopCount + 1
|
|
||||||
}
|
}
|
||||||
if msgParsed%1000 == 0 {
|
if msgParsed%1000 == 0 {
|
||||||
fmt.Printf("Waiting : %d messages retrieved out of %d dating back %s (%d) ...\n", msgCount, msgParsed, lastParsedTime.Format(time.RFC3339), lastParsedID64)
|
fmt.Printf("Waiting : %d messages retrieved out of %d dating back %s ...\n", msgCount, msgParsed, lastParsedTime.Format(time.RFC3339))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user