From 769594c0317c0bcb0f11ad4ee5b10f4cc0896c76 Mon Sep 17 00:00:00 2001 From: Erisa A Date: Fri, 5 Jan 2024 01:40:47 +0000 Subject: [PATCH] Add support for Uptime Kuma heartbeat push Closes #186 --- .env-example | 3 ++- Events/HeartbeatEvent.cs | 15 +++++++++++++++ Program.cs | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Events/HeartbeatEvent.cs diff --git a/.env-example b/.env-example index 09e1e14b..4dff6783 100644 --- a/.env-example +++ b/.env-example @@ -4,4 +4,5 @@ CLIPTOK_ANTIPHISHING_ENDPOINT=useyourimagination RAVY_API_TOKEN=goodluckfindingone CLOUDFLARED_TOKEN=ignoreifnotrelevant USERNAME_CHECK_ENDPOINT=https://api.example.com/username -CLIPTALK_WEBHOOK=https://discord.com \ No newline at end of file +CLIPTALK_WEBHOOK=https://discord.com +UPTIME_KUMA_PUSH_URL= \ No newline at end of file diff --git a/Events/HeartbeatEvent.cs b/Events/HeartbeatEvent.cs new file mode 100644 index 00000000..216bcd58 --- /dev/null +++ b/Events/HeartbeatEvent.cs @@ -0,0 +1,15 @@ +namespace Cliptok.Events +{ + public class HeartbeatEvent + { + public static async Task OnHeartbeat(DiscordClient client, HeartbeatEventArgs e) + { + if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("UPTIME_KUMA_PUSH_URL"))) + { + var response = await Program.httpClient.GetAsync(Environment.GetEnvironmentVariable("UPTIME_KUMA_PUSH_URL") + client.Ping); + client.Logger.LogDebug("Heartbeat ping sent: {status} {content}", (int)response.StatusCode, await response.Content.ReadAsStringAsync()); + return; + } + } + } +} diff --git a/Program.cs b/Program.cs index a4ac647d..a7125ffd 100644 --- a/Program.cs +++ b/Program.cs @@ -151,6 +151,7 @@ static async Task Main(string[] _) discord.ThreadListSynced += ThreadEvents.Discord_ThreadListSynced; discord.ThreadMemberUpdated += ThreadEvents.Discord_ThreadMemberUpdated; discord.ThreadMembersUpdated += ThreadEvents.Discord_ThreadMembersUpdated; + discord.Heartbeated += HeartbeatEvent.OnHeartbeat; discord.GuildBanRemoved += UnbanEvent.OnUnban;