Skip to content

Commit

Permalink
Shows the preconditions of the command
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasAunvik committed Jun 11, 2020
1 parent d944b45 commit a5e5e5c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
10 changes: 2 additions & 8 deletions AnimeListBot/Modules/AutoAdder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ public async Task RemoveChannel()
await embed.SendMessage(Context.Channel);
}

[RequireUserPermission(GuildPermission.ManageRoles)]
[Command("autolistupdate")]
[RequireUserPermission(GuildPermission.ManageRoles, Group = "Admin")]
[RequireOwner(Group = "Admin")]
public async Task AutoListUpdate()
{
DiscordServer server = await _db.GetServerById(Context.Guild.Id);
Expand Down Expand Up @@ -117,13 +118,6 @@ public async Task AutoListUpdate()
await embed.UpdateEmbed();
}

[RequireOwner]
[Command("autolistupdate")]
public async Task AutoListUpdateOwner()
{
await AutoListUpdate();
}

[Command("autolistchannel")]
public async Task GetAutoMalChannel()
{
Expand Down
51 changes: 41 additions & 10 deletions AnimeListBot/Modules/HelpModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
using Discord.Commands;
using Discord.WebSocket;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;

namespace AnimeListBot.Modules
Expand Down Expand Up @@ -81,6 +83,43 @@ public static EmbedHandler GetCommandHelp(string command, ICommandContext contex
$"{cmd.Remarks}";
x.IsInline = false;
});

if (cmd.Preconditions.Count > 0)
{
List<PreconditionAttribute> preconditions = cmd.Preconditions.ToList();
List<PreconditionAttribute> sameGroup = new List<PreconditionAttribute>();
string preconditionString = string.Empty;
for (int i = 0; i < preconditions.Count; i++)
{
PreconditionAttribute attrib = cmd.Preconditions[i];
var same = preconditions.FindAll(x => x.Group == attrib.Group && x.Group != null);
if (same.Count != 0)
{
sameGroup.AddRange(same);
i += same.Count - 1;
}
else sameGroup.Add(attrib);

preconditionString += string.Join("\n**Or**\n", sameGroup.Select(x =>
{
if (x is RequireUserPermissionAttribute userPerm) return userPerm.ChannelPermission != null ? ("User Channel Permission: " + userPerm.ChannelPermission.ToString()) : ("User Guild Permission: " + userPerm.GuildPermission.ToString());
if (x is RequireBotPermissionAttribute botPerm) return botPerm.ChannelPermission != null ? ("Bot Channel Permission: " + botPerm.ChannelPermission.ToString()) : ("Bot Guild Permission: " + botPerm.GuildPermission.ToString());
if (x is RequireValidAnimelistAttribute) return "Valid Animelist Profile";
if (x is RequireOwnerAttribute) return "Bot Owner Permission";
return x.GetType().Name;
})
) + "\n";

sameGroup = new List<PreconditionAttribute>();
}

builder.AddField(x =>
{
x.Name = "Preconditions";
x.Value = preconditionString;
x.IsInline = false;
});
}
}
if (builder.Fields.Count <= 0)
{
Expand Down Expand Up @@ -205,20 +244,12 @@ public async Task GitStatus()
}

[Command("prefix")]
[RequireUserPermission(GuildPermission.Administrator, Group = "Admin")]
[RequireOwner(Group = "Admin")]
public async Task Prefix(string newPrefix = "")
{
EmbedHandler embed = new EmbedHandler(Context.User);
DiscordServer server = await _db.GetServerById(Context.Guild.Id);

IGuildUser user = Context.Guild.GetUser(Context.User.Id);
if (!user.GuildPermissions.Administrator)
{
if (!Program.botOwners.Contains(Context.User.Id))
{
newPrefix = string.Empty;
}
}

if (string.IsNullOrEmpty(newPrefix))
{
embed.Title = "Current Prefix";
Expand Down

0 comments on commit a5e5e5c

Please sign in to comment.