Added UI support for LINUX KDE Plasma

This commit is contained in:
2023-12-27 18:03:26 +02:00
parent c8480b3c83
commit af90ae5fba
11 changed files with 259 additions and 26 deletions

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>disable</Nullable>
<ApplicationIcon/>
<StartupObject/>

View File

@@ -1,6 +1,10 @@
using System;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using PluginManager.UX;
namespace DiscordBot;

View File

@@ -1,28 +1,33 @@
using System;
using PluginManager;
using Spectre.Console;
using System.Threading.Tasks;
namespace DiscordBot;
public static class Installer
{
public static void GenerateStartupConfig()
public static async Task GenerateStartupConfig()
{
AnsiConsole.MarkupLine("Welcome to the [bold]SethBot[/] installer !");
AnsiConsole.MarkupLine("First, we need to configure the bot. Don't worry, it will be quick !");
var token = AnsiConsole.Ask<string>("Please enter the bot [yellow]token[/]:");
var prefix = AnsiConsole.Ask<string>("Please enter the bot [yellow]prefix[/]:");
var serverId = AnsiConsole.Ask<string>("Please enter the [yellow]Server ID[/]:");
string token = await PluginManager.UX.UxHandler.ShowInputBox("SethBot", "Please enter the bot token:");
string botPrefix = await PluginManager.UX.UxHandler.ShowInputBox("SethBot", "Please enter the bot prefix:");
string serverId = await PluginManager.UX.UxHandler.ShowInputBox("SethBot", "Please enter the Server ID:");
if (string.IsNullOrWhiteSpace(serverId)) serverId = "NULL";
if (string.IsNullOrWhiteSpace(token) || string.IsNullOrWhiteSpace(botPrefix))
{
await PluginManager.UX.UxHandler.ShowMessageBox("SethBot", "Invalid token or prefix !", PluginManager.UX.MessageBoxType.Error);
Environment.Exit(-20);
}
Config.AppSettings.Add("token", token);
Config.AppSettings.Add("prefix", prefix);
Config.AppSettings.Add("prefix", botPrefix);
Config.AppSettings.Add("ServerID", serverId);
Config.AppSettings.SaveToFile();
AnsiConsole.MarkupLine("[bold]Config saved ![/]");
await Config.AppSettings.SaveToFile();
Config.Logger.Log("Config Saved", source: typeof(Installer));
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -7,6 +8,7 @@ using DiscordBot.Utilities;
using PluginManager.Bot;
using PluginManager.Others;
using PluginManager.Others.Actions;
using PluginManager.UX;
using Spectre.Console;
using static PluginManager.Config;
@@ -24,7 +26,7 @@ public class Program
PreLoadComponents(args).Wait();
if (!AppSettings.ContainsKey("ServerID") || !AppSettings.ContainsKey("token") || !AppSettings.ContainsKey("prefix"))
Installer.GenerateStartupConfig();
Installer.GenerateStartupConfig().Wait();
HandleInput().Wait();
}
@@ -87,7 +89,6 @@ public class Program
/// <summary>
/// Handle user input arguments from the startup of the application
/// </summary>
/// <param name="args">The arguments</param>
private static async Task HandleInput()
{
await StartNoGui();
@@ -100,12 +101,10 @@ public class Program
{
if (ex.Message == "No process is on the other end of the pipe." || (uint)ex.HResult == 0x800700E9)
{
if (AppSettings.ContainsKey("LaunchMessage"))
AppSettings.Add("LaunchMessage",
"An error occured while closing the bot last time. Please consider closing the bot using the &rexit&c method !\n" +
"There is a risk of losing all data or corruption of the save file, which in some cases requires to reinstall the bot !"
);
UxHandler.ShowMessageBox("SethBot", "An error occured while closing the bot last time. Please consider closing the bot using the &rexit&c method !\n" +
"There is a risk of losing all data or corruption of the save file, which in some cases requires to reinstall the bot !", MessageBoxType.Error).Wait();
Logger.Log("An error occured while closing the bot last time. Please consider closing the bot using the &rexit&c method !\n" +
"There is a risk of losing all data or corruption of the save file, which in some cases requires to reinstall the bot !",
source: typeof(Program), type: LogType.ERROR