diff --git a/DiscordBot/Bot/Actions/AddPlugin.cs b/DiscordBot/Bot/Actions/AddPlugin.cs index 04469d4..09245d9 100644 --- a/DiscordBot/Bot/Actions/AddPlugin.cs +++ b/DiscordBot/Bot/Actions/AddPlugin.cs @@ -22,7 +22,7 @@ namespace DiscordBot.Bot.Actions public string Usage => "add-plugin "; public IEnumerable ListOfOptions => [ - new InternalActionOption("path", "The path to the plugin to add") + new InternalActionOption("fileName", "The file name") ]; public InternalActionRunType RunType => InternalActionRunType.ON_CALL; @@ -32,13 +32,14 @@ namespace DiscordBot.Bot.Actions if(args.Length < 1) { Console.WriteLine("Invalid arguments given. Please use the following format:"); - Console.WriteLine("add-plugin "); - Console.WriteLine("path: The path to the plugin to add"); + Console.WriteLine("add-plugin "); + Console.WriteLine("fileName: The file name"); return; } - var path = args[0]; + string fileName = args[0] + ".dll"; + var path = Application.GetPluginFullPath(fileName); if(!System.IO.File.Exists(path)) { @@ -47,7 +48,7 @@ namespace DiscordBot.Bot.Actions } FileInfo fileInfo = new FileInfo(path); - PluginInfo pluginInfo = new PluginInfo(fileInfo.Name, new(1, 0, 0), [], false, true); + PluginInfo pluginInfo = new PluginInfo(args[0], new(1, 0, 0), [], false, true); await Application.CurrentApplication.PluginManager.AppendPluginToDatabase(pluginInfo); } } diff --git a/DiscordBot/Program.cs b/DiscordBot/Program.cs index 79cb0fb..2130b8b 100644 --- a/DiscordBot/Program.cs +++ b/DiscordBot/Program.cs @@ -105,10 +105,9 @@ public class Program _ => "[white]" }; - if (logMessage.Message.Contains('[')) + if (logMessage.Message.Contains('[') || logMessage.Message.Contains(']')) { - Console.WriteLine(logMessage.Message); - return; + logMessage.Message = logMessage.Message.Replace("[", "<").Replace("]", ">"); } string messageToPrint = $"{messageColor}{logMessage.Message}[/]"; diff --git a/DiscordBotCore/Application.cs b/DiscordBotCore/Application.cs index ff8e7df..14aa8f5 100644 --- a/DiscordBotCore/Application.cs +++ b/DiscordBotCore/Application.cs @@ -111,5 +111,13 @@ namespace DiscordBotCore } public static string GetResourceFullPath() => _ResourcesFolder; + + public static string GetPluginFullPath(string path) + { + string result = Path.Combine(_PluginsFolder, path); + return result; + } + + public static string GetPluginFullPath() => _PluginsFolder; } } diff --git a/DiscordBotCore/Interfaces/ICommandAction.cs b/DiscordBotCore/Interfaces/ICommandAction.cs index 3cf979e..4709bfb 100644 --- a/DiscordBotCore/Interfaces/ICommandAction.cs +++ b/DiscordBotCore/Interfaces/ICommandAction.cs @@ -19,6 +19,4 @@ public interface ICommandAction public InternalActionRunType RunType { get; } public Task Execute(string[]? args); - - public void ExecuteStartup() { } } diff --git a/DiscordBotCore/Loaders/Loader.cs b/DiscordBotCore/Loaders/Loader.cs index f9be807..49f7bdb 100644 --- a/DiscordBotCore/Loaders/Loader.cs +++ b/DiscordBotCore/Loaders/Loader.cs @@ -67,6 +67,9 @@ internal class Loader _ => PluginType.UNKNOWN }; + if (pluginType == PluginType.UNKNOWN) + throw new Exception($"Unknown plugin type for plugin with type {type.FullName} [{type.Assembly}]"); + OnPluginLoaded?.Invoke(new PluginLoadResultData(type.FullName, pluginType, true, plugin: plugin)); } catch (Exception ex) diff --git a/DiscordBotCore/Loaders/PluginLoader.cs b/DiscordBotCore/Loaders/PluginLoader.cs index fd2a614..bac59a5 100644 --- a/DiscordBotCore/Loaders/PluginLoader.cs +++ b/DiscordBotCore/Loaders/PluginLoader.cs @@ -72,7 +72,7 @@ public class PluginLoader case PluginType.ACTION: ICommandAction action = (ICommandAction)result.Plugin; if (action.RunType == InternalActionRunType.ON_STARTUP || action.RunType == InternalActionRunType.BOTH) - action.ExecuteStartup(); + action.Execute(null); if(action.RunType == InternalActionRunType.ON_CALL || action.RunType == InternalActionRunType.BOTH) Actions.Add(action); diff --git a/DiscordBotCore/Others/Logger/LogMessage.cs b/DiscordBotCore/Others/Logger/LogMessage.cs index b98e453..b74ff92 100644 --- a/DiscordBotCore/Others/Logger/LogMessage.cs +++ b/DiscordBotCore/Others/Logger/LogMessage.cs @@ -6,6 +6,7 @@ namespace DiscordBotCore.Others.Logger { internal sealed class LogMessage : ILogMessage { + private static readonly string _DefaultLogMessageSender = "\b"; public string Message { get; set; } public DateTime ThrowTime { get; set; } public string SenderName { get; set; } @@ -22,7 +23,7 @@ namespace DiscordBotCore.Others.Logger public LogMessage(string message, object sender) { Message = message; - SenderName = sender.GetType().FullName ?? sender.GetType().Name; + SenderName = sender is string && sender as string == string.Empty ? _DefaultLogMessageSender : sender.GetType().FullName ?? sender.GetType().Name; ThrowTime = DateTime.Now; LogMessageType = LogType.INFO; } @@ -30,7 +31,7 @@ namespace DiscordBotCore.Others.Logger public LogMessage(string message, object sender, DateTime throwTime) { Message = message; - SenderName = sender.GetType().FullName ?? sender.GetType().Name; + SenderName = sender is string && sender as string == string.Empty ? _DefaultLogMessageSender : sender.GetType().FullName ?? sender.GetType().Name; ThrowTime = throwTime; LogMessageType = LogType.INFO; } @@ -38,7 +39,7 @@ namespace DiscordBotCore.Others.Logger public LogMessage(string message, object sender, LogType logMessageType) { Message = message; - SenderName = sender.GetType().FullName ?? sender.GetType().Name; + SenderName = sender is string && sender as string == string.Empty ? _DefaultLogMessageSender : sender.GetType().FullName ?? sender.GetType().Name; ThrowTime = DateTime.Now; LogMessageType = logMessageType; @@ -48,7 +49,7 @@ namespace DiscordBotCore.Others.Logger { Message = message; ThrowTime = throwTime; - SenderName = sender.GetType().FullName ?? sender.GetType().Name; + SenderName = sender is string && sender as string == string.Empty ? _DefaultLogMessageSender : sender.GetType().FullName ?? sender.GetType().Name; LogMessageType = logMessageType; } diff --git a/DiscordBotCore/Others/Logger/Logger.cs b/DiscordBotCore/Others/Logger/Logger.cs index d7f6e43..814f133 100644 --- a/DiscordBotCore/Others/Logger/Logger.cs +++ b/DiscordBotCore/Others/Logger/Logger.cs @@ -80,6 +80,7 @@ public sealed class Logger : ILogger LogToFile(messageAsString); } + public void Log(string message) => Log(new LogMessage(message, string.Empty, LogType.INFO)); public void Log(string message, LogType logType, string format) => Log(new LogMessage(message, logType), format); public void Log(string message, LogType logType) => Log(new LogMessage(message, logType)); public void Log(string message, object Sender) => Log(new LogMessage(message, Sender)); diff --git a/DiscordBotUI/Program.cs b/DiscordBotUI/Program.cs index d18134b..8a68582 100644 --- a/DiscordBotUI/Program.cs +++ b/DiscordBotUI/Program.cs @@ -23,18 +23,12 @@ namespace DiscordBotUI public InternalActionRunType RunType => InternalActionRunType.BOTH; - public async void ExecuteStartup() - { - Directory.CreateDirectory(Path.Combine(DiscordBotCore.Application.CurrentApplication.DataFolder, "DiscordBotUI")); - await Execute(["start"]); - } - public async Task Execute(string[]? args) { if (args == null || args.Length == 0) { - Console.WriteLine("Please provide an option"); - return; + Directory.CreateDirectory(Path.Combine(DiscordBotCore.Application.GetResourceFullPath(), "DiscordBotUI")); + await StartUI(); } if (args[0] == "theme") diff --git a/DiscordBotUI/ThemeManager.cs b/DiscordBotUI/ThemeManager.cs index 5e32b95..fc75a8f 100644 --- a/DiscordBotUI/ThemeManager.cs +++ b/DiscordBotUI/ThemeManager.cs @@ -85,7 +85,7 @@ namespace DiscordBotUI_Windows if (theme == null) throw new Exception("Theme not found"); - string basefolderPath = Path.Combine(DiscordBotCore.Application.CurrentApplication.DataFolder, _ThemesFolder); + string basefolderPath = DiscordBotCore.Application.GetResourceFullPath(_ThemesFolder); Directory.CreateDirectory(basefolderPath); string filePath = Path.Combine(basefolderPath, $"{themeName}.json"); await DiscordBotCore.Others.JsonManager.SaveToJsonFile(filePath, theme); @@ -93,7 +93,7 @@ namespace DiscordBotUI_Windows internal async Task LoadThemesFromThemesFolder() { - string basefolderPath = Path.Combine(DiscordBotCore.Application.CurrentApplication.DataFolder, _ThemesFolder); + string basefolderPath = DiscordBotCore.Application.GetResourceFullPath(_ThemesFolder); Directory.CreateDirectory(basefolderPath); var files = Directory.GetFiles(basefolderPath, "*.json"); _InstalledThemes.Clear(); diff --git a/SethDiscordBot.sln b/SethDiscordBot.sln index a062e99..c4b9785 100644 --- a/SethDiscordBot.sln +++ b/SethDiscordBot.sln @@ -14,6 +14,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MusicPlayer", "..\SethPlugi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LevelingSystem", "..\SethPlugins\LevelingSystem\LevelingSystem.csproj", "{39EF14F8-7E67-4C14-A4F1-E706CFF61192}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CppWrapper", "..\SethPlugins\CppWrapper\CppWrapper.csproj", "{2E526F88-368C-4BE5-9B46-69EE3D311E9B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -40,6 +42,10 @@ Global {39EF14F8-7E67-4C14-A4F1-E706CFF61192}.Debug|Any CPU.Build.0 = Debug|Any CPU {39EF14F8-7E67-4C14-A4F1-E706CFF61192}.Release|Any CPU.ActiveCfg = Release|Any CPU {39EF14F8-7E67-4C14-A4F1-E706CFF61192}.Release|Any CPU.Build.0 = Release|Any CPU + {2E526F88-368C-4BE5-9B46-69EE3D311E9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E526F88-368C-4BE5-9B46-69EE3D311E9B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E526F88-368C-4BE5-9B46-69EE3D311E9B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E526F88-368C-4BE5-9B46-69EE3D311E9B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -47,6 +53,7 @@ Global GlobalSection(NestedProjects) = preSolution {F094D29D-6F1A-46BC-8B1F-88F3D98FCA84} = {8FAEFF5E-F749-435C-BB7B-D57C0F8B17FC} {39EF14F8-7E67-4C14-A4F1-E706CFF61192} = {8FAEFF5E-F749-435C-BB7B-D57C0F8B17FC} + {2E526F88-368C-4BE5-9B46-69EE3D311E9B} = {8FAEFF5E-F749-435C-BB7B-D57C0F8B17FC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3FB3C5DE-ED21-4D2E-ABDD-3A00EE4A2FFF}