Added Basic UI Functionality
This commit is contained in:
90
DiscordBotUI/Bot/Commands/Help.cs
Normal file
90
DiscordBotUI/Bot/Commands/Help.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System.Collections.Generic;
|
||||
using Discord;
|
||||
using PluginManager;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Loaders;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace DiscordBotUI.Bot.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// The help command
|
||||
/// </summary>
|
||||
internal class Help: DBCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Command name
|
||||
/// </summary>
|
||||
public string Command => "help";
|
||||
|
||||
public List<string> Aliases => null;
|
||||
|
||||
/// <summary>
|
||||
/// Command Description
|
||||
/// </summary>
|
||||
public string Description => "This command allows you to check all loaded commands";
|
||||
|
||||
/// <summary>
|
||||
/// Command usage
|
||||
/// </summary>
|
||||
public string Usage => "help <command>";
|
||||
|
||||
/// <summary>
|
||||
/// Check if the command require administrator to be executed
|
||||
/// </summary>
|
||||
public bool requireAdmin => false;
|
||||
|
||||
/// <summary>
|
||||
/// The main body of the command
|
||||
/// </summary>
|
||||
/// <param name="context">The command context</param>
|
||||
public void ExecuteServer(DbCommandExecutingArguments args)
|
||||
{
|
||||
if (args.arguments is not null)
|
||||
{
|
||||
var e = GenerateHelpCommand(args.arguments[0]);
|
||||
if (e is null)
|
||||
args.context.Channel.SendMessageAsync("Unknown Command " + args.arguments[0]);
|
||||
else
|
||||
args.context.Channel.SendMessageAsync(embed: e.Build());
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var embedBuilder = new EmbedBuilder();
|
||||
|
||||
var adminCommands = "";
|
||||
var normalCommands = "";
|
||||
|
||||
foreach (var cmd in PluginLoader.Commands)
|
||||
if (cmd.requireAdmin)
|
||||
adminCommands += cmd.Command + " ";
|
||||
else
|
||||
normalCommands += cmd.Command + " ";
|
||||
|
||||
|
||||
if (adminCommands.Length > 0)
|
||||
embedBuilder.AddField("Admin Commands", adminCommands);
|
||||
if (normalCommands.Length > 0)
|
||||
embedBuilder.AddField("Normal Commands", normalCommands);
|
||||
args.context.Channel.SendMessageAsync(embed: embedBuilder.Build());
|
||||
}
|
||||
|
||||
private EmbedBuilder GenerateHelpCommand(string command)
|
||||
{
|
||||
var embedBuilder = new EmbedBuilder();
|
||||
var cmd = PluginLoader.Commands.Find(p => p.Command == command ||
|
||||
p.Aliases is not null && p.Aliases.Contains(command)
|
||||
);
|
||||
if (cmd == null) return null;
|
||||
|
||||
embedBuilder.AddField("Usage", Config.AppSettings["prefix"] + cmd.Usage);
|
||||
embedBuilder.AddField("Description", cmd.Description);
|
||||
if (cmd.Aliases is null)
|
||||
return embedBuilder;
|
||||
embedBuilder.AddField("Alias", cmd.Aliases.Count == 0 ? "-" : string.Join(", ", cmd.Aliases));
|
||||
|
||||
return embedBuilder;
|
||||
}
|
||||
}
|
||||
83
DiscordBotUI/Bot/DiscordBot.cs
Normal file
83
DiscordBotUI/Bot/DiscordBot.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using PluginManager;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Loaders;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace DiscordBotUI.Bot
|
||||
{
|
||||
internal class DiscordBot
|
||||
{
|
||||
private readonly string[] _StartArguments;
|
||||
|
||||
public DiscordBot(string[] args)
|
||||
{
|
||||
this._StartArguments = args;
|
||||
}
|
||||
|
||||
public async Task InitializeBot()
|
||||
{
|
||||
string token = Config.AppSettings["token"];
|
||||
string prefix = Config.AppSettings["prefix"];
|
||||
PluginManager.Bot.Boot discordBooter = new PluginManager.Bot.Boot(token, prefix);
|
||||
await discordBooter.Awake();
|
||||
}
|
||||
|
||||
public async Task LoadPlugins()
|
||||
{
|
||||
var loader = new PluginLoader(Config.DiscordBot.client);
|
||||
|
||||
loader.OnCommandLoaded += (data) =>
|
||||
{
|
||||
if (data.IsSuccess)
|
||||
{
|
||||
Config.Logger.Log("Successfully loaded command : " + data.PluginName, typeof(ICommandAction),
|
||||
LogType.INFO
|
||||
);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Config.Logger.Log("Failed to load command : " + data.PluginName + " because " + data.ErrorMessage,
|
||||
typeof(ICommandAction), LogType.ERROR
|
||||
);
|
||||
}
|
||||
};
|
||||
loader.OnEventLoaded += (data) =>
|
||||
{
|
||||
if (data.IsSuccess)
|
||||
{
|
||||
Config.Logger.Log("Successfully loaded event : " + data.PluginName, typeof(ICommandAction),
|
||||
LogType.INFO
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Config.Logger.Log("Failed to load event : " + data.PluginName + " because " + data.ErrorMessage,
|
||||
typeof(ICommandAction), LogType.ERROR
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
loader.OnSlashCommandLoaded += (data) =>
|
||||
{
|
||||
if (data.IsSuccess)
|
||||
{
|
||||
Config.Logger.Log("Successfully loaded slash command : " + data.PluginName, typeof(ICommandAction),
|
||||
LogType.INFO
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Config.Logger.Log("Failed to load slash command : " + data.PluginName + " because " + data.ErrorMessage,
|
||||
typeof(ICommandAction), LogType.ERROR
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
await loader.LoadPlugins();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user