using System; using System.Collections.Generic; using System.Threading.Tasks; using DiscordBot.Bot.Actions.Extra; using DiscordBotCore; using DiscordBotCore.Interfaces; using DiscordBotCore.Others; using DiscordBotCore.Others.Actions; namespace DiscordBot.Bot.Actions; public class Plugin: ICommandAction { private bool pluginsLoaded; public string ActionName => "plugin"; public string Description => "Manages plugins. Use plugin help for more info."; public string Usage => "plugin "; public IEnumerable ListOfOptions => new List { new InternalActionOption("help", "Displays this message"), new InternalActionOption("list", "Lists all plugins"), new InternalActionOption("load", "Loads all plugins"), new InternalActionOption("install", "Installs a plugin", [ new InternalActionOption("name", "The name of the plugin to install") ]), new InternalActionOption("refresh", "Refreshes the plugin list"), new InternalActionOption("uninstall", "Uninstalls a plugin"), 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") ]) }; public InternalActionRunType RunType => InternalActionRunType.ON_CALL; public async Task Execute(string[] args) { if (args is null || args.Length == 0) { await Application.CurrentApplication.InternalActionManager.Execute("help", ActionName); return; } switch (args[0]) { case "enable": { if (args.Length < 2) { Console.WriteLine("Usage : plugin enable "); return; } string pluginName = string.Join(' ', args, 1, args.Length - 1); await PluginMethods.EnablePlugin(pluginName); break; } case "disable": { if (args.Length < 2) { Console.WriteLine("Usage : plugin disable "); return; } string pluginName = string.Join(' ', args, 1, args.Length - 1); await PluginMethods.DisablePlugin(pluginName); break; } case "branch": if (args.Length < 2) { Console.WriteLine("Usage : plugin branch