Removed UI and Added IsDisabled plugin property
This commit is contained in:
@@ -48,7 +48,7 @@ namespace DiscordBot.Bot.Actions
|
||||
}
|
||||
|
||||
FileInfo fileInfo = new FileInfo(path);
|
||||
PluginInfo pluginInfo = new PluginInfo(args[0], new(1, 0, 0), [], false, true);
|
||||
PluginInfo pluginInfo = new PluginInfo(args[0], new(1, 0, 0), [], false, true, false);
|
||||
await Application.CurrentApplication.PluginManager.AppendPluginToDatabase(pluginInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
||||
using DiscordBot.Utilities;
|
||||
|
||||
using DiscordBotCore;
|
||||
using DiscordBotCore.Interfaces.PluginManager;
|
||||
using DiscordBotCore.Loaders;
|
||||
using DiscordBotCore.Online;
|
||||
using DiscordBotCore.Others;
|
||||
@@ -19,15 +20,17 @@ namespace DiscordBot.Bot.Actions.Extra;
|
||||
internal static class PluginMethods
|
||||
{
|
||||
|
||||
internal static async Task List(PluginManager manager)
|
||||
internal static async Task List()
|
||||
{
|
||||
Console.WriteLine($"Fetching plugin list from branch {manager.Branch} ...");
|
||||
|
||||
var data = await ConsoleUtilities.ExecuteWithProgressBar(manager.GetPluginsList(), "Reading remote database");
|
||||
|
||||
Console.WriteLine($"Fetching plugin list from branch {Application.CurrentApplication.PluginManager.Branch} ...");
|
||||
|
||||
var data = await ConsoleUtilities.ExecuteWithProgressBar(Application.CurrentApplication.PluginManager.GetPluginsList(), "Reading remote database");
|
||||
|
||||
TableData tableData = new(["Name", "Description", "Version", "Is Installed", "Dependencies"]);
|
||||
|
||||
var installedPlugins = await ConsoleUtilities.ExecuteWithProgressBar(manager.GetInstalledPlugins(), "Reading local database ");
|
||||
var installedPlugins = await ConsoleUtilities.ExecuteWithProgressBar(Application.CurrentApplication.PluginManager.GetInstalledPlugins(), "Reading local database ");
|
||||
|
||||
foreach (var plugin in data)
|
||||
{
|
||||
@@ -87,9 +90,19 @@ internal static class PluginMethods
|
||||
|
||||
}
|
||||
|
||||
internal static async Task DownloadPlugin(PluginManager manager, string pluginName)
|
||||
internal static async Task DisablePlugin(string pluginName)
|
||||
{
|
||||
var pluginData = await manager.GetPluginDataByName(pluginName);
|
||||
await Application.CurrentApplication.PluginManager.SetDisabledStatus(pluginName, true);
|
||||
}
|
||||
|
||||
internal static async Task EnablePlugin(string pluginName)
|
||||
{
|
||||
await Application.CurrentApplication.PluginManager.SetDisabledStatus(pluginName, false);
|
||||
}
|
||||
|
||||
internal static async Task DownloadPlugin(string pluginName)
|
||||
{
|
||||
var pluginData = await Application.CurrentApplication.PluginManager.GetPluginDataByName(pluginName);
|
||||
if (pluginData is null)
|
||||
{
|
||||
Console.WriteLine($"Plugin {pluginName} not found. Please check the spelling and try again.");
|
||||
@@ -127,12 +140,12 @@ internal static class PluginMethods
|
||||
if (pluginData.HasScriptDependencies)
|
||||
{
|
||||
Console.WriteLine("Executing post install scripts ...");
|
||||
await manager.ExecutePluginInstallScripts(pluginData.ScriptDependencies);
|
||||
await Application.CurrentApplication.PluginManager.ExecutePluginInstallScripts(pluginData.ScriptDependencies);
|
||||
}
|
||||
|
||||
PluginInfo pluginInfo = new(pluginName, pluginData.Version, []);
|
||||
Console.WriteLine("Finished installing " + pluginName + " successfully");
|
||||
await manager.AppendPluginToDatabase(pluginInfo);
|
||||
await Application.CurrentApplication.PluginManager.AppendPluginToDatabase(pluginInfo);
|
||||
await RefreshPlugins(false);
|
||||
return;
|
||||
}
|
||||
@@ -175,7 +188,7 @@ internal static class PluginMethods
|
||||
await Parallel.ForEachAsync(downloadTasks, options, async (tuple, token) =>
|
||||
{
|
||||
tuple.Item1.IsIndeterminate = false;
|
||||
string downloadLocation = manager.GenerateDependencyLocation(pluginName, tuple.Item4);
|
||||
string downloadLocation = Application.CurrentApplication.PluginManager.GenerateDependencyLocation(pluginName, tuple.Item4);
|
||||
await ServerCom.DownloadFileAsync(tuple.Item3, downloadLocation, tuple.Item2);
|
||||
}
|
||||
);
|
||||
@@ -189,10 +202,10 @@ internal static class PluginMethods
|
||||
if(pluginData.HasScriptDependencies)
|
||||
{
|
||||
Console.WriteLine("Executing post install scripts ...");
|
||||
await manager.ExecutePluginInstallScripts(pluginData.ScriptDependencies);
|
||||
await Application.CurrentApplication.PluginManager.ExecutePluginInstallScripts(pluginData.ScriptDependencies);
|
||||
}
|
||||
|
||||
await manager.AppendPluginToDatabase(PluginInfo.FromOnlineInfo(pluginData));
|
||||
await Application.CurrentApplication.PluginManager.AppendPluginToDatabase(PluginInfo.FromOnlineInfo(pluginData));
|
||||
await RefreshPlugins(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,12 @@ public class Plugin: ICommandAction
|
||||
new InternalActionOption("branch", "Sets a plugin option", [
|
||||
new InternalActionOption("set", "Sets the branch"),
|
||||
new InternalActionOption("get", "Gets the branch")
|
||||
]),
|
||||
new InternalActionOption("enable", "Enables a plugin", [
|
||||
new InternalActionOption("name", "The name of the plugin to enable")
|
||||
]),
|
||||
new InternalActionOption("disable", "Disables a plugin", [
|
||||
new InternalActionOption("name", "The name of the plugin to disable")
|
||||
])
|
||||
};
|
||||
|
||||
@@ -36,20 +42,40 @@ public class Plugin: ICommandAction
|
||||
|
||||
public async Task Execute(string[] args)
|
||||
{
|
||||
if (args is null || args.Length == 0 || args[0] == "help")
|
||||
if (args is null || args.Length == 0)
|
||||
{
|
||||
Console.WriteLine("Usage : plugin [help|list|load|install]");
|
||||
Console.WriteLine("help : Displays this message");
|
||||
Console.WriteLine("list : Lists all plugins");
|
||||
Console.WriteLine("load : Loads all plugins");
|
||||
Console.WriteLine("install : Installs a plugin");
|
||||
Console.WriteLine("refresh : Refreshes the plugin list");
|
||||
|
||||
await Application.CurrentApplication.InternalActionManager.Execute("help", ActionName);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args[0])
|
||||
{
|
||||
case "enable":
|
||||
{
|
||||
if (args.Length < 2)
|
||||
{
|
||||
Console.WriteLine("Usage : plugin enable <plugin name>");
|
||||
return;
|
||||
}
|
||||
|
||||
string pluginName = string.Join(' ', args, 1, args.Length - 1);
|
||||
await Application.CurrentApplication.PluginManager.SetDisabledStatus(pluginName, false);
|
||||
|
||||
break;
|
||||
}
|
||||
case "disable":
|
||||
{
|
||||
if (args.Length < 2)
|
||||
{
|
||||
Console.WriteLine("Usage : plugin disable <plugin name>");
|
||||
return;
|
||||
}
|
||||
|
||||
string pluginName = string.Join(' ', args, 1, args.Length - 1);
|
||||
await Application.CurrentApplication.PluginManager.SetDisabledStatus(pluginName, true);
|
||||
|
||||
break;
|
||||
}
|
||||
case "branch":
|
||||
if (args.Length < 2)
|
||||
{
|
||||
@@ -87,14 +113,15 @@ public class Plugin: ICommandAction
|
||||
break;
|
||||
|
||||
case "uninstall":
|
||||
string plugName = string.Join(' ', args, 1, args.Length-1);
|
||||
{
|
||||
string plugName = string.Join(' ', args, 1, args.Length - 1);
|
||||
bool result = await Application.CurrentApplication.PluginManager.MarkPluginToUninstall(plugName);
|
||||
if(result)
|
||||
if (result)
|
||||
Console.WriteLine($"Marked to uninstall plugin {plugName}. Please restart the bot");
|
||||
break;
|
||||
|
||||
}
|
||||
case "list":
|
||||
await PluginMethods.List(Application.CurrentApplication.PluginManager);
|
||||
await PluginMethods.List();
|
||||
break;
|
||||
case "load":
|
||||
if (pluginsLoaded)
|
||||
@@ -113,6 +140,7 @@ public class Plugin: ICommandAction
|
||||
break;
|
||||
|
||||
case "install":
|
||||
{
|
||||
var pluginName = string.Join(' ', args, 1, args.Length - 1);
|
||||
if (string.IsNullOrEmpty(pluginName) || pluginName.Length < 2)
|
||||
{
|
||||
@@ -126,8 +154,10 @@ public class Plugin: ICommandAction
|
||||
}
|
||||
}
|
||||
|
||||
await PluginMethods.DownloadPlugin(Application.CurrentApplication.PluginManager, pluginName);
|
||||
await PluginMethods.DownloadPlugin(pluginName);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user