NZCovidBot/internal/nzcovidbot/nzcovidbot.go
Daniel Mason 86eef8cc8e
- Skip invalid webhooks
- Build cache based on row data instead of entire row
- Compare columns instead of entire row
- Removed commitHash check and instead just processes on succesfull git pull
- No more entire file dumps!
2021-09-03 14:18:47 +12:00

60 lines
1 KiB
Go

package nzcovidbot
import (
"fmt"
"time"
)
var Repository string
func Lesgoooo() {
// Setup repo stuff
loadRepo(Repository)
// Create chan to end timer
endTicker := make(chan bool)
// Timer to run every minute
minuteTicker := time.NewTicker(time.Duration(60) * time.Second)
// Initial check on load
go checkForUpdates()
for {
select {
case <-endTicker:
fmt.Println("Stopping background workers")
return
case <-minuteTicker.C:
// Check for updates
go checkForUpdates()
}
}
}
func postTheUpdates() {
// Lets reshuffle our structured data a bit (Exposure Date ASC)
orderRowDataByDate()
// Twitter
go postToTwitter()
// Slack
go postToSlack()
// Discord
postableDiscordData := getPostableDiscordData()
if len(postableDiscordData) == 0 {
return
}
for _, discordWebhook := range DiscordWebhooks {
for _, postableData := range postableDiscordData {
go postToDiscord(discordWebhook, postableData)
time.Sleep(500 * time.Millisecond)
}
}
// Clear out posted data!
updatedLocations = UpdatedLocations{}
}