From 80a41c1f38a9299e5fc3cf730a583b8e4ffadc98 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 17 Nov 2024 19:14:40 +0000 Subject: [PATCH] fix: fixed nullref in blacklist --- .../SelfAssignableRolesExtensions.cs | 22 ------------------- .../{Provider.cs => StreamProvider.cs} | 2 +- .../_common/Services/Impl/BlacklistService.cs | 8 +++---- 3 files changed, 4 insertions(+), 28 deletions(-) delete mode 100644 src/NadekoBot/Db/Extensions/SelfAssignableRolesExtensions.cs rename src/NadekoBot/Modules/Searches/_common/StreamNotifications/Providers/{Provider.cs => StreamProvider.cs} (98%) diff --git a/src/NadekoBot/Db/Extensions/SelfAssignableRolesExtensions.cs b/src/NadekoBot/Db/Extensions/SelfAssignableRolesExtensions.cs deleted file mode 100644 index 61ccb3777..000000000 --- a/src/NadekoBot/Db/Extensions/SelfAssignableRolesExtensions.cs +++ /dev/null @@ -1,22 +0,0 @@ -#nullable disable -using Microsoft.EntityFrameworkCore; -using NadekoBot.Db.Models; - -namespace NadekoBot.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/NadekoBot/Modules/Searches/_common/StreamNotifications/Providers/Provider.cs b/src/NadekoBot/Modules/Searches/_common/StreamNotifications/Providers/StreamProvider.cs similarity index 98% rename from src/NadekoBot/Modules/Searches/_common/StreamNotifications/Providers/Provider.cs rename to src/NadekoBot/Modules/Searches/_common/StreamNotifications/Providers/StreamProvider.cs index 368824ca5..ced49ecb2 100644 --- a/src/NadekoBot/Modules/Searches/_common/StreamNotifications/Providers/Provider.cs +++ b/src/NadekoBot/Modules/Searches/_common/StreamNotifications/Providers/StreamProvider.cs @@ -5,7 +5,7 @@ namespace NadekoBot.Modules.Searches.Common.StreamNotifications.Providers; /// /// Abstract class implemented by providers of all supported platforms /// -public abstract class Provider +public abstract class StreamProvider { /// /// Type of the platform. diff --git a/src/NadekoBot/_common/Services/Impl/BlacklistService.cs b/src/NadekoBot/_common/Services/Impl/BlacklistService.cs index 73bae6a83..9c2e38ba5 100644 --- a/src/NadekoBot/_common/Services/Impl/BlacklistService.cs +++ b/src/NadekoBot/_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,