From 2d806119b4d545f67d7f83c1d273ed6b1f3ca351 Mon Sep 17 00:00:00 2001 From: Toastie Date: Mon, 18 Nov 2024 16:55:56 +1300 Subject: [PATCH] fixed nullref in blacklist --- .../SelfAssignableRolesExtensions.cs | 22 ------------------- .../{Provider.cs => StreamProvider.cs} | 0 .../_common/Services/Impl/BlacklistService.cs | 8 +++---- 3 files changed, 3 insertions(+), 27 deletions(-) delete mode 100644 src/EllieBot/Db/Extensions/SelfAssignableRolesExtensions.cs rename src/EllieBot/Modules/Searches/_common/StreamNotifications/Providers/{Provider.cs => StreamProvider.cs} (100%) diff --git a/src/EllieBot/Db/Extensions/SelfAssignableRolesExtensions.cs b/src/EllieBot/Db/Extensions/SelfAssignableRolesExtensions.cs deleted file mode 100644 index 740a155..0000000 --- a/src/EllieBot/Db/Extensions/SelfAssignableRolesExtensions.cs +++ /dev/null @@ -1,22 +0,0 @@ -#nullable disable -using Microsoft.EntityFrameworkCore; -using EllieBot.Db.Models; - -namespace EllieBot.Db; - -public static class SelfAssignableRolesExtensions -{ - public static bool DeleteByGuildAndRoleId(this DbSet roles, ulong guildId, ulong roleId) - { - var role = roles.FirstOrDefault(s => s.GuildId == guildId && s.RoleId == roleId); - - if (role is null) - return false; - - roles.Remove(role); - return true; - } - - public static IReadOnlyCollection GetFromGuild(this DbSet roles, ulong guildId) - => roles.AsQueryable().Where(s => s.GuildId == guildId).ToArray(); -} \ No newline at end of file diff --git a/src/EllieBot/Modules/Searches/_common/StreamNotifications/Providers/Provider.cs b/src/EllieBot/Modules/Searches/_common/StreamNotifications/Providers/StreamProvider.cs similarity index 100% rename from src/EllieBot/Modules/Searches/_common/StreamNotifications/Providers/Provider.cs rename to src/EllieBot/Modules/Searches/_common/StreamNotifications/Providers/StreamProvider.cs diff --git a/src/EllieBot/_common/Services/Impl/BlacklistService.cs b/src/EllieBot/_common/Services/Impl/BlacklistService.cs index 6655149..b92f5b2 100644 --- a/src/EllieBot/_common/Services/Impl/BlacklistService.cs +++ b/src/EllieBot/_common/Services/Impl/BlacklistService.cs @@ -1,4 +1,3 @@ -#nullable disable using LinqToDB; using LinqToDB.Data; using LinqToDB.EntityFrameworkCore; @@ -53,8 +52,7 @@ public sealed class BlacklistService : IExecOnMessage, IReadyExecutor private ValueTask OnReload(BlacklistEntry[] newBlacklist) { - if (newBlacklist is null) - return default; + newBlacklist ??= []; blacklistedGuilds = new HashSet(newBlacklist.Where(x => x.Type == BlacklistType.Server).Select(x => x.ItemId)) @@ -69,9 +67,9 @@ public sealed class BlacklistService : IExecOnMessage, IReadyExecutor return default; } - public Task ExecOnMessageAsync(IGuild guild, IUserMessage usrMsg) + public Task ExecOnMessageAsync(IGuild? guild, IUserMessage usrMsg) { - if (blacklistedGuilds.Contains(guild.Id)) + if (guild is not null && blacklistedGuilds.Contains(guild.Id)) { Log.Information("Blocked input from blacklisted guild: {GuildName} [{GuildId}]", guild.Name,