using Discord;
using Discord.Commands;
using Discord.WebSocket;
using PluginManager.Loaders;
using PluginManager.Interfaces;
using PluginManager.Others.Permissions;
using PluginManager.Others;
using System.Collections.Generic;
namespace DiscordBot.Discord.Commands
{
///
/// The help command
///
internal class Help : DBCommand
{
///
/// Command name
///
public string Command => "help";
///
/// Command Description
///
public string Description => "This command allows you to check all loadded commands";
///
/// Command usage
///
public string Usage => "help";
///
/// Check if the command can be used />
///
public bool canUseDM => true;
///
/// Check if the command can be used in a server
///
public bool canUseServer => true;
///
/// Check if the command require administrator to be executed
///
public bool requireAdmin => false;
///
/// The main body of the command
///
/// The command context
/// The command message
/// The discord bot client
/// True if the message was sent from a DM channel, false otherwise
public void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
{
List args = Functions.GetArguments(message);
if (args.Count != 0)
{
foreach (var item in args)
{
var e = GenerateHelpCommand(item);
if (e != null)
context.Channel.SendMessageAsync(embed: e.Build());
else
context.Channel.SendMessageAsync("Unknown Command " + item);
}
return;
}
EmbedBuilder embedBuilder = new EmbedBuilder();
string adminCommands = "";
string normalCommands = "";
string DMCommands = "";
foreach (var cmd in PluginLoader.Plugins!)
{
if (cmd.canUseDM)
DMCommands += cmd.Command + " ";
if (cmd.requireAdmin)
adminCommands += cmd.Command + " ";
else if (cmd.canUseServer) normalCommands += cmd.Command + " ";
}
embedBuilder.AddField("Admin Commands", adminCommands);
embedBuilder.AddField("Normal Commands", normalCommands);
embedBuilder.AddField("DM Commands", DMCommands);
context.Channel.SendMessageAsync(embed: embedBuilder.Build());
}
private EmbedBuilder GenerateHelpCommand(string command)
{
EmbedBuilder embedBuilder = new EmbedBuilder();
DBCommand cmd = PluginLoader.Plugins.Find(p => p.Command == command);
if (cmd == null)
return null;
embedBuilder.AddField("Usage", cmd.Usage);
embedBuilder.AddField("Description", cmd.Description);
return embedBuilder;
}
}
}