-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathBotStatusMonitor.cs
27 lines (25 loc) · 1.05 KB
/
BotStatusMonitor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using CompatBot.Database;
using Microsoft.EntityFrameworkCore;
namespace CompatBot.EventHandlers;
internal static class BotStatusMonitor
{
public static async Task RefreshAsync(DiscordClient client)
{
try
{
await using var db = await BotDb.OpenReadAsync().ConfigureAwait(false);
var status = await db.BotState.FirstOrDefaultAsync(s => s.Key == "bot-status-activity").ConfigureAwait(false);
var txt = await db.BotState.FirstOrDefaultAsync(s => s.Key == "bot-status-text").ConfigureAwait(false);
var msg = txt?.Value;
if (Enum.TryParse<DiscordActivityType>(status?.Value ?? "Watching", true, out var activity)
&& msg is {Length: >0})
await client.UpdateStatusAsync(new(msg, activity), DiscordUserStatus.Online).ConfigureAwait(false);
else
await client.UpdateStatusAsync(userStatus: DiscordUserStatus.Online).ConfigureAwait(false);
}
catch (Exception e)
{
Config.Log.Error(e);
}
}
}