mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-11-21 21:54:36 +00:00
Check against configuring 'everyone' role
This commit is contained in:
parent
586c11d540
commit
aebc63358d
2 changed files with 16 additions and 1 deletions
|
@ -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}**."));
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue