Skip to content

Commit

Permalink
Fixes NullRef in LogDelete
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackcatmaxy committed Jun 21, 2022
1 parent 3fb43cf commit d398449
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/BotCatMaxy/Services/Logging/LoggingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,20 @@ private async Task LogDelete(Cacheable<IMessage, ulong> message, Cacheable<IMess
IMessageChannel channel = await cachedChannel.GetOrDownloadAsync();
try
{
if (!(channel is SocketGuildChannel))
if (channel is not SocketGuildChannel guildChannel || guildChannel.Guild == null)
return;
SocketGuild guild = (channel as SocketGuildChannel).Guild;
SocketGuild guild = guildChannel.Guild;

// Check if we should stop doing the log based on settings
LogSettings settings = guild.LoadFromFile<LogSettings>();

if (settings.channelLogBlacklist.Contains(channel.Id))
LogSettings settings = guild.LoadFromFile<LogSettings>(false);
if (settings?.channelLogBlacklist != null && settings.channelLogBlacklist.Contains(channel.Id))
return;

await DiscordLogging.LogMessage("Deleted message", message.GetOrDownloadAsync().Result);
}
catch (Exception exception)
{
await new LogMessage(LogSeverity.Error, "Logging", "Error", exception).Log();
LogSeverity.Error.LogException("Logging", "Error logging deleted message", exception);
}
//Console.WriteLine(new LogMessage(LogSeverity.Info, "Logging", "Message deleted"));
}
}

0 comments on commit d398449

Please sign in to comment.