|
|
|
@ -25,28 +25,45 @@ func RecalculateEverything(dg *discordgo.Session, guildID string) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
listOfMessages := make(map[string][]*discordgo.Message)
|
|
|
|
|
for _, v := range guild.Channels {
|
|
|
|
|
if persistent.IgnoredChannels[v.ID] {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
beforeID := ""
|
|
|
|
|
for {
|
|
|
|
|
messages, err := dg.ChannelMessages(v.ID, 100, beforeID, "", "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
util.ReportError(dg, err)
|
|
|
|
|
return
|
|
|
|
|
latestMessage := make(map[string]string)
|
|
|
|
|
for {
|
|
|
|
|
newMessagesFound := false
|
|
|
|
|
for _, v := range guild.Channels {
|
|
|
|
|
if persistent.IgnoredChannels[v.ID] {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
for _, msg := range messages {
|
|
|
|
|
if list, ok := listOfMessages[msg.Author.ID]; ok {
|
|
|
|
|
listOfMessages[msg.Author.ID] = append(list, msg)
|
|
|
|
|
} else {
|
|
|
|
|
listOfMessages[msg.Author.ID] = []*discordgo.Message{msg}
|
|
|
|
|
beforeID := ""
|
|
|
|
|
for {
|
|
|
|
|
messages, err := dg.ChannelMessages(v.ID, 100, beforeID, "", "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
util.ReportError(dg, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if beforeID == "" && len(messages) > 0 && messages[0].ID != latestMessage[v.ID] {
|
|
|
|
|
newMessagesFound = true
|
|
|
|
|
latestMessage[v.ID] = messages[0].ID
|
|
|
|
|
}
|
|
|
|
|
dupe := false
|
|
|
|
|
for _, msg := range messages {
|
|
|
|
|
if msg.ID == latestMessage[v.ID] {
|
|
|
|
|
dupe = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
if list, ok := listOfMessages[msg.Author.ID]; ok {
|
|
|
|
|
listOfMessages[msg.Author.ID] = append(list, msg)
|
|
|
|
|
} else {
|
|
|
|
|
listOfMessages[msg.Author.ID] = []*discordgo.Message{msg}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if len(messages) < 100 || dupe {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
beforeID = messages[99].ID
|
|
|
|
|
}
|
|
|
|
|
if len(messages) < 100 {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
beforeID = messages[99].ID
|
|
|
|
|
}
|
|
|
|
|
fmt.Printf("[RECALC] Batch step reached in %v.\n", time.Now().Sub(startTime))
|
|
|
|
|
if !newMessagesFound {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fetchedTime := time.Now()
|
|
|
|
|