Code formatting and renamed DBCommandExecutingArguments to DbCommandExecutingArguments
This commit is contained in:
@@ -151,9 +151,7 @@ internal static class PluginMethods
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
await RefreshPlugins(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ internal class Help: DBCommand
|
||||
/// The main body of the command
|
||||
/// </summary>
|
||||
/// <param name="context">The command context</param>
|
||||
public void ExecuteServer(DBCommandExecutingArguments args)
|
||||
public void ExecuteServer(DbCommandExecutingArguments args)
|
||||
{
|
||||
if (args.arguments is not null)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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}\"",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
/// <param name="args">The disocrd Context</param>
|
||||
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
|
||||
/// </summary>
|
||||
/// <param name="args">The disocrd Context</param>
|
||||
void ExecuteDM(DBCommandExecutingArguments args)
|
||||
void ExecuteDM(DbCommandExecutingArguments args)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<string[]>();
|
||||
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[]
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
namespace PluginManager.Others;
|
||||
|
||||
/// <summary>
|
||||
/// A list of operating systems
|
||||
/// </summary>
|
||||
public enum OperatingSystem
|
||||
{
|
||||
WINDOWS,
|
||||
LINUX,
|
||||
MAC_OS,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The output log type
|
||||
/// </summary>
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -29,18 +29,6 @@ public static class Functions
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the Operating system you are runnin on
|
||||
/// </summary>
|
||||
/// <returns>An Operating system</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy one Stream to another <see langword="async" />
|
||||
/// </summary>
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.0.6" />
|
||||
<PackageReference Include="Discord.Net" Version="3.11.0"/>
|
||||
<PackageReference Include="Spectre.Console" Version="0.47.0" />
|
||||
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.118"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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<string> 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<int> 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();
|
||||
|
||||
@@ -19,33 +19,29 @@ internal class Console : IOutputModel
|
||||
|
||||
public Task<string> ShowInputBox(string title, string message)
|
||||
{
|
||||
AnsiConsole.Markup(title);
|
||||
AnsiConsole.Markup(message);
|
||||
AnsiConsole.MarkupLine(title);
|
||||
|
||||
string input = AnsiConsole.Ask<string>("Please enter the value:");
|
||||
string input = AnsiConsole.Ask<string>(message);
|
||||
|
||||
return Task.FromResult(input);
|
||||
}
|
||||
|
||||
public Task ShowMessageBox(string message)
|
||||
{
|
||||
AnsiConsole.Markup(message);
|
||||
AnsiConsole.MarkupLine(message);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<int> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<string, string>("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<string, object>("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<string, object>("settings.txt");
|
||||
|
||||
appSettings[keyName] = value;
|
||||
|
||||
Assert.Same(appSettings[keyName], value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/>
|
||||
<PackageReference Include="xunit" Version="2.4.1"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="DiscordBot\"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DiscordBot\DiscordBot.csproj"/>
|
||||
<ProjectReference Include="..\PluginManager\PluginManager.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1 +0,0 @@
|
||||
global using Xunit;
|
||||
Reference in New Issue
Block a user