Skip to content

Commit 9f79324

Browse files
committed
Check for the new ServerAdmin module in the help commands.
Use SocketRole instead of getting a role by its name in AdminRole and ModRole.
1 parent 744a5a6 commit 9f79324

File tree

5 files changed

+12
-19
lines changed

5 files changed

+12
-19
lines changed

Volte/Core/Commands/Modules/Admin/AdminRoleCommand.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Linq;
22
using System.Threading.Tasks;
33
using Discord;
4+
using Discord.WebSocket;
45
using Qmmands;
56
using Volte.Core.Commands.Preconditions;
67
using Volte.Core.Extensions;
@@ -11,23 +12,18 @@ public partial class AdminModule : VolteModule
1112
{
1213
[Command("AdminRole")]
1314
[Description("Sets the role able to use Admin commands for the current guild.")]
14-
[Remarks("Usage: |prefix|adminrole {roleName}")]
15+
[Remarks("Usage: |prefix|adminrole {role}")]
1516
[RequireGuildAdmin]
16-
public async Task AdminRoleAsync([Remainder] string roleName)
17+
public async Task AdminRoleAsync(SocketRole role)
1718
{
1819
var embed = Context.CreateEmbed(string.Empty).ToEmbedBuilder();
1920
var config = Db.GetConfig(Context.Guild);
20-
var role = Context.Guild.Roles.FirstOrDefault(r => r.Name.EqualsIgnoreCase(roleName));
2121
if (role != null)
2222
{
2323
config.ModerationOptions.AdminRole = role.Id;
2424
Db.UpdateConfig(config);
2525
embed.WithDescription($"Set **{role.Name}** as the Admin role for this server.");
2626
}
27-
else
28-
{
29-
embed.WithDescription($"**{roleName}** doesn't exist in this server.");
30-
}
3127

3228
await embed.SendTo(Context.Channel);
3329
}

Volte/Core/Commands/Modules/Admin/ModRoleCommand.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Linq;
22
using System.Threading.Tasks;
3+
using Discord.WebSocket;
34
using Qmmands;
45
using Volte.Core.Commands.Preconditions;
56
using Volte.Core.Extensions;
@@ -10,17 +11,12 @@ public partial class AdminModule : VolteModule
1011
{
1112
[Command("ModRole")]
1213
[Description("Sets the role able to use Moderation commands for the current guild.")]
13-
[Remarks("Usage: |prefix|modrole {roleName}")]
14+
[Remarks("Usage: |prefix|modrole {role}")]
1415
[RequireGuildAdmin]
15-
public async Task ModRoleAsync([Remainder] string roleName)
16+
public async Task ModRoleAsync(SocketRole role)
1617
{
1718
var config = Db.GetConfig(Context.Guild);
18-
var role = Context.Guild.Roles.FirstOrDefault(r => r.Name.EqualsIgnoreCase(roleName));
19-
if (role is null)
20-
{
21-
await Context.CreateEmbed($"{roleName} doesn't exist in this server.").SendTo(Context.Channel);
22-
}
23-
else
19+
if (role != null)
2420
{
2521
config.ModerationOptions.ModRole = role.Id;
2622
Db.UpdateConfig(config);

Volte/Core/Commands/Modules/Help/CommandCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public async Task CommandAsync([Remainder] string cmdName)
2222

2323
if ((c.Module.SanitizeName().EqualsIgnoreCase("admin") && !UserUtil.IsAdmin(Context)) ||
2424
(c.Module.SanitizeName().EqualsIgnoreCase("owner") && !UserUtil.IsBotOwner(Context.User)) ||
25-
(c.Module.SanitizeName().EqualsIgnoreCase("moderation") && !UserUtil.IsModerator(Context)))
25+
(c.Module.SanitizeName().EqualsIgnoreCase("moderation") && !UserUtil.IsModerator(Context)) ||
26+
(c.Module.SanitizeName().EqualsIgnoreCase("serveradmin") && !UserUtil.IsAdmin(Context)))
2627
{
2728
await Context.CreateEmbed($"{EmojiService.X} You don't have permission to use the module that command is from.")
2829
.SendTo(Context.Channel);

Volte/Core/Commands/Modules/Help/CommandsCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public async Task CommandsAsync(string module)
2222

2323
if ((target.SanitizeName().EqualsIgnoreCase("admin") && !UserUtil.IsAdmin(Context)) ||
2424
(target.SanitizeName().EqualsIgnoreCase("owner") && !UserUtil.IsBotOwner(Context.User)) ||
25-
(target.SanitizeName().EqualsIgnoreCase("moderation") && !UserUtil.IsModerator(Context)))
25+
(target.SanitizeName().EqualsIgnoreCase("moderation") && !UserUtil.IsModerator(Context)) ||
26+
(target.SanitizeName().EqualsIgnoreCase("serveradmin") && !UserUtil.IsAdmin(Context)))
2627
{
2728
await Context.CreateEmbed($"{EmojiService.X} You don't have permission to use the module that command is from.")
2829
.SendTo(Context.Channel);

Volte/Core/Commands/Modules/Help/ModulesCommand.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ public partial class HelpModule : VolteModule
1212
[Remarks("Usage: |prefix|modules")]
1313
public async Task ModulesAsync()
1414
{
15-
var modules = CommandService.GetAllModules().Aggregate(string.Empty,
16-
(current, module) => current + $"`{module.SanitizeName()}`, ");
15+
var modules = $"`{string.Join("`, `", CommandService.GetAllModules().Select(x => x.SanitizeName()))}`";
1716
await Context.CreateEmbedBuilder(modules.Remove(modules.LastIndexOf(","))).WithTitle("Available Modules")
1817
.SendTo(Context.Channel);
1918
}

0 commit comments

Comments
 (0)