diff --git a/.gitignore b/.gitignore index d76e8eb..36496ba 100644 --- a/.gitignore +++ b/.gitignore @@ -98,6 +98,7 @@ StyleCopReport.xml *.pidb *.svclog *.scc +*.code-workspace # Chutzpah Test files _Chutzpah* diff --git a/.idea/.idea.SethDiscordBot/.idea/.gitignore b/.idea/.idea.SethDiscordBot/.idea/.gitignore deleted file mode 100644 index 22f4eee..0000000 --- a/.idea/.idea.SethDiscordBot/.idea/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Rider ignored files -/contentModel.xml -/.idea.SethDiscordBot.iml -/projectSettingsUpdater.xml -/modules.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/DiscordBot/Discord/Core/Boot.cs b/DiscordBot/Discord/Core/Boot.cs index b7db843..898884c 100644 --- a/DiscordBot/Discord/Core/Boot.cs +++ b/DiscordBot/Discord/Core/Boot.cs @@ -108,12 +108,11 @@ internal class Boot await cmd.DeleteAsync();*/ } - private async Task Ready() + private Task Ready() { Console.Title = "ONLINE"; - - isReady = true; + return Task.CompletedTask; } private Task LoggedIn() diff --git a/DiscordBot/Discord/Core/CommandHandler.cs b/DiscordBot/Discord/Core/CommandHandler.cs index 0abb273..d3d1ff5 100644 --- a/DiscordBot/Discord/Core/CommandHandler.cs +++ b/DiscordBot/Discord/Core/CommandHandler.cs @@ -44,7 +44,7 @@ internal class CommandHandler await commandService.AddModulesAsync(Assembly.GetEntryAssembly(), null); } - private async Task Client_SlashCommandExecuted(SocketSlashCommand arg) + private Task Client_SlashCommandExecuted(SocketSlashCommand arg) { try { @@ -52,7 +52,8 @@ internal class CommandHandler .Where(p => p.Name == arg.Data.Name) .FirstOrDefault(); - if (plugin is null) throw new Exception("Failed to run command. !"); + if (plugin is null) + throw new Exception("Failed to run command. !"); if (arg.Channel is SocketDMChannel) @@ -66,6 +67,8 @@ internal class CommandHandler ex.WriteErrFile(); } + return Task.CompletedTask; + } /// diff --git a/DiscordBot/DiscordBot - Backup.csproj b/DiscordBot/DiscordBot - Backup.csproj deleted file mode 100644 index 5deed1f..0000000 --- a/DiscordBot/DiscordBot - Backup.csproj +++ /dev/null @@ -1,52 +0,0 @@ - - - - Exe - net6.0 - disable - - - False - True - 1.0.1.0 - - - - none - - - - none - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/DiscordBot/DiscordBot.csproj b/DiscordBot/DiscordBot.csproj index 9ff94f2..1f88f48 100644 --- a/DiscordBot/DiscordBot.csproj +++ b/DiscordBot/DiscordBot.csproj @@ -38,11 +38,11 @@ - + - + diff --git a/DiscordBot/Program.cs b/DiscordBot/Program.cs index 74fc5a9..1eaaf2b 100644 --- a/DiscordBot/Program.cs +++ b/DiscordBot/Program.cs @@ -24,7 +24,6 @@ namespace DiscordBot; public class Program { private static bool loadPluginsOnStartup; - private static bool listPluginsAtStartup; private static ConsoleCommandsHandler consoleCommandsHandler; /// @@ -33,7 +32,7 @@ public class Program [STAThread] public static void Startup(string[] args) { - PreLoadComponents().Wait(); + PreLoadComponents(args).Wait(); if (!Config.Variables.Exists("ServerID") || !Config.Variables.Exists("token") || Config.Variables.GetValue("token") == null || @@ -195,10 +194,11 @@ public class Program { #if DEBUG Logger.WriteLine(); - ConsoleCommandsHandler.ExecuteCommad("lp").Wait(); + Logger.WriteLine("Debug mode enabled"); + Logger.WriteLine(); + loadPluginsOnStartup = true; #else if (loadPluginsOnStartup) consoleCommandsHandler.HandleCommand("lp"); - if (listPluginsAtStartup) consoleCommandsHandler.HandleCommand("listplugs"); #endif while (true) @@ -310,8 +310,12 @@ public class Program mainThread.Start(); } - private static async Task PreLoadComponents() + private static async Task PreLoadComponents(string[] args) { + Directory.CreateDirectory("./Data/Resources"); + Directory.CreateDirectory("./Data/Plugins"); + Directory.CreateDirectory("./Data/PAKS"); + Settings.sqlDatabase = new SqlDatabase("SetDB.dat"); await Settings.sqlDatabase.Open(); @@ -325,9 +329,6 @@ public class Program Logger.WriteLine("Loading resources ..."); var main = new Utilities.ProgressBar(ProgressBarType.NO_END); main.Start(); - Directory.CreateDirectory("./Data/Resources"); - Directory.CreateDirectory("./Data/Plugins"); - Directory.CreateDirectory("./Data/PAKS"); if (await Config.Variables.ExistsAsync("DeleteLogsAtStartup")) if (await Config.Variables.GetValueAsync("DeleteLogsAtStartup") == "true") @@ -416,12 +417,37 @@ public class Program { var url = $"https://github.com/Wizzy69/SethDiscordBot/releases/download/v{newVersion}/net6.0_linux.zip"; - Logger.WriteLine("Downloading update ..."); - await ServerCom.DownloadFileNoProgressAsync(url, "./update.zip"); + if (Logger.isConsole) + Console.SetCursorPosition(0, Console.CursorTop); + Logger.WriteLine($"executing: download_file {url}"); + + await ServerCom.DownloadFileAsync(url, "./update.zip", new Progress(percent => { Logger.Write($"\rProgress: {percent}% "); })); await File.WriteAllTextAsync("Install.sh", - "#!/bin/bash\nunzip -qq update.zip -d ./\nrm update.zip\nchmod +x SethDiscordBot\n./DiscordBot"); - Process.Start("Install.sh").WaitForExit(); - Environment.Exit(0); + "#!/bin/bash\nunzip -qq -o update.zip \nrm update.zip\nchmod a+x DiscordBot"); + Logger.WriteLine(); + + try + { + Logger.WriteLine("executing: chmod a+x Install.sh"); + Process.Start("chmod", "a+x Install.sh").WaitForExit(); + Process.Start("Install.sh").WaitForExit(); + + Logger.WriteLine("executing: rm Install.sh"); + Process.Start("rm", "Install.sh").WaitForExit(); + + Logger.WriteLine("The new version of the bot has been installed."); + Logger.WriteLine("Please restart the bot."); + Environment.Exit(0); + } + catch (Exception ex) + { + Logger.WriteErrFile(ex.Message); + if (ex.Message.Contains("Access de")) + Logger.WriteLine("Please run the bot as root."); + } + + //Process.Start(Functions.dataFolder + "Applications/Updater", $"{url}"); + } } } diff --git a/PluginManager/Database/SqlDatabase.cs b/PluginManager/Database/SqlDatabase.cs index faac328..03a94ee 100644 --- a/PluginManager/Database/SqlDatabase.cs +++ b/PluginManager/Database/SqlDatabase.cs @@ -118,7 +118,7 @@ namespace PluginManager.Database } - public async Task GetValueAsync(string tableName, string keyName, string KeyValue, + public async Task GetValueAsync(string tableName, string keyName, string KeyValue, string ResultColumnName) { if (!await TableExistsAsync(tableName)) @@ -127,7 +127,7 @@ namespace PluginManager.Database return await ReadDataAsync($"SELECT {ResultColumnName} FROM {tableName} WHERE {keyName}='{KeyValue}'"); } - public string GetValue(string tableName, string keyName, string KeyValue, string ResultColumnName) + public string? GetValue(string tableName, string keyName, string KeyValue, string ResultColumnName) { if (!TableExists(tableName)) throw new System.Exception($"Table {tableName} does not exist"); @@ -233,7 +233,7 @@ namespace PluginManager.Database return r; } - public async Task ReadDataAsync(string query) + public async Task ReadDataAsync(string query) { if (!Connection.State.HasFlag(System.Data.ConnectionState.Open)) await Connection.OpenAsync(); @@ -250,7 +250,7 @@ namespace PluginManager.Database return null; } - public string ReadData(string query) + public string? ReadData(string query) { if (!Connection.State.HasFlag(System.Data.ConnectionState.Open)) Connection.Open(); @@ -267,7 +267,7 @@ namespace PluginManager.Database return null; } - public async Task ReadDataArrayAsync(string query) + public async Task ReadDataArrayAsync(string query) { if (!Connection.State.HasFlag(System.Data.ConnectionState.Open)) await Connection.OpenAsync(); @@ -284,7 +284,7 @@ namespace PluginManager.Database return null; } - public async Task> ReadAllRowsAsync(string query) + public async Task?> ReadAllRowsAsync(string query) { if (!Connection.State.HasFlag(System.Data.ConnectionState.Open)) await Connection.OpenAsync(); @@ -307,7 +307,7 @@ namespace PluginManager.Database return rows; } - public object[] ReadDataArray(string query) + public object[]? ReadDataArray(string query) { if (!Connection.State.HasFlag(System.Data.ConnectionState.Open)) Connection.Open(); diff --git a/PluginManager/Items/Command.cs b/PluginManager/Items/Command.cs index de41b21..887b631 100644 --- a/PluginManager/Items/Command.cs +++ b/PluginManager/Items/Command.cs @@ -43,8 +43,8 @@ public class Command public class ConsoleCommand { - public string CommandName { get; init; } - public string Description { get; init; } - public string Usage { get; init; } - public Action Action { get; init; } + public string? CommandName { get; init; } + public string? Description { get; init; } + public string? Usage { get; init; } + public Action? Action { get; init; } } \ No newline at end of file diff --git a/PluginManager/Items/ConsoleCommandsHandler.cs b/PluginManager/Items/ConsoleCommandsHandler.cs index dcdbc26..a8f5dde 100644 --- a/PluginManager/Items/ConsoleCommandsHandler.cs +++ b/PluginManager/Items/ConsoleCommandsHandler.cs @@ -429,8 +429,8 @@ public class ConsoleCommandsHandler } else { - Process.Start("./DiscordBot", "lp"); - HandleCommand("sd"); + //HandleCommand("sd"); + Console.WriteLine("This command can not be used outside of Windows yet. Please restart the bot using the manual way"); } }); diff --git a/SethDiscordBot.sln b/SethDiscordBot.sln index 7f602fa..bc1f6ac 100644 --- a/SethDiscordBot.sln +++ b/SethDiscordBot.sln @@ -13,11 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlashCommands", "..\Discord EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LevelingSystem", "..\DiscordBotItems\Plugins\LevelingSystem\LevelingSystem.csproj", "{0138F343-BBB9-4D5F-B499-D9C2978BE9AA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiscordBotUI", "..\DiscordBotItems\DiscordBotUI\DiscordBotUI.csproj", "{3202CE21-BB39-452E-9B0C-740528CAFE43}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Roles", "..\DiscordBotItems\Roles\Roles.csproj", "{0900B4CB-B531-4A8D-98D8-E709A7C2E098}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DBEconomy", "DBEconomy\DBEconomy.csproj", "{203464A2-8D25-4431-97BE-B9FF78F55850}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DBEconomy", "..\DiscordBotItems\Plugins\DBEconomy\DBEconomy.csproj", "{0321365B-4ADC-4B1D-BD98-F573D36E83B2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -45,18 +43,14 @@ Global {0138F343-BBB9-4D5F-B499-D9C2978BE9AA}.Debug|Any CPU.Build.0 = Debug|Any CPU {0138F343-BBB9-4D5F-B499-D9C2978BE9AA}.Release|Any CPU.ActiveCfg = Release|Any CPU {0138F343-BBB9-4D5F-B499-D9C2978BE9AA}.Release|Any CPU.Build.0 = Release|Any CPU - {3202CE21-BB39-452E-9B0C-740528CAFE43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3202CE21-BB39-452E-9B0C-740528CAFE43}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3202CE21-BB39-452E-9B0C-740528CAFE43}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3202CE21-BB39-452E-9B0C-740528CAFE43}.Release|Any CPU.Build.0 = Release|Any CPU {0900B4CB-B531-4A8D-98D8-E709A7C2E098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0900B4CB-B531-4A8D-98D8-E709A7C2E098}.Debug|Any CPU.Build.0 = Debug|Any CPU {0900B4CB-B531-4A8D-98D8-E709A7C2E098}.Release|Any CPU.ActiveCfg = Release|Any CPU {0900B4CB-B531-4A8D-98D8-E709A7C2E098}.Release|Any CPU.Build.0 = Release|Any CPU - {203464A2-8D25-4431-97BE-B9FF78F55850}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {203464A2-8D25-4431-97BE-B9FF78F55850}.Debug|Any CPU.Build.0 = Debug|Any CPU - {203464A2-8D25-4431-97BE-B9FF78F55850}.Release|Any CPU.ActiveCfg = Release|Any CPU - {203464A2-8D25-4431-97BE-B9FF78F55850}.Release|Any CPU.Build.0 = Release|Any CPU + {0321365B-4ADC-4B1D-BD98-F573D36E83B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0321365B-4ADC-4B1D-BD98-F573D36E83B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0321365B-4ADC-4B1D-BD98-F573D36E83B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0321365B-4ADC-4B1D-BD98-F573D36E83B2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE