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