diff --git a/BirthdayBot.cs b/BirthdayBot.cs index bb8e7c2..51e957a 100644 --- a/BirthdayBot.cs +++ b/BirthdayBot.cs @@ -120,8 +120,7 @@ namespace BirthdayBot var gconf = await GuildConfiguration.LoadAsync(channel.Guild.Id); // Ban check - bool isMod = gconf.ModeratorRole.HasValue && author.Roles.Any(r => r.Id == gconf.ModeratorRole.Value); - if (!isMod) // skip check if user is a moderator + if (!gconf.IsBotModerator(author)) // skip check if user is a moderator { if (await gconf.IsUserBlockedAsync(author.Id)) return; // silently ignore } diff --git a/Data/GuildConfiguration.cs b/Data/GuildConfiguration.cs index 1f35645..b84487a 100644 --- a/Data/GuildConfiguration.cs +++ b/Data/GuildConfiguration.cs @@ -1,7 +1,9 @@ -using Npgsql; +using Discord.WebSocket; +using Npgsql; using NpgsqlTypes; using System; using System.Data.Common; +using System.Linq; using System.Threading.Tasks; namespace BirthdayBot.Data @@ -128,6 +130,13 @@ namespace BirthdayBot.Data return result != 0; } + /// + /// Checks if the given user can be considered a bot moderator. + /// Checks for either the Manage Guild permission or if the user is within a predetermined role. + /// + public bool IsBotModerator(SocketGuildUser user) + => user.GuildPermissions.ManageGuild || (ModeratorRole.HasValue && user.Roles.Any(r => r.Id == ModeratorRole.Value)); + #region Database public const string BackingTable = "settings"; public const string BackingTableBans = "banned_users";