fixed nullref in blacklist
This commit is contained in:
parent
f68ff81dce
commit
2d806119b4
3 changed files with 3 additions and 27 deletions
|
@ -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();
|
|
||||||
}
|
|
|
@ -1,4 +1,3 @@
|
||||||
#nullable disable
|
|
||||||
using LinqToDB;
|
using LinqToDB;
|
||||||
using LinqToDB.Data;
|
using LinqToDB.Data;
|
||||||
using LinqToDB.EntityFrameworkCore;
|
using LinqToDB.EntityFrameworkCore;
|
||||||
|
@ -53,8 +52,7 @@ public sealed class BlacklistService : IExecOnMessage, IReadyExecutor
|
||||||
|
|
||||||
private ValueTask OnReload(BlacklistEntry[] newBlacklist)
|
private ValueTask OnReload(BlacklistEntry[] newBlacklist)
|
||||||
{
|
{
|
||||||
if (newBlacklist is null)
|
newBlacklist ??= [];
|
||||||
return default;
|
|
||||||
|
|
||||||
blacklistedGuilds =
|
blacklistedGuilds =
|
||||||
new HashSet<ulong>(newBlacklist.Where(x => x.Type == BlacklistType.Server).Select(x => x.ItemId))
|
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;
|
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}]",
|
Log.Information("Blocked input from blacklisted guild: {GuildName} [{GuildId}]",
|
||||||
guild.Name,
|
guild.Name,
|
||||||
|
|
Loading…
Reference in a new issue