fixed nullref in blacklist

This commit is contained in:
Toastie (DCS Team) 2024-11-18 16:55:56 +13:00
parent f68ff81dce
commit 2d806119b4
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
3 changed files with 3 additions and 27 deletions

View file

@ -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<SelfAssignedRole> 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<SelfAssignedRole> GetFromGuild(this DbSet<SelfAssignedRole> roles, ulong guildId)
=> roles.AsQueryable().Where(s => s.GuildId == guildId).ToArray();
}

View file

@ -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<ulong>(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<bool> ExecOnMessageAsync(IGuild guild, IUserMessage usrMsg)
public Task<bool> 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,