diff --git a/BUILDS/net6.0/PluginManager.dll b/BUILDS/net6.0/PluginManager.dll index 030162f..110653e 100644 Binary files a/BUILDS/net6.0/PluginManager.dll and b/BUILDS/net6.0/PluginManager.dll differ diff --git a/DiscordBot/DiscordBot.csproj b/DiscordBot/DiscordBot.csproj index adc235a..5aa59c2 100644 --- a/DiscordBot/DiscordBot.csproj +++ b/DiscordBot/DiscordBot.csproj @@ -8,7 +8,7 @@ False True - 1.0.0.2 + 1.0.0.3 diff --git a/DiscordBot/Program.cs b/DiscordBot/Program.cs index 77f2207..3383372 100644 --- a/DiscordBot/Program.cs +++ b/DiscordBot/Program.cs @@ -19,6 +19,7 @@ public class Program { private static bool loadPluginsOnStartup; private static bool listPluginsAtStartup; + private static ConsoleCommandsHandler consoleCommandsHandler; /// /// The main entry point for the application. @@ -33,6 +34,7 @@ public class Program Directory.CreateDirectory("./Data/Plugins/Events"); PreLoadComponents().Wait(); + if (!Config.ContainsKey("ServerID")) { do @@ -105,7 +107,7 @@ public class Program /// The discord booter used to start the application private static void NoGUI(Boot discordbooter) { - var consoleCommandsHandler = new ConsoleCommandsHandler(discordbooter.client); + #if DEBUG Console.WriteLine(); consoleCommandsHandler.HandleCommand("lp"); @@ -118,10 +120,11 @@ public class Program { //Console_Utilities.WriteColorText("&rSethBot (&yDEBUG&r) &c> ", false); var cmd = Console.ReadLine(); - if (!consoleCommandsHandler.HandleCommand(cmd!, + if (!consoleCommandsHandler.HandleCommand(cmd! #if DEBUG - false + , false #endif + ) && cmd.Length > 0) Console.WriteLine("Failed to run command " + cmd); } @@ -199,8 +202,11 @@ public class Program /// The arguments private static async Task HandleInput(string[] args) { + var b = await StartNoGUI(); + consoleCommandsHandler = new ConsoleCommandsHandler(b.client); var len = args.Length; + if (len == 3 && args[0] == "/download") { var url = args[1]; @@ -211,6 +217,17 @@ public class Program return; } + if (len > 0 && args[0] == "/remplug") + { + + string plugName = Functions.MergeStrings(args, 1); + Console.WriteLine("Starting to remove " + plugName); + await ConsoleCommandsHandler.ExecuteCommad("remplug " + plugName); + loadPluginsOnStartup = true; + len = 0; + } + + if (len > 0 && (args.Contains("--cmd") || args.Contains("--args") || args.Contains("--nomessage"))) { if (args.Contains("lp") || args.Contains("loadplugins")) @@ -222,10 +239,10 @@ public class Program } + + if (len == 0 || (args[0] != "--exec" && args[0] != "--execute")) { - var b = await StartNoGUI(); - Thread mainThread = new Thread(() => NoGUI(b)); mainThread.Start(); return; diff --git a/PluginManager/Items/ConsoleCommandsHandler.cs b/PluginManager/Items/ConsoleCommandsHandler.cs index 8c67892..a25ac76 100644 --- a/PluginManager/Items/ConsoleCommandsHandler.cs +++ b/PluginManager/Items/ConsoleCommandsHandler.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Net.Http; @@ -168,6 +169,7 @@ public class ConsoleCommandsHandler continue; var split = line.Split(','); Console.WriteLine($"\nDownloading item: {split[1]}"); + if (File.Exists("./" + split[1])) File.Delete("./" + split[1]); await ServerCom.DownloadFileAsync(split[0], "./" + split[1]); Console.WriteLine(); @@ -294,6 +296,80 @@ public class ConsoleCommandsHandler } }); + AddCommand("remplug", "Remove a plugin", "remplug [plugName]", async args => + { + isDownloading = true; + if (args.Length <= 1) return; + string plugName = Functions.MergeStrings(args, 1); + if (pluginsLoaded) + { + if (Functions.GetOperatingSystem() == Others.OperatingSystem.WINDOWS) + { + Process.Start("DiscordBot.exe ", $"/remplug {plugName}"); + Environment.Exit(0); + } + else + { + Process.Start("./DiscordBot", $"/remplug {plugName}"); + Environment.Exit(0); + } + isDownloading = false; + return; + } + + + string location = "./Data/Plugins/"; + + location = Config.PluginConfig.GetPluginType(plugName) switch + { + PluginType.Command => location + "Commands/" + plugName + "." + PluginLoader.pluginCMDExtension, + PluginType.Event => location + "Events/" + plugName + "." + PluginLoader.pluginEVEExtension, + PluginType.Unknown => "./", + _ => throw new NotImplementedException("Plugin type incorrect") + }; + + if (!File.Exists(location)) + { + Console.WriteLine("The plugig does not exist"); + return; + } + + File.Delete(location); + if (Config.PluginConfig.Contains(plugName)) + { + var tuple = Config.PluginConfig.InstalledPlugins.Where(t => t.Item1 == plugName).FirstOrDefault(); + Console.WriteLine("Found: " + tuple.ToString()); + Config.PluginConfig.InstalledPlugins.Remove(tuple); + Config.RemovePluginVersion(plugName); + Config.SaveConfig(); + } + Console.WriteLine("Removed the plugin DLL. Checking for other files ..."); + + var info = await manager.GetPluginLinkByName(plugName); + if (info[2] != string.Empty) + { + var lines = await ServerCom.ReadTextFromURL(info[2]); + foreach (var line in lines) + { + if (!(line.Length > 0 && line.Contains(","))) + continue; + var split = line.Split(','); + if (File.Exists("./" + split[1])) + File.Delete("./" + split[1]); + + + Console.WriteLine("Removed: " + split[1]); + } + + + if (Directory.Exists(plugName)) + Directory.Delete(plugName, true); + } + isDownloading = false; + Console.WriteLine(plugName + " has been successfully deleted !"); + + }); + //Sort the commands by name commandList.Sort((x, y) => x.CommandName.CompareTo(y.CommandName)); } @@ -325,9 +401,10 @@ public class ConsoleCommandsHandler return commandList.FirstOrDefault(t => t.CommandName == command); } - internal static async Task ExecuteCommad(string command) + public static async Task ExecuteCommad(string command) { var args = command.Split(' '); + // Console.WriteLine(command); foreach (var item in commandList.ToList()) if (item.CommandName == args[0]) { diff --git a/PluginManager/Others/Functions.cs b/PluginManager/Others/Functions.cs index 8039902..a99bc7f 100644 --- a/PluginManager/Others/Functions.cs +++ b/PluginManager/Others/Functions.cs @@ -26,12 +26,12 @@ namespace PluginManager.Others /// /// The location for all logs /// - public static readonly string logFolder = @"./Output/Logs/"; + public static readonly string logFolder = @"./Data/Output/Logs/"; /// /// The location for all errors /// - public static readonly string errFolder = @"./Output/Errors/"; + public static readonly string errFolder = @"./Data/Output/Errors/"; /// /// Archives folder