Updated Permissions module

This commit is contained in:
Toastie (DCS Team) 2024-06-26 22:20:28 +12:00
parent a4adabb3ea
commit 888994dd67
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
10 changed files with 16 additions and 18 deletions

View file

@ -1,4 +1,4 @@
#nullable disable #nullable disable
using EllieBot.Modules.Permissions.Services; using EllieBot.Modules.Permissions.Services;
using EllieBot.Db.Models; using EllieBot.Db.Models;
@ -46,7 +46,7 @@ public partial class Permissions
Log.Warning("Can't get {BlacklistType} [{BlacklistItemId}]", Log.Warning("Can't get {BlacklistType} [{BlacklistItemId}]",
i.Type, i.Type,
i.ItemId); i.ItemId);
return Task.FromResult(Format.Code(i.ItemId.ToString())); return Task.FromResult(Format.Code(i.ItemId.ToString()));
} }
}) })

View file

@ -33,7 +33,7 @@ public sealed class CmdCdService : IExecPreCommand, IReadyExecutor, IEService
{ {
if (guild is null) if (guild is null)
return Task.FromResult(false); return Task.FromResult(false);
if (!_settings.TryGetValue(guild.Id, out var cooldownSettings)) if (!_settings.TryGetValue(guild.Id, out var cooldownSettings))
return Task.FromResult(false); return Task.FromResult(false);
@ -82,7 +82,7 @@ public sealed class CmdCdService : IExecPreCommand, IReadyExecutor, IEService
_activeCooldowns.Remove((guildId, commandName), out _); _activeCooldowns.Remove((guildId, commandName), out _);
continue; continue;
} }
Cleanup(dict, cdSeconds); Cleanup(dict, cdSeconds);
} }
} }
@ -103,7 +103,7 @@ public sealed class CmdCdService : IExecPreCommand, IReadyExecutor, IEService
dict.TryRemove(cmdName, out _); dict.TryRemove(cmdName, out _);
_activeCooldowns.TryRemove((guildId, cmdName), out _); _activeCooldowns.TryRemove((guildId, cmdName), out _);
using var ctx = _db.GetDbContext(); using var ctx = _db.GetDbContext();
var gc = ctx.GuildConfigsForId(guildId, x => x.Include(x => x.CommandCooldowns)); var gc = ctx.GuildConfigsForId(guildId, x => x.Include(x => x.CommandCooldowns));
gc.CommandCooldowns.RemoveWhere(x => x.CommandName == cmdName); gc.CommandCooldowns.RemoveWhere(x => x.CommandName == cmdName);
@ -120,7 +120,7 @@ public sealed class CmdCdService : IExecPreCommand, IReadyExecutor, IEService
// force cleanup // force cleanup
if (_activeCooldowns.TryGetValue((guildId, name), out var dict)) if (_activeCooldowns.TryGetValue((guildId, name), out var dict))
Cleanup(dict, secs); Cleanup(dict, secs);
using var ctx = _db.GetDbContext(); using var ctx = _db.GetDbContext();
var gc = ctx.GuildConfigsForId(guildId, x => x.Include(x => x.CommandCooldowns)); var gc = ctx.GuildConfigsForId(guildId, x => x.Include(x => x.CommandCooldowns));
gc.CommandCooldowns.RemoveWhere(x => x.CommandName == name); gc.CommandCooldowns.RemoveWhere(x => x.CommandName == name);

View file

@ -171,7 +171,7 @@ public sealed class FilterService : IExecOnMessage
// if user has manage messages perm, don't filter // if user has manage messages perm, don't filter
if (usrMsg.Channel is ITextChannel ch && usrMsg.Author is IGuildUser gu && gu.GetPermissions(ch).ManageMessages) if (usrMsg.Channel is ITextChannel ch && usrMsg.Author is IGuildUser gu && gu.GetPermissions(ch).ManageMessages)
return false; return false;
if ((InviteFilteringChannels.Contains(usrMsg.Channel.Id) || InviteFilteringServers.Contains(guild.Id)) if ((InviteFilteringChannels.Contains(usrMsg.Channel.Id) || InviteFilteringServers.Contains(guild.Id))
&& usrMsg.Content.IsDiscordInvite()) && usrMsg.Content.IsDiscordInvite())
{ {
@ -207,7 +207,7 @@ public sealed class FilterService : IExecOnMessage
// if user has manage messages perm, don't filter // if user has manage messages perm, don't filter
if (usrMsg.Channel is ITextChannel ch && usrMsg.Author is IGuildUser gu && gu.GetPermissions(ch).ManageMessages) if (usrMsg.Channel is ITextChannel ch && usrMsg.Author is IGuildUser gu && gu.GetPermissions(ch).ManageMessages)
return false; return false;
if ((LinkFilteringChannels.Contains(usrMsg.Channel.Id) || LinkFilteringServers.Contains(guild.Id)) if ((LinkFilteringChannels.Contains(usrMsg.Channel.Id) || LinkFilteringServers.Contains(guild.Id))
&& usrMsg.Content.TryGetUrlPath(out _)) && usrMsg.Content.TryGetUrlPath(out _))
{ {

View file

@ -1,4 +1,4 @@
#nullable disable #nullable disable
namespace EllieBot.Modules.Permissions.Services; namespace EllieBot.Modules.Permissions.Services;
public readonly struct ServerFilterSettings public readonly struct ServerFilterSettings

View file

@ -1,4 +1,4 @@
#nullable disable #nullable disable
using EllieBot.Common.ModuleBehaviors; using EllieBot.Common.ModuleBehaviors;
namespace EllieBot.Modules.Permissions.Services; namespace EllieBot.Modules.Permissions.Services;

View file

@ -1,4 +1,4 @@
#nullable disable #nullable disable
using EllieBot.Db.Models; using EllieBot.Db.Models;
namespace EllieBot.Modules.Permissions.Common; namespace EllieBot.Modules.Permissions.Common;

View file

@ -1,4 +1,4 @@
#nullable disable #nullable disable
using EllieBot.Db.Models; using EllieBot.Db.Models;
namespace EllieBot.Modules.Permissions.Common; namespace EllieBot.Modules.Permissions.Common;

View file

@ -541,4 +541,4 @@ public partial class Permissions : EllieModule<PermissionService>
else else
await Response().Confirm(strs.asm_disable).SendAsync(); await Response().Confirm(strs.asm_disable).SendAsync();
} }
} }

View file

@ -1,4 +1,4 @@
#nullable disable #nullable disable
namespace EllieBot.Modules.Permissions.Common; namespace EllieBot.Modules.Permissions.Common;
public class PermissionsCollection<T> : IndexedCollection<T> public class PermissionsCollection<T> : IndexedCollection<T>

View file

@ -149,8 +149,7 @@ public class PermissionService : IExecPreCommand, IEService
returnMsg = "You need Admin permissions in order to use permission commands."; returnMsg = "You need Admin permissions in order to use permission commands.";
if (pc.Verbose) if (pc.Verbose)
{ {
try try { await _sender.Response(channel).Error(returnMsg).SendAsync(); }
{ await _sender.Response(channel).Error(returnMsg).SendAsync(); }
catch { } catch { }
} }
@ -162,8 +161,7 @@ public class PermissionService : IExecPreCommand, IEService
returnMsg = $"You need the {Format.Bold(role.Name)} role in order to use permission commands."; returnMsg = $"You need the {Format.Bold(role.Name)} role in order to use permission commands.";
if (pc.Verbose) if (pc.Verbose)
{ {
try try { await _sender.Response(channel).Error(returnMsg).SendAsync(); }
{ await _sender.Response(channel).Error(returnMsg).SendAsync(); }
catch { } catch { }
} }