1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-06 22:16:29 +03:00

Log exceptions thrown during "fire-and-forget" async method calls

This commit is contained in:
Octol1ttle 2022-11-16 23:27:10 +05:00
parent 14ebcb1f1c
commit 29c2332ad9
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
3 changed files with 44 additions and 28 deletions

View file

@ -11,7 +11,9 @@ public static class Boyfriend {
private static readonly DiscordSocketConfig Config = new() {
MessageCacheSize = 250,
GatewayIntents = (GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent | GatewayIntents.GuildMembers) & ~GatewayIntents.GuildInvites,
GatewayIntents
= (GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent | GatewayIntents.GuildMembers) &
~GatewayIntents.GuildInvites,
AlwaysDownloadUsers = true,
AlwaysResolveStickers = false,
AlwaysDownloadDefaultStickers = false,
@ -59,7 +61,7 @@ public static class Boyfriend {
private static async Task Init() {
var token = (await File.ReadAllTextAsync("token.txt")).Trim();
Client.Log += Log;
Client.Log += x => Log(x);
await Client.LoginAsync(TokenType.Bot, token);
await Client.StartAsync();
@ -75,7 +77,7 @@ public static class Boyfriend {
// ReSharper disable once FunctionNeverReturns
}
private static Task Log(LogMessage msg) {
public static Task Log(LogMessage msg) {
switch (msg.Severity) {
case LogSeverity.Critical:
Console.ForegroundColor = ConsoleColor.DarkRed;
@ -103,7 +105,8 @@ public static class Boyfriend {
}
public static async Task WriteGuildConfigAsync(ulong id) {
await File.WriteAllTextAsync($"config_{id}.json", JsonConvert.SerializeObject(GuildConfigDictionary[id], Formatting.Indented));
await File.WriteAllTextAsync($"config_{id}.json",
JsonConvert.SerializeObject(GuildConfigDictionary[id], Formatting.Indented));
if (RemovedRolesDictionary.TryGetValue(id, out var removedRoles))
await File.WriteAllTextAsync($"removedroles_{id}.json",