diff --git a/config-example.xml b/config-example.xml index 6654845..e734c6b 100644 --- a/config-example.xml +++ b/config-example.xml @@ -3,4 +3,5 @@ AUTH_KEY_HERE CLOUDFLARE_TOKEN ZONE_NAME + \ No newline at end of file diff --git a/config.go b/config.go index b190d6b..479cf31 100644 --- a/config.go +++ b/config.go @@ -10,6 +10,7 @@ type Config struct { AccuweatherKey string `xml:"accuweather_key"` CloudflareToken string `xml:"cloudflare_token"` CloudflareZoneName string `xml:"cloudflare_zone_name"` + DiscordWebhook string `xml:"discord_webhook"` } func GetConfig() Config { diff --git a/main.go b/main.go index 3dad699..16ff4c1 100644 --- a/main.go +++ b/main.go @@ -188,8 +188,9 @@ func main() { }() } - // Finally purge Cloudflare cache + // Finally purge Cloudflare cache and send a webhook purgeCloudflareCache() + sendWebhook() wg.Wait() fmt.Println(time.Since(start)) diff --git a/webhook.go b/webhook.go new file mode 100644 index 0000000..f41dc39 --- /dev/null +++ b/webhook.go @@ -0,0 +1,45 @@ +package main + +import ( + "bytes" + "encoding/json" + "net/http" + "time" +) + +func sendWebhook() { + if config.DiscordWebhook != "" { + data := map[string]any{ + "username": "Forecast Bot", + "content": "Weather Data has been updated!", + "avatar_url": "https://rc24.xyz/images/logo-small.png", + "attachments": []map[string]any{ + { + "fallback": "Weather Data Update", + "color": "#0381D7", + "author_name": "RiiConnect24 Forecast Script", + "author_icon": "https://rc24.xyz/images/webhooks/forecast/profile.png", + "text": "Weather Data has been updated!", + "title": "Update!", + "fields": []map[string]any{ + { + "title": "Script", + "value": "Forecast Channel", + "short": false, + }, + }, + "thumb_url": "https://rc24.xyz/images/webhooks/forecast/accuweather.png", + "footer": "RiiConnect24 Script", + "footer_icon": "https://rc24.xyz/images/logo-small.png", + "ts": int(time.Now().Unix()), + }, + }, + } + + _bytes, err := json.Marshal(data) + checkError(err) + + _, err = http.Post(config.DiscordWebhook, "application/json", bytes.NewReader(_bytes)) + checkError(err) + } +}