From 196fb6d3d1c01161a75ae5cfae539c459a3404a1 Mon Sep 17 00:00:00 2001 From: Andrei Tudor Date: Sat, 24 Feb 2024 23:22:02 +0200 Subject: [PATCH] Code formatting and renamed DBCommandExecutingArguments to DbCommandExecutingArguments --- DiscordBot/Bot/Actions/Extra/PluginMethods.cs | 4 +- .../Bot/Commands/NormalCommands/Help.cs | 2 +- DiscordBot/Program.cs | 2 +- PluginManager/Bot/CommandHandler.cs | 2 +- PluginManager/Config.cs | 1 - PluginManager/Interfaces/DBCommand.cs | 4 +- .../{IInternalAction.cs => ICommandAction.cs} | 0 PluginManager/Online/PluginsManager.cs | 12 ++--- .../Others/DBCommandExecutingArguments.cs | 11 ++--- PluginManager/Others/Enums.cs | 17 ------- PluginManager/Others/Functions.cs | 12 ----- PluginManager/PluginManager.csproj | 1 + PluginManager/UX/Linux/KDE.cs | 12 +++-- PluginManager/UX/Other/Console.cs | 14 ++---- PluginManager/UX/UxHandler.cs | 6 +-- SethDiscordBot.sln | 6 --- .../PluginManagerTests/AppSettingsTests.cs | 46 ------------------- SethTests/SethTests.csproj | 33 ------------- SethTests/Usings.cs | 1 - 19 files changed, 31 insertions(+), 155 deletions(-) rename PluginManager/Interfaces/{IInternalAction.cs => ICommandAction.cs} (100%) delete mode 100644 SethTests/PluginManagerTests/AppSettingsTests.cs delete mode 100644 SethTests/SethTests.csproj delete mode 100644 SethTests/Usings.cs diff --git a/DiscordBot/Bot/Actions/Extra/PluginMethods.cs b/DiscordBot/Bot/Actions/Extra/PluginMethods.cs index 89da9fe..58be800 100644 --- a/DiscordBot/Bot/Actions/Extra/PluginMethods.cs +++ b/DiscordBot/Bot/Actions/Extra/PluginMethods.cs @@ -151,9 +151,7 @@ internal static class PluginMethods } ); - - - + await RefreshPlugins(false); } diff --git a/DiscordBot/Bot/Commands/NormalCommands/Help.cs b/DiscordBot/Bot/Commands/NormalCommands/Help.cs index 8387dc5..c45d2a0 100644 --- a/DiscordBot/Bot/Commands/NormalCommands/Help.cs +++ b/DiscordBot/Bot/Commands/NormalCommands/Help.cs @@ -38,7 +38,7 @@ internal class Help: DBCommand /// The main body of the command /// /// The command context - public void ExecuteServer(DBCommandExecutingArguments args) + public void ExecuteServer(DbCommandExecutingArguments args) { if (args.arguments is not null) { diff --git a/DiscordBot/Program.cs b/DiscordBot/Program.cs index 48e0183..62a20bd 100644 --- a/DiscordBot/Program.cs +++ b/DiscordBot/Program.cs @@ -69,7 +69,7 @@ public class Program ConsoleUtilities.WriteColorText("&rRemember to close the bot using the ShutDown command (&yexit&r) or some settings won't be saved"); - ConsoleUtilities.WriteColorText($"Running on &m{Functions.GetOperatingSystem()}"); + ConsoleUtilities.WriteColorText($"Running on &m{(System.OperatingSystem.IsWindows() ? "Windows" : "Linux")}"); Console.WriteLine("============================ LOG ============================"); Console.ForegroundColor = ConsoleColor.White; diff --git a/PluginManager/Bot/CommandHandler.cs b/PluginManager/Bot/CommandHandler.cs index 6c3fc72..5fc4256 100644 --- a/PluginManager/Bot/CommandHandler.cs +++ b/PluginManager/Bot/CommandHandler.cs @@ -141,7 +141,7 @@ internal class CommandHandler if (split.Length > 1) argsClean = string.Join(' ', split, 1, split.Length - 1).Split(' '); - DBCommandExecutingArguments cmd = new(context, cleanMessage, split[0], argsClean); + DbCommandExecutingArguments cmd = new(context, cleanMessage, split[0], argsClean); Config.Logger.Log( message: $"User ({context.User.Username}) from Guild \"{context.Guild.Name}\" executed command \"{cmd.cleanContent}\"", diff --git a/PluginManager/Config.cs b/PluginManager/Config.cs index b23daa5..5a0d398 100644 --- a/PluginManager/Config.cs +++ b/PluginManager/Config.cs @@ -1,7 +1,6 @@ using System; using System.IO; using System.Threading.Tasks; -using Avalonia.Controls.Notifications; using PluginManager.Bot; using PluginManager.Others; using PluginManager.Others.Logger; diff --git a/PluginManager/Interfaces/DBCommand.cs b/PluginManager/Interfaces/DBCommand.cs index 251f103..e25fe15 100644 --- a/PluginManager/Interfaces/DBCommand.cs +++ b/PluginManager/Interfaces/DBCommand.cs @@ -36,7 +36,7 @@ public interface DBCommand /// The main body of the command. This is what is executed when user calls the command in Server /// /// The disocrd Context - void ExecuteServer(DBCommandExecutingArguments args) + void ExecuteServer(DbCommandExecutingArguments args) { } @@ -44,7 +44,7 @@ public interface DBCommand /// The main body of the command. This is what is executed when user calls the command in DM /// /// The disocrd Context - void ExecuteDM(DBCommandExecutingArguments args) + void ExecuteDM(DbCommandExecutingArguments args) { } } diff --git a/PluginManager/Interfaces/IInternalAction.cs b/PluginManager/Interfaces/ICommandAction.cs similarity index 100% rename from PluginManager/Interfaces/IInternalAction.cs rename to PluginManager/Interfaces/ICommandAction.cs diff --git a/PluginManager/Online/PluginsManager.cs b/PluginManager/Online/PluginsManager.cs index 8417b69..285762d 100644 --- a/PluginManager/Online/PluginsManager.cs +++ b/PluginManager/Online/PluginsManager.cs @@ -1,11 +1,8 @@ using System; using System.Collections.Generic; -using System.Data.Common; using System.Threading.Tasks; using PluginManager.Online.Helpers; using PluginManager.Others; -using OperatingSystem = PluginManager.Others.OperatingSystem; - namespace PluginManager.Online; public class PluginsManager @@ -40,7 +37,6 @@ public class PluginsManager var lines = list.ToArray(); var data = new List(); - var op = Functions.GetOperatingSystem(); var len = lines.Length; for (var i = 0; i < len; i++) @@ -49,7 +45,7 @@ public class PluginsManager continue; var content = lines[i].Split(','); var display = new string[4]; // 4 columns - if (op == OperatingSystem.WINDOWS) + if (System.OperatingSystem.IsWindows()) { if (content[4].Contains("Windows")) { @@ -62,7 +58,7 @@ public class PluginsManager data.Add(display); } } - else if (op == OperatingSystem.LINUX) + else if (System.OperatingSystem.IsLinux()) { if (content[4].Contains("Linux")) { @@ -122,7 +118,7 @@ public class PluginsManager var contents = lines[i].Split(','); if (contents[0].ToLowerInvariant() == name.ToLowerInvariant()) { - if (Functions.GetOperatingSystem() == OperatingSystem.WINDOWS && contents[4].Contains("Windows")) + if (System.OperatingSystem.IsWindows() && contents[4].Contains("Windows")) { if (contents.Length == 6) return new[] @@ -138,7 +134,7 @@ public class PluginsManager } - if (Functions.GetOperatingSystem() == OperatingSystem.LINUX && contents[4].Contains("Linux")) + if (System.OperatingSystem.IsLinux() && contents[4].Contains("Linux")) { if (contents.Length == 6) return new[] diff --git a/PluginManager/Others/DBCommandExecutingArguments.cs b/PluginManager/Others/DBCommandExecutingArguments.cs index ee7da81..7ce0c81 100644 --- a/PluginManager/Others/DBCommandExecutingArguments.cs +++ b/PluginManager/Others/DBCommandExecutingArguments.cs @@ -1,13 +1,12 @@ -using System.Linq; -using Discord.Commands; +using Discord.Commands; using Discord.WebSocket; -using PluginManager.Bot; + namespace PluginManager.Others; -public class DBCommandExecutingArguments +public class DbCommandExecutingArguments { - public DBCommandExecutingArguments( + public DbCommandExecutingArguments( SocketCommandContext context, string cleanContent, string commandUsed, string[]? arguments) { this.context = context; @@ -16,7 +15,7 @@ public class DBCommandExecutingArguments this.arguments = arguments; } - public DBCommandExecutingArguments(SocketUserMessage? message, DiscordSocketClient client) + public DbCommandExecutingArguments(SocketUserMessage? message, DiscordSocketClient client) { this.context = new SocketCommandContext(client, message); int pos = 0; diff --git a/PluginManager/Others/Enums.cs b/PluginManager/Others/Enums.cs index 4f080ad..53a156a 100644 --- a/PluginManager/Others/Enums.cs +++ b/PluginManager/Others/Enums.cs @@ -1,16 +1,5 @@ namespace PluginManager.Others; -/// -/// A list of operating systems -/// -public enum OperatingSystem -{ - WINDOWS, - LINUX, - MAC_OS, - UNKNOWN -} - /// /// The output log type /// @@ -39,9 +28,3 @@ public enum InternalActionRunType ON_STARTUP, ON_CALL } - -internal enum ExceptionExitCode: int -{ - CONFIG_FAILED_TO_LOAD = 1, - CONFIG_KEY_NOT_FOUND = 2, -} diff --git a/PluginManager/Others/Functions.cs b/PluginManager/Others/Functions.cs index 7c71576..6ea23ae 100644 --- a/PluginManager/Others/Functions.cs +++ b/PluginManager/Others/Functions.cs @@ -29,18 +29,6 @@ public static class Functions } } - /// - /// Get the Operating system you are runnin on - /// - /// An Operating system - public static OperatingSystem GetOperatingSystem() - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return OperatingSystem.WINDOWS; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) return OperatingSystem.LINUX; - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) return OperatingSystem.MAC_OS; - return OperatingSystem.UNKNOWN; - } - /// /// Copy one Stream to another /// diff --git a/PluginManager/PluginManager.csproj b/PluginManager/PluginManager.csproj index f61b9f8..1342f6a 100644 --- a/PluginManager/PluginManager.csproj +++ b/PluginManager/PluginManager.csproj @@ -14,6 +14,7 @@ + diff --git a/PluginManager/UX/Linux/KDE.cs b/PluginManager/UX/Linux/KDE.cs index 3d3673e..50ebd00 100644 --- a/PluginManager/UX/Linux/KDE.cs +++ b/PluginManager/UX/Linux/KDE.cs @@ -5,11 +5,12 @@ namespace PluginManager.UX.Linux; internal class KDE : IOutputModel { + internal string KdeDialogApplication { get; } = "kdialog"; public async Task ShowMessageBox(string title, string message, MessageBoxType type) { var process = new Process(); - process.StartInfo.FileName = "kdialog"; + process.StartInfo.FileName = KdeDialogApplication; string typeStr = type switch { @@ -27,9 +28,10 @@ internal class KDE : IOutputModel public async Task ShowInputBox(string title, string message) { var process = new Process(); - process.StartInfo.FileName = "kdialog"; + process.StartInfo.FileName = KdeDialogApplication; process.StartInfo.Arguments = $"--title \"{title}\" --inputbox \"{message}\""; process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardInput = true; process.Start(); await process.WaitForExitAsync(); @@ -39,7 +41,7 @@ internal class KDE : IOutputModel public async Task ShowMessageBox(string message) { var process = new Process(); - process.StartInfo.FileName = "kdialog"; + process.StartInfo.FileName = KdeDialogApplication; process.StartInfo.Arguments = $"--msgbox \"{message}\""; process.Start(); await process.WaitForExitAsync(); @@ -48,7 +50,7 @@ internal class KDE : IOutputModel public async Task ShowMessageBox(string title, string message, MessageBoxButtons buttons, bool isWarning) { var process = new Process(); - process.StartInfo.FileName = "kdialog"; + process.StartInfo.FileName = KdeDialogApplication; string buttonsStr = buttons switch { @@ -67,7 +69,7 @@ internal class KDE : IOutputModel public async Task ShowNotification(string title, string message, int timeout_seconds = 5) { var process = new Process(); - process.StartInfo.FileName = "kdialog"; + process.StartInfo.FileName = KdeDialogApplication; process.StartInfo.Arguments = $"--title \"{title}\" --passivepopup \"{message}\" {timeout_seconds}"; process.Start(); await process.WaitForExitAsync(); diff --git a/PluginManager/UX/Other/Console.cs b/PluginManager/UX/Other/Console.cs index 94132e0..803b1cd 100644 --- a/PluginManager/UX/Other/Console.cs +++ b/PluginManager/UX/Other/Console.cs @@ -19,33 +19,29 @@ internal class Console : IOutputModel public Task ShowInputBox(string title, string message) { - AnsiConsole.Markup(title); - AnsiConsole.Markup(message); + AnsiConsole.MarkupLine(title); - string input = AnsiConsole.Ask("Please enter the value:"); + string input = AnsiConsole.Ask(message); return Task.FromResult(input); } public Task ShowMessageBox(string message) { - AnsiConsole.Markup(message); + AnsiConsole.MarkupLine(message); return Task.CompletedTask; } public Task ShowMessageBox(string title, string message,MessageBoxButtons buttons, bool isWarning) { - AnsiConsole.Markup(title); - AnsiConsole.Markup(message); + AnsiConsole.MarkupLine(title); + AnsiConsole.MarkupLine(message); return Task.FromResult(0); } public Task ShowNotification(string title, string message, int timeout_seconds = 5) { - AnsiConsole.Markup(title); - AnsiConsole.Markup(message); - return Task.CompletedTask; } } diff --git a/PluginManager/UX/UxHandler.cs b/PluginManager/UX/UxHandler.cs index 40bc254..76830ed 100644 --- a/PluginManager/UX/UxHandler.cs +++ b/PluginManager/UX/UxHandler.cs @@ -4,15 +4,15 @@ namespace PluginManager.UX; public static class UxHandler { - private static IOutputModel _model; + private static IOutputModel? _model; public static void Init() { _model = Config.AppSettings["UI"] switch { "KDE" => new Linux.KDE(), - "Console" => new Other.Console(), - _ => _model + "CONSOLE" => new Other.Console(), + _ => null }; } diff --git a/SethDiscordBot.sln b/SethDiscordBot.sln index d355007..a8d9f43 100644 --- a/SethDiscordBot.sln +++ b/SethDiscordBot.sln @@ -15,8 +15,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LevelingSystem", "..\SethPl EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonCompatibilityLayer", "..\SethPlugins\PythonCompatibilityLayer\PythonCompatibilityLayer.csproj", "{81ED4953-13E5-4950-96A8-8CEF5FD59559}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SethTests", "SethTests\SethTests.csproj", "{B3044E3C-2F68-4556-9E87-3772702B4CE7}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -43,10 +41,6 @@ Global {81ED4953-13E5-4950-96A8-8CEF5FD59559}.Debug|Any CPU.Build.0 = Debug|Any CPU {81ED4953-13E5-4950-96A8-8CEF5FD59559}.Release|Any CPU.ActiveCfg = Release|Any CPU {81ED4953-13E5-4950-96A8-8CEF5FD59559}.Release|Any CPU.Build.0 = Release|Any CPU - {B3044E3C-2F68-4556-9E87-3772702B4CE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B3044E3C-2F68-4556-9E87-3772702B4CE7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B3044E3C-2F68-4556-9E87-3772702B4CE7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B3044E3C-2F68-4556-9E87-3772702B4CE7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SethTests/PluginManagerTests/AppSettingsTests.cs b/SethTests/PluginManagerTests/AppSettingsTests.cs deleted file mode 100644 index ed18d62..0000000 --- a/SethTests/PluginManagerTests/AppSettingsTests.cs +++ /dev/null @@ -1,46 +0,0 @@ -using PluginManager; -using Xunit.Abstractions; - -namespace SethTests.PluginManagerTests; - -public class AppSettingsTests -{ - private readonly ITestOutputHelper _testOutputHelper; - - public AppSettingsTests(ITestOutputHelper testOutputHelper) - { - _testOutputHelper = testOutputHelper; - } - - [Fact] - public void TestAppSettings_ConstructorInitializeTheClassAndFile() - { - var appSettings = new PluginManager.Others.SettingsDictionary("settings.txt"); - - Assert.NotNull(appSettings); - } - - [Theory] - [InlineData("key1", "value1")] - [InlineData("key2", true)] - public void TestAppSettings_InsertingValueIntoSettings(string keyName, object value) - { - var appSettings = new PluginManager.Others.SettingsDictionary("settings.txt"); - - appSettings[keyName] = value; - Assert.True(appSettings.ContainsKey(keyName)); - } - - [Theory] - //[InlineData("key2", 32)] // fails - [InlineData("key1", "value1")] - public void TestAppSettings_GettingTheValueFromSettings(string keyName, object value) - { - var appSettings = new PluginManager.Others.SettingsDictionary("settings.txt"); - - appSettings[keyName] = value; - - Assert.Same(appSettings[keyName], value); - } - -} \ No newline at end of file diff --git a/SethTests/SethTests.csproj b/SethTests/SethTests.csproj deleted file mode 100644 index e2d19d2..0000000 --- a/SethTests/SethTests.csproj +++ /dev/null @@ -1,33 +0,0 @@ - - - - net6.0 - enable - enable - - false - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - - - - - - diff --git a/SethTests/Usings.cs b/SethTests/Usings.cs deleted file mode 100644 index 8c927eb..0000000 --- a/SethTests/Usings.cs +++ /dev/null @@ -1 +0,0 @@ -global using Xunit; \ No newline at end of file