linux updater

This commit is contained in:
2023-01-10 19:42:10 +02:00
parent 1683234376
commit 22f2cd4e59
11 changed files with 67 additions and 109 deletions

1
.gitignore vendored
View File

@@ -98,6 +98,7 @@ StyleCopReport.xml
*.pidb
*.svclog
*.scc
*.code-workspace
# Chutzpah Test files
_Chutzpah*

View File

@@ -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

View File

@@ -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()

View File

@@ -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;
}
/// <summary>

View File

@@ -1,52 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>disable</Nullable>
<ApplicationIcon />
<StartupObject />
<SignAssembly>False</SignAssembly>
<IsPublishable>True</IsPublishable>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>none</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Data\**" />
<Compile Remove="obj\**" />
<Compile Remove="Output\**" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Remove="Data\**" />
<EmbeddedResource Remove="obj\**" />
<EmbeddedResource Remove="Output\**" />
</ItemGroup>
<ItemGroup>
<None Remove="Data\**" />
<None Remove="obj\**" />
<None Remove="Output\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.7.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PluginManager\PluginManager.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy /B /Y &quot;$(TargetDir)*.dll&quot; &quot;$(TargetDir)Libraries&quot;" />
</Target>
</Project>

View File

@@ -38,7 +38,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.8.1" />
<PackageReference Include="Discord.Net" Version="3.9.0" />
</ItemGroup>
<ItemGroup>

View File

@@ -24,7 +24,6 @@ namespace DiscordBot;
public class Program
{
private static bool loadPluginsOnStartup;
private static bool listPluginsAtStartup;
private static ConsoleCommandsHandler consoleCommandsHandler;
/// <summary>
@@ -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,13 +417,38 @@ 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<float>(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");
"#!/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}");
}
}
}

View File

@@ -118,7 +118,7 @@ namespace PluginManager.Database
}
public async Task<string> GetValueAsync(string tableName, string keyName, string KeyValue,
public async Task<string?> 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<string> ReadDataAsync(string query)
public async Task<string?> 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<object[]> ReadDataArrayAsync(string query)
public async Task<object[]?> 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<List<string[]>> ReadAllRowsAsync(string query)
public async Task<List<string[]>?> 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();

View File

@@ -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<string[]> Action { get; init; }
public string? CommandName { get; init; }
public string? Description { get; init; }
public string? Usage { get; init; }
public Action<string[]>? Action { get; init; }
}

View File

@@ -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");
}
});

View File

@@ -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