Actions are now loaded together with all plugins. Called the LoadPlugins at startup
This commit is contained in:
@@ -40,8 +40,9 @@ internal static class PluginMethods
|
||||
|
||||
internal static async Task RefreshPlugins(bool quiet)
|
||||
{
|
||||
await Application.CurrentApplication.InternalActionManager.Execute("plugin", "load", quiet ? "-q" : string.Empty);
|
||||
await Application.CurrentApplication.InternalActionManager.Refresh();
|
||||
|
||||
await LoadPlugins(quiet ? ["-q"] : null);
|
||||
await Application.CurrentApplication.InternalActionManager.Initialize();
|
||||
}
|
||||
|
||||
internal static async Task DownloadPlugin(PluginManager manager, string pluginName)
|
||||
@@ -156,7 +157,7 @@ internal static class PluginMethods
|
||||
internal static async Task<bool> LoadPlugins(string[] args)
|
||||
{
|
||||
var loader = new PluginLoader(Application.CurrentApplication.DiscordBotClient.Client);
|
||||
if (args.Length == 2 && args[1] == "-q")
|
||||
if (args != null && (args.Length == 2 && args[1] == "-q"))
|
||||
{
|
||||
await loader.LoadPlugins();
|
||||
return true;
|
||||
@@ -211,6 +212,22 @@ internal static class PluginMethods
|
||||
Console.ForegroundColor = cc;
|
||||
};
|
||||
|
||||
loader.OnActionLoaded += (data) =>
|
||||
{
|
||||
if (data.IsSuccess)
|
||||
{
|
||||
Application.CurrentApplication.Logger.Log("Successfully loaded action : " + data.PluginName, LogType.INFO, "\t\t > {Message}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Application.CurrentApplication.Logger.Log("Failed to load action : " + data.PluginName + " because " + data.ErrorMessage,
|
||||
typeof(PluginMethods), LogType.ERROR
|
||||
);
|
||||
}
|
||||
|
||||
Console.ForegroundColor = cc;
|
||||
};
|
||||
|
||||
await loader.LoadPlugins();
|
||||
Console.ForegroundColor = cc;
|
||||
return true;
|
||||
|
||||
@@ -38,15 +38,15 @@ public class Help: ICommandAction
|
||||
|
||||
tableData.Columns = ["Command", "Usage", "Description", "Options"];
|
||||
|
||||
foreach (var a in Application.CurrentApplication.InternalActionManager.Actions)
|
||||
foreach (var a in Application.CurrentApplication.InternalActionManager.GetActions())
|
||||
{
|
||||
Markup actionName = new Markup($"[bold]{a.Key}[/]");
|
||||
Markup usage = new Markup($"[italic]{a.Value.Usage}[/]");
|
||||
Markup description = new Markup($"[dim]{a.Value.Description}[/]");
|
||||
Markup actionName = new Markup($"[bold]{a.ActionName}[/]");
|
||||
Markup usage = new Markup($"[italic]{a.Usage}[/]");
|
||||
Markup description = new Markup($"[dim]{a.Description}[/]");
|
||||
|
||||
if (a.Value.ListOfOptions.Any())
|
||||
if (a.ListOfOptions.Any())
|
||||
{
|
||||
tableData.AddRow([actionName, usage, description, CreateTableWithSubOptions(a.Value.ListOfOptions)]);
|
||||
tableData.AddRow([actionName, usage, description, CreateTableWithSubOptions(a.ListOfOptions)]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -64,13 +64,13 @@ public class Help: ICommandAction
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Application.CurrentApplication.InternalActionManager.Actions.ContainsKey(args[0]))
|
||||
if (!Application.CurrentApplication.InternalActionManager.Exists(args[0]))
|
||||
{
|
||||
Console.WriteLine("Command not found");
|
||||
return;
|
||||
}
|
||||
|
||||
var action = Application.CurrentApplication.InternalActionManager.Actions[args[0]];
|
||||
var action = Application.CurrentApplication.InternalActionManager.GetAction(args[0]);
|
||||
tableData.Columns = ["Command", "Usage", "Description"];
|
||||
tableData.AddRow([action.ActionName, action.Usage, action.Description]);
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Discord;
|
||||
@@ -31,7 +32,11 @@ public class Help: DBSlashCommand
|
||||
EmbedBuilder embedBuilder = new();
|
||||
|
||||
embedBuilder.WithTitle("Help Command");
|
||||
embedBuilder.WithColor(Functions.RandomColor);
|
||||
|
||||
var random = new Random();
|
||||
Color c = new Color(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255));
|
||||
|
||||
embedBuilder.WithColor(c);
|
||||
var slashCommands = PluginLoader.SlashCommands;
|
||||
var options = context.Data.Options;
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using DiscordBot.Bot.Actions.Extra;
|
||||
|
||||
using DiscordBotCore;
|
||||
using DiscordBotCore.Bot;
|
||||
using DiscordBotCore.Others;
|
||||
@@ -22,6 +24,8 @@ public class Program
|
||||
{
|
||||
await LoadComponents(args);
|
||||
await PrepareConsole();
|
||||
await PluginMethods.LoadPlugins(null);
|
||||
await Application.CurrentApplication.InternalActionManager.Initialize();
|
||||
await ConsoleInputHandler();
|
||||
}
|
||||
|
||||
@@ -30,7 +34,6 @@ public class Program
|
||||
/// </summary>
|
||||
private static async Task ConsoleInputHandler()
|
||||
{
|
||||
await Application.CurrentApplication.InternalActionManager.Execute("plugin", "load");
|
||||
|
||||
while (true)
|
||||
{
|
||||
@@ -65,7 +68,7 @@ public class Program
|
||||
{
|
||||
var token = Application.CurrentApplication.ApplicationEnvironmentVariables["token"];
|
||||
var prefix = Application.CurrentApplication.ApplicationEnvironmentVariables["prefix"];
|
||||
var discordbooter = new Boot(token, prefix);
|
||||
var discordbooter = new App(token, prefix);
|
||||
await discordbooter.Awake();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -118,6 +121,8 @@ public class Program
|
||||
!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("token") ||
|
||||
!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("prefix"))
|
||||
await Installer.GenerateStartupConfig();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user