From aebc63358d5f909465ba9dc8622608b467db72c9 Mon Sep 17 00:00:00 2001 From: Noi Date: Wed, 30 Mar 2022 11:49:25 -0700 Subject: [PATCH] Check against configuring 'everyone' role --- ApplicationCommands/ConfigModule.cs | 10 +++++++++- BackgroundServices/BirthdayRoleUpdate.cs | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ApplicationCommands/ConfigModule.cs b/ApplicationCommands/ConfigModule.cs index dd8e61f..715c8b3 100644 --- a/ApplicationCommands/ConfigModule.cs +++ b/ApplicationCommands/ConfigModule.cs @@ -122,13 +122,21 @@ public class ConfigModule : BotModuleBase { [Group("role", HelpPfxModOnly + HelpCmdRole)] public class SubCmdsConfigRole : BotModuleBase { [SlashCommand("set-birthday-role", HelpPfxModOnly + "Set the role given to users having a birthday.")] - public async Task CmdSetBRole([Summary(description: HelpOptRole)] SocketRole role) { + public async Task CmdSetBRole([Summary(description: HelpOptRole)]SocketRole role) { + if (role.IsEveryone || role.IsManaged) { + await RespondAsync(":x: This role cannot be used for this setting.", ephemeral: true); + return; + } await DoDatabaseUpdate(Context, s => s.RoleId = (long)role.Id); await RespondAsync($":white_check_mark: The birthday role has been set to **{role.Name}**.").ConfigureAwait(false); } [SlashCommand("set-moderator-role", HelpPfxModOnly + "Designate a role whose members can configure the bot." + HelpPofxBlankUnset)] public async Task CmdSetModRole([Summary(description: HelpOptRole)]SocketRole? role = null) { + if (role != null && (role.IsEveryone || role.IsManaged)) { + await RespondAsync(":x: This role cannot be used for this setting.", ephemeral: true); + return; + } await DoDatabaseUpdate(Context, s => s.ModeratorRole = (long?)role?.Id); await RespondAsync(":white_check_mark: The moderator role has been " + (role == null ? "unset." : $"set to **{role.Name}**.")); diff --git a/BackgroundServices/BirthdayRoleUpdate.cs b/BackgroundServices/BirthdayRoleUpdate.cs index cf847ea..4bf4f06 100644 --- a/BackgroundServices/BirthdayRoleUpdate.cs +++ b/BackgroundServices/BirthdayRoleUpdate.cs @@ -40,6 +40,13 @@ class BirthdayRoleUpdate : BackgroundService { if (role == null || !guild.CurrentUser.GuildPermissions.ManageRoles || role.Position >= guild.CurrentUser.Hierarchy) continue; + if (role.IsEveryone || role.IsManaged) { + // Invalid role was configured. Clear the setting and quit. + settings.RoleId = null; + db.Update(settings); + await db.SaveChangesAsync(); + continue; + } // Load up user configs and begin processing birthdays await db.Entry(settings).Collection(t => t.UserEntries).LoadAsync(CancellationToken.None);