mirror of
https://github.com/idanoo/NZCovidBot
synced 2025-07-01 11:12:15 +00:00
Batch discord data to 20 locations at a time
This commit is contained in:
parent
fdad4bffbb
commit
4c283f1cbb
2 changed files with 14 additions and 6 deletions
|
@ -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 {
|
||||
|
|
|
@ -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!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue