diff --git a/BUILDS/net6.0/EVE_LevelingSystem.dll b/BUILDS/net6.0/EVE_LevelingSystem.dll index 42de544..4a7dd3c 100644 Binary files a/BUILDS/net6.0/EVE_LevelingSystem.dll and b/BUILDS/net6.0/EVE_LevelingSystem.dll differ diff --git a/BUILDS/net6.0/PluginManager.dll b/BUILDS/net6.0/PluginManager.dll index bda798d..b790e5f 100644 Binary files a/BUILDS/net6.0/PluginManager.dll and b/BUILDS/net6.0/PluginManager.dll differ diff --git a/DiscordBot/Discord/Commands/Restart.cs b/DiscordBot/Discord/Commands/Restart.cs index 0d3a6b4..b88936e 100644 --- a/DiscordBot/Discord/Commands/Restart.cs +++ b/DiscordBot/Discord/Commands/Restart.cs @@ -1,16 +1,9 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - using System.Diagnostics; -using System.Text; -using System.Threading.Tasks; - using Discord.WebSocket; -using dsc = Discord.Commands; -using ds = Discord; +using DiscordLibCommands = Discord.Commands; +using DiscordLib = Discord; using PluginManager.Interfaces; using PluginManager.Others.Permissions; @@ -56,9 +49,9 @@ namespace DiscordBot.Discord.Commands /// The command message /// The discord bot client /// True if the message was sent from a DM channel, false otherwise - public async void Execute(dsc.SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM) + public async void Execute(DiscordLibCommands.SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM) { - if (!DiscordPermissions.hasPermission(message.Author as SocketGuildUser, ds.GuildPermission.Administrator)) return; + if (!DiscordPermissions.hasPermission(message.Author as SocketGuildUser, DiscordLib.GuildPermission.Administrator)) return; var args = Functions.GetArguments(message); var OS = Functions.GetOperatinSystem(); if (args.Count == 0) @@ -87,15 +80,22 @@ namespace DiscordBot.Discord.Commands break; case "-cmd": case "-args": + string cmd = "--args"; + + if (args.Count > 1) + for (int i = 1; i < args.Count; i++) + cmd += $" {args[i]}"; + switch (OS) { case PluginManager.Others.OperatingSystem.WINDOWS: - Process.Start("./DiscordBot.exe", Functions.MergeStrings(args.ToArray(), 1)); + Functions.WriteLogFile("Restarting the bot with the following arguments: \"" + cmd + "\""); + Process.Start("./DiscordBot.exe", cmd); break; case PluginManager.Others.OperatingSystem.LINUX: case PluginManager.Others.OperatingSystem.MAC_OS: - Process.Start("./DiscordBot", Functions.MergeStrings(args.ToArray(), 1)); + Process.Start("./DiscordBot", cmd); break; default: return; diff --git a/DiscordBot/Program.cs b/DiscordBot/Program.cs index b276b1f..4b9fc73 100644 --- a/DiscordBot/Program.cs +++ b/DiscordBot/Program.cs @@ -36,9 +36,9 @@ namespace DiscordBot Directory.CreateDirectory("./Data/Languages"); Directory.CreateDirectory("./Data/Plugins/Commands"); Directory.CreateDirectory("./Data/Plugins/Events"); - if (!File.Exists("./Data/Resources/DiscordBotCore.data") || Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_TOKEN", '\t')!.Length != 59) + if (!File.Exists("./Data/Resources/DiscordBotCore.data") || Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_TOKEN", '=')!.Length != 59) { - File.WriteAllText("./Data/Resources/DiscordBotCore.data", "BOT_TOKEN\ttoken\nBOT_PREFIX\t!\n"); + File.WriteAllText("./Data/Resources/DiscordBotCore.data", "BOT_TOKEN=token\nBOT_PREFIX=!\n"); while (true) { Console.WriteLine("Please insert your token: "); @@ -46,11 +46,10 @@ namespace DiscordBot string botToken = Console.ReadLine(); if (botToken.Length == 59) { - string prefix = Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_PREFIX", - '\t'); + string prefix = Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_PREFIX", '='); if (prefix == string.Empty || prefix == null) prefix = "!"; - File.WriteAllText("./Data/Resources/DiscordBotCore.data", $"BOT_TOKEN\t{botToken}\nBOT_PREFIX\t{prefix}\n"); + File.WriteAllText("./Data/Resources/DiscordBotCore.data", $"BOT_TOKEN={botToken}\nBOT_PREFIX={prefix}\n"); break; } else Console.WriteLine("Invalid Token !"); @@ -239,7 +238,7 @@ namespace DiscordBot break; case "token": if (File.Exists("./Data/Resources/DiscordBotCore.data")) - Console.WriteLine("Token: " + Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_TOKEN", '\t')); + Console.WriteLine("Token: " + Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_TOKEN", '=')); else Console.WriteLine("File could not be found. Please register token"); break; default: @@ -359,17 +358,12 @@ namespace DiscordBot Console.Clear(); Console.ForegroundColor = ConsoleColor.DarkYellow; - Console.WriteLine("Discord BOT for Cross Platform\n\nCreated by: Wizzy\nDiscord: Wizzy#9181"); + //Console.WriteLine("Discord BOT for Cross Platform\n\nCreated by: Wizzy\nDiscord: Wizzy#9181"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("============================ Discord BOT - Cross Platform ============================"); - string token = - Functions.readCodeFromFile((Functions.dataFolder + "DiscordBotCore.data"), "BOT_TOKEN", - '\t'); - string prefix = Functions.readCodeFromFile((Functions.dataFolder + "DiscordBotCore.data"), - "BOT_PREFIX", - '\t'); + string token = Functions.readCodeFromFile(Functions.dataFolder + "DiscordBotCore.data", "BOT_TOKEN", '='); + string prefix = Functions.readCodeFromFile(Functions.dataFolder + "DiscordBotCore.data", "BOT_PREFIX", '='); - Console.WriteLine("Detected prefix: " + prefix); var discordbooter = new Boot(token, prefix); await discordbooter.Awake(); return discordbooter; @@ -430,7 +424,7 @@ namespace DiscordBot return; } - if (len > 0 && args.Contains("--cmd")) + if (len > 0 && (args.Contains("--cmd") || args.Contains("--args"))) { if (args.Contains("lp") || args.Contains("loadplugins")) loadPluginsOnStartup = true; diff --git a/EVE_LevelingSystem/LevelingSystem.cs b/EVE_LevelingSystem/LevelingSystem.cs index 9b399b0..1edfa6b 100644 --- a/EVE_LevelingSystem/LevelingSystem.cs +++ b/EVE_LevelingSystem/LevelingSystem.cs @@ -18,7 +18,17 @@ public class LevelingSystem : DBEvent private async Task Client_MessageReceived(SocketMessage arg) { - if (arg.Author.IsBot || arg.Attachments.Count > 0 || arg.Content.StartsWith(Functions.readCodeFromFile(System.IO.Path.Combine(Functions.dataFolder, "DiscordBotCore.data"), "BOT_PREFIX", '\t'))) + if (arg.Author.IsBot || arg.Attachments.Count > 0 || + arg.Content.StartsWith + ( + Functions.readCodeFromFile + ( + fileName: System.IO.Path.Combine(Functions.dataFolder, "DiscordBotCore.data"), + Code: "BOT_PREFIX", + separator: '=' + ) + ) + ) return; if (Core.playerMessages.ContainsKey(arg.Author.Id)) diff --git a/PluginManager/Others/Functions.cs b/PluginManager/Others/Functions.cs index 02afbf5..2a09b70 100644 --- a/PluginManager/Others/Functions.cs +++ b/PluginManager/Others/Functions.cs @@ -48,7 +48,7 @@ namespace PluginManager.Others /// File name /// Setting name /// Separator between setting key code and its value - /// The value of the specified setting key code in the specified file (STRING) + /// The value of the specified setting key code in the specified file () public static string? readCodeFromFile(string fileName, string Code, char separator) => File.ReadAllLines(fileName) .Where(p => p.StartsWith(Code) && !p.StartsWith(commentMark.ToString())) @@ -65,9 +65,7 @@ namespace PluginManager.Others archFile = pakFolder + archFile; Directory.CreateDirectory(pakFolder); if (!File.Exists(archFile)) - { - throw new Exception("Failed to load file !"); - } + throw new FileNotFoundException("Failed to load file !"); string? textValue = null; var fs = new FileStream(archFile, FileMode.Open);