test
This commit is contained in:
parent
2c184d72fb
commit
9e157a1945
8
main.go
8
main.go
@ -30,8 +30,10 @@ type Config struct {
|
||||
}
|
||||
|
||||
var (
|
||||
config = flag.String("config", "gocw2.cfg", "config file path")
|
||||
history = flag.Bool("history", false, "initialize chat history")
|
||||
config = flag.String("config", "gocw2.cfg", "config file path")
|
||||
history = flag.Bool("history", false, "initialize chat history")
|
||||
historyChatID64 = flag.int64("chat_id", nil, "chat to historize")
|
||||
historySenderUserID64 = flag.int64("sender_user_id", nil, "sender_user_id to historize")
|
||||
|
||||
cfg Config
|
||||
|
||||
@ -111,7 +113,7 @@ func main() {
|
||||
|
||||
if *history {
|
||||
fmt.Printf("Retrieving chat.\n")
|
||||
getHistory(client)
|
||||
getHistory(client, historyChatID64, historySenderUserID64)
|
||||
return
|
||||
}
|
||||
|
||||
|
28
td.go
28
td.go
@ -67,13 +67,19 @@ func ListenCW(c *tdlib.Client) {
|
||||
}
|
||||
}
|
||||
|
||||
func getHistory(c *tdlib.Client) {
|
||||
func getHistory(c *tdlib.Client, chatID64 int64, senderUserID64 int64) {
|
||||
var lastMsgID64 int64 = int64(math.MaxInt64)
|
||||
var msgCount int32 = 0
|
||||
var lastMsgTime time.Time = time.Now()
|
||||
|
||||
if chatID64 == nil {
|
||||
c := user_chtwrsbot
|
||||
} else {
|
||||
c = chatID64
|
||||
}
|
||||
|
||||
for lastMsgID64 >= 0 {
|
||||
msgs, err := c.GetChatHistory(user_chtwrsbot, lastMsgID64, 0, 10, false)
|
||||
msgs, err := c.GetChatHistory(c, lastMsgID64, 0, 10, false)
|
||||
if err != nil {
|
||||
if err.Error() == "timeout" {
|
||||
logOnError(err, "Waiting...")
|
||||
@ -94,12 +100,24 @@ func getHistory(c *tdlib.Client) {
|
||||
ChatID64: msg.ChatID,
|
||||
Text: msg.Content.(*tdlib.MessageText).Text.Text,
|
||||
}
|
||||
} else if msg.ForwardInfo.GetMessageForwardInfoEnum() == tdlib.MessageForwardedFromUserType {
|
||||
m = ChatWarsMessage{
|
||||
SenderUserID64: int64(msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).SenderUserID),
|
||||
Date: msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).Date,
|
||||
ID64: msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).ForwardedFromMessageID,
|
||||
ChatID64: msg.ForwardInfo.(*tdlib.MessageForwardedFromUser).ForwardedFromChatID,
|
||||
Text: msg.Content.(*tdlib.MessageText).Text.Text,
|
||||
}
|
||||
} else {
|
||||
m = nil
|
||||
}
|
||||
|
||||
if m != nil {
|
||||
MQCWMsgQueue <- m
|
||||
|
||||
if msg.ID < lastMsgID64 {
|
||||
lastMsgID64 = msg.ID
|
||||
lastMsgTime = time.Unix(int64(msg.Date), 0)
|
||||
if m.ID64 < lastMsgID64 {
|
||||
lastMsgID64 = m.ID64
|
||||
lastMsgTime = time.Unix(int64(m.Date), 0)
|
||||
}
|
||||
msgCount = msgCount + 1
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user