Skip to content

Commit

Permalink
Add Uptime Kuma heartbeat status to /ping because why not
Browse files Browse the repository at this point in the history
  • Loading branch information
FloatingMilkshake committed Sep 8, 2024
1 parent 4e6a6bd commit 0841861
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Commands/Ping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(
$"Pong!\n"
+ $"Websocket ping: `{websocketPing}ms`\n"
+ $"Interaction latency: `{interactionLatency}ms`\n"
+ $"Database ping: {(double.IsNaN(dbPing) ? "Unreachable!" : $"`{dbPing}ms`")}"));
+ $"Database ping: {(double.IsNaN(dbPing) ? "Unreachable!" : $"`{dbPing}ms`")}\n"
+ $"Uptime Kuma heartbeat status: `{Program.LastUptimeKumaHeartbeatStatus}`"));
}
}
2 changes: 2 additions & 0 deletions Events/HeartbeatEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ public static async Task Heartbeated(DiscordClient client, HeartbeatEventArgs e)
Program.Discord.Logger.LogDebug(Program.BotEventId, "Successfully sent Uptime Kuma heartbeat with ping {ping}ms", e.Ping);
else
Program.Discord.Logger.LogWarning(Program.BotEventId, "Uptime Kuma heartbeat failed with status code {statusCode}", heartbeatResponse.StatusCode);
Program.LastUptimeKumaHeartbeatStatus = heartbeatResponse.StatusCode.ToString();
}
catch (Exception ex)
{
Program.Discord.Logger.LogWarning(Program.BotEventId, "Uptime Kuma heartbeat failed: {exType}: {exMessage}\n{stackTrace}", ex.GetType(), ex.Message, ex.StackTrace);
Program.LastUptimeKumaHeartbeatStatus = "exception thrown";
}
}
}
4 changes: 3 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System.Net;
using System.Threading;

namespace MechanicalMilkshake;

Expand Down Expand Up @@ -26,6 +27,7 @@ public class Program
public static readonly IDatabase Db = Redis.GetDatabase();
public static bool RedisExceptionsSuppressed;
public static readonly MessageCache MessageCache = new();
public static string LastUptimeKumaHeartbeatStatus = "N/A";

public static readonly Dictionary<string, ulong> UserFlagEmoji = new()
{
Expand Down

0 comments on commit 0841861

Please sign in to comment.