Batch discord data to 20 locations at a time

This commit is contained in:
Daniel Mason 2021-09-02 09:37:06 +12:00
parent fdad4bffbb
commit 4c283f1cbb
Signed by: idanoo
GPG key ID: 387387CDBC02F132
2 changed files with 14 additions and 6 deletions

View file

@ -89,9 +89,10 @@ func parseRawRowData(data string) []string {
return append(output, starttime, endtime, c[1], c[2])
}
func getPostableDiscordData() string {
func getPostableDiscordData() []string {
groups := make([]string, 0)
if len(updatedLocations.Locations) == 0 {
return ""
return groups
}
rows := make([]string, 0)
@ -101,9 +102,14 @@ func getPostableDiscordData() string {
} else {
rows = append(rows, location.DiscordData)
}
if len(rows) > 20 {
groups = append(groups, strings.Join(rows, "\n"))
rows = make([]string, 0)
}
}
return strings.Join(rows, "\n")
return append(groups, strings.Join(rows, "\n"))
}
func getPostableSlackData() []string {

View file

@ -42,13 +42,15 @@ func postTheUpdates() {
// Discord
postableDiscordData := getPostableDiscordData()
if postableDiscordData == "" {
if len(postableDiscordData) == 0 {
return
}
// Not using go routines so we don't get rate limited
for _, discordWebhook := range DiscordWebhooks {
postToDiscord(discordWebhook, postableDiscordData)
for _, postableData := range postableDiscordData {
go postToDiscord(discordWebhook, postableData)
time.Sleep(1 * time.Second)
}
}
// Clear out posted data!