From 888994dd677c182acaa11a5bda2512b6a5bd9c57 Mon Sep 17 00:00:00 2001 From: Toastie Date: Wed, 26 Jun 2024 22:20:28 +1200 Subject: [PATCH] Updated Permissions module --- .../Modules/Permissions/Blacklist/BlacklistCommands.cs | 4 ++-- .../Modules/Permissions/CommandCooldown/CmdCdService.cs | 8 ++++---- src/EllieBot/Modules/Permissions/Filter/FilterService.cs | 4 ++-- .../Modules/Permissions/Filter/ServerFilterSettings.cs | 2 +- .../GlobalPermissions/GlobalPermissionService.cs | 2 +- src/EllieBot/Modules/Permissions/PermissionCache.cs | 2 +- src/EllieBot/Modules/Permissions/PermissionExtensions.cs | 2 +- src/EllieBot/Modules/Permissions/Permissions.cs | 2 +- src/EllieBot/Modules/Permissions/PermissionsCollection.cs | 2 +- src/EllieBot/Modules/Permissions/PermissionsService.cs | 6 ++---- 10 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/EllieBot/Modules/Permissions/Blacklist/BlacklistCommands.cs b/src/EllieBot/Modules/Permissions/Blacklist/BlacklistCommands.cs index 9db46fb..b552636 100644 --- a/src/EllieBot/Modules/Permissions/Blacklist/BlacklistCommands.cs +++ b/src/EllieBot/Modules/Permissions/Blacklist/BlacklistCommands.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable using EllieBot.Modules.Permissions.Services; using EllieBot.Db.Models; @@ -46,7 +46,7 @@ public partial class Permissions Log.Warning("Can't get {BlacklistType} [{BlacklistItemId}]", i.Type, i.ItemId); - + return Task.FromResult(Format.Code(i.ItemId.ToString())); } }) diff --git a/src/EllieBot/Modules/Permissions/CommandCooldown/CmdCdService.cs b/src/EllieBot/Modules/Permissions/CommandCooldown/CmdCdService.cs index f4ea9e8..9f5c6e2 100644 --- a/src/EllieBot/Modules/Permissions/CommandCooldown/CmdCdService.cs +++ b/src/EllieBot/Modules/Permissions/CommandCooldown/CmdCdService.cs @@ -33,7 +33,7 @@ public sealed class CmdCdService : IExecPreCommand, IReadyExecutor, IEService { if (guild is null) return Task.FromResult(false); - + if (!_settings.TryGetValue(guild.Id, out var cooldownSettings)) return Task.FromResult(false); @@ -82,7 +82,7 @@ public sealed class CmdCdService : IExecPreCommand, IReadyExecutor, IEService _activeCooldowns.Remove((guildId, commandName), out _); continue; } - + Cleanup(dict, cdSeconds); } } @@ -103,7 +103,7 @@ public sealed class CmdCdService : IExecPreCommand, IReadyExecutor, IEService dict.TryRemove(cmdName, out _); _activeCooldowns.TryRemove((guildId, cmdName), out _); - + using var ctx = _db.GetDbContext(); var gc = ctx.GuildConfigsForId(guildId, x => x.Include(x => x.CommandCooldowns)); gc.CommandCooldowns.RemoveWhere(x => x.CommandName == cmdName); @@ -120,7 +120,7 @@ public sealed class CmdCdService : IExecPreCommand, IReadyExecutor, IEService // force cleanup if (_activeCooldowns.TryGetValue((guildId, name), out var dict)) Cleanup(dict, secs); - + using var ctx = _db.GetDbContext(); var gc = ctx.GuildConfigsForId(guildId, x => x.Include(x => x.CommandCooldowns)); gc.CommandCooldowns.RemoveWhere(x => x.CommandName == name); diff --git a/src/EllieBot/Modules/Permissions/Filter/FilterService.cs b/src/EllieBot/Modules/Permissions/Filter/FilterService.cs index 9dfe01e..139d0d5 100644 --- a/src/EllieBot/Modules/Permissions/Filter/FilterService.cs +++ b/src/EllieBot/Modules/Permissions/Filter/FilterService.cs @@ -171,7 +171,7 @@ public sealed class FilterService : IExecOnMessage // if user has manage messages perm, don't filter if (usrMsg.Channel is ITextChannel ch && usrMsg.Author is IGuildUser gu && gu.GetPermissions(ch).ManageMessages) return false; - + if ((InviteFilteringChannels.Contains(usrMsg.Channel.Id) || InviteFilteringServers.Contains(guild.Id)) && usrMsg.Content.IsDiscordInvite()) { @@ -207,7 +207,7 @@ public sealed class FilterService : IExecOnMessage // if user has manage messages perm, don't filter if (usrMsg.Channel is ITextChannel ch && usrMsg.Author is IGuildUser gu && gu.GetPermissions(ch).ManageMessages) return false; - + if ((LinkFilteringChannels.Contains(usrMsg.Channel.Id) || LinkFilteringServers.Contains(guild.Id)) && usrMsg.Content.TryGetUrlPath(out _)) { diff --git a/src/EllieBot/Modules/Permissions/Filter/ServerFilterSettings.cs b/src/EllieBot/Modules/Permissions/Filter/ServerFilterSettings.cs index bf8454b..3c60a9f 100644 --- a/src/EllieBot/Modules/Permissions/Filter/ServerFilterSettings.cs +++ b/src/EllieBot/Modules/Permissions/Filter/ServerFilterSettings.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable namespace EllieBot.Modules.Permissions.Services; public readonly struct ServerFilterSettings diff --git a/src/EllieBot/Modules/Permissions/GlobalPermissions/GlobalPermissionService.cs b/src/EllieBot/Modules/Permissions/GlobalPermissions/GlobalPermissionService.cs index 00dfd78..42ad5d7 100644 --- a/src/EllieBot/Modules/Permissions/GlobalPermissions/GlobalPermissionService.cs +++ b/src/EllieBot/Modules/Permissions/GlobalPermissions/GlobalPermissionService.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable using EllieBot.Common.ModuleBehaviors; namespace EllieBot.Modules.Permissions.Services; diff --git a/src/EllieBot/Modules/Permissions/PermissionCache.cs b/src/EllieBot/Modules/Permissions/PermissionCache.cs index 47b5983..75bd501 100644 --- a/src/EllieBot/Modules/Permissions/PermissionCache.cs +++ b/src/EllieBot/Modules/Permissions/PermissionCache.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable using EllieBot.Db.Models; namespace EllieBot.Modules.Permissions.Common; diff --git a/src/EllieBot/Modules/Permissions/PermissionExtensions.cs b/src/EllieBot/Modules/Permissions/PermissionExtensions.cs index 04eee4e..776664e 100644 --- a/src/EllieBot/Modules/Permissions/PermissionExtensions.cs +++ b/src/EllieBot/Modules/Permissions/PermissionExtensions.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable using EllieBot.Db.Models; namespace EllieBot.Modules.Permissions.Common; diff --git a/src/EllieBot/Modules/Permissions/Permissions.cs b/src/EllieBot/Modules/Permissions/Permissions.cs index 90de56b..447dd19 100644 --- a/src/EllieBot/Modules/Permissions/Permissions.cs +++ b/src/EllieBot/Modules/Permissions/Permissions.cs @@ -541,4 +541,4 @@ public partial class Permissions : EllieModule else await Response().Confirm(strs.asm_disable).SendAsync(); } -} +} \ No newline at end of file diff --git a/src/EllieBot/Modules/Permissions/PermissionsCollection.cs b/src/EllieBot/Modules/Permissions/PermissionsCollection.cs index c2526ea..e869bc7 100644 --- a/src/EllieBot/Modules/Permissions/PermissionsCollection.cs +++ b/src/EllieBot/Modules/Permissions/PermissionsCollection.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable namespace EllieBot.Modules.Permissions.Common; public class PermissionsCollection : IndexedCollection diff --git a/src/EllieBot/Modules/Permissions/PermissionsService.cs b/src/EllieBot/Modules/Permissions/PermissionsService.cs index 7bca184..95b6388 100644 --- a/src/EllieBot/Modules/Permissions/PermissionsService.cs +++ b/src/EllieBot/Modules/Permissions/PermissionsService.cs @@ -149,8 +149,7 @@ public class PermissionService : IExecPreCommand, IEService returnMsg = "You need Admin permissions in order to use permission commands."; if (pc.Verbose) { - try - { await _sender.Response(channel).Error(returnMsg).SendAsync(); } + try { await _sender.Response(channel).Error(returnMsg).SendAsync(); } 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."; if (pc.Verbose) { - try - { await _sender.Response(channel).Error(returnMsg).SendAsync(); } + try { await _sender.Response(channel).Error(returnMsg).SendAsync(); } catch { } }