diff --git a/BUILDS/net5.0/CMD_Utils.dll b/BUILDS/net5.0/CMD_Utils.dll index 0980936..6811276 100644 Binary files a/BUILDS/net5.0/CMD_Utils.dll and b/BUILDS/net5.0/CMD_Utils.dll differ diff --git a/BUILDS/net5.0/PluginManager.dll b/BUILDS/net5.0/PluginManager.dll index 1bc4197..0928abb 100644 Binary files a/BUILDS/net5.0/PluginManager.dll and b/BUILDS/net5.0/PluginManager.dll differ diff --git a/CMD_LevelingSystem/CMD_LevelingSystem.csproj b/CMD_LevelingSystem/CMD_LevelingSystem.csproj index 8495526..ac6b96b 100644 --- a/CMD_LevelingSystem/CMD_LevelingSystem.csproj +++ b/CMD_LevelingSystem/CMD_LevelingSystem.csproj @@ -5,11 +5,13 @@ - E:\DiscordBot\BUILDS\ + ..\BUILDS\ DEBUG;TRACE prompt none false + false + diff --git a/CMD_Utils/CMD_Utils.csproj b/CMD_Utils/CMD_Utils.csproj index 6d89c4e..449a275 100644 --- a/CMD_Utils/CMD_Utils.csproj +++ b/CMD_Utils/CMD_Utils.csproj @@ -5,7 +5,7 @@ - E:\DiscordBot\BUILDS\ + ..\BUILDS\ diff --git a/DiscordBot/Discord/Commands/Help.cs b/DiscordBot/Discord/Commands/Help.cs index 92f4b25..429342d 100644 --- a/DiscordBot/Discord/Commands/Help.cs +++ b/DiscordBot/Discord/Commands/Help.cs @@ -1,9 +1,13 @@ -using Discord.Commands; +using Discord; +using Discord.Commands; using Discord.WebSocket; using PluginManager.Loaders; using PluginManager.Interfaces; using PluginManager.Others.Permissions; +using PluginManager.Others; + +using System.Collections.Generic; namespace PluginManager.Commands { @@ -22,43 +26,59 @@ namespace PluginManager.Commands public void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM) { + List args = Functions.GetArguments(message); + if (args.Count != 0) + { + + foreach (var item in args) + { + bool commandExists = false; + var e = GenerateHelpCommand(item); + if (e != null) + { + commandExists = true; + context.Channel.SendMessageAsync(embed: e.Build()); + } + if (!commandExists) + context.Channel.SendMessageAsync("Unknown Command " + item); + } + return; + } + bool isAdmin = ((SocketGuildUser)message.Author).isAdmin(); - if (isAdmin) + Discord.EmbedBuilder embedBuilder = new Discord.EmbedBuilder(); + + string adminCommands = ""; + string normalCommands = ""; + string DMCommands = ""; + + foreach (var cmd in PluginLoader.Plugins!) { - if (isDM) - { - foreach (DBCommand p in PluginLoader.Plugins!) - if (p.canUseDM) - if (p.requireAdmin) - context.Channel.SendMessageAsync("[ADMIN] " + p.Usage + "\t" + p.Description); - else context.Channel.SendMessageAsync(p.Usage + "\t" + p.Description); - } - else - { - foreach (DBCommand p in PluginLoader.Plugins!) - if (p.canUseServer) - if (p.requireAdmin) - context.Channel.SendMessageAsync("[ADMIN] " + p.Usage + "\t" + p.Description); - else context.Channel.SendMessageAsync(p.Usage + "\t" + p.Description); - } - } - else - { - if (isDM) - { - foreach (DBCommand p in PluginLoader.Plugins!) - if (p.canUseDM && !p.requireAdmin) - context.Channel.SendMessageAsync(p.Usage + "\t" + p.Description); - } - else - { - foreach (DBCommand p in PluginLoader.Plugins!) - if (p.canUseServer && !p.requireAdmin) - context.Channel.SendMessageAsync(p.Usage + "\t" + p.Description); - } + if (cmd.canUseDM) + DMCommands += cmd.Command + " "; + if (cmd.requireAdmin) + adminCommands += cmd.Command + " "; + else normalCommands += cmd.Command + " "; } + embedBuilder.AddField("Admin Commands", adminCommands); + embedBuilder.AddField("Normal Commands", normalCommands); + embedBuilder.AddField("DM Commands", DMCommands); + context.Channel.SendMessageAsync(embed: embedBuilder.Build()); } + + private EmbedBuilder GenerateHelpCommand(string command) + { + EmbedBuilder embedBuilder = new EmbedBuilder(); + DBCommand cmd = PluginLoader.Plugins.Find(p => p.Command == command); + if (cmd == null) + return null; + + embedBuilder.AddField("Usage", cmd.Usage); + embedBuilder.AddField("Description", cmd.Description); + + return embedBuilder; + } } } \ No newline at end of file diff --git a/DiscordBot/Discord/Core/Boot.cs b/DiscordBot/Discord/Core/Boot.cs index 0e47f34..08128d3 100644 --- a/DiscordBot/Discord/Core/Boot.cs +++ b/DiscordBot/Discord/Core/Boot.cs @@ -11,8 +11,8 @@ namespace PluginManager.Core { internal class Boot { - private readonly string botPrefix; - private readonly string botToken; + public readonly string botPrefix; + public readonly string botToken; private bool isReady = false; diff --git a/DiscordBot/DiscordBot.csproj b/DiscordBot/DiscordBot.csproj index 46319c7..89fc3d9 100644 --- a/DiscordBot/DiscordBot.csproj +++ b/DiscordBot/DiscordBot.csproj @@ -3,7 +3,7 @@ Exe net5.0 - enable + disable diff --git a/DiscordBot/Program.cs b/DiscordBot/Program.cs index 04f4853..d824150 100644 --- a/DiscordBot/Program.cs +++ b/DiscordBot/Program.cs @@ -1,4 +1,5 @@ using Discord; + using System; using System.IO; using System.Threading.Tasks; @@ -8,6 +9,7 @@ using PluginManager.Others; using PluginManager.Loaders; using PluginManager.LanguageSystem; using PluginManager.Online; +using System.Diagnostics; namespace DiscordBot { @@ -37,12 +39,12 @@ namespace DiscordBot { Console.WriteLine("Please insert your token: "); Console.Write("TOKEN: "); - string? botToken = Console.ReadLine(); + string botToken = Console.ReadLine(); if (botToken.Length == 59) { - string? prefix = Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_PREFIX", + string prefix = Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_PREFIX", '\t'); - if (prefix == String.Empty || prefix == null) + if (prefix == string.Empty || prefix == null) prefix = "!"; File.WriteAllText("./Data/Resources/DiscordBotCore.data", $"BOT_TOKEN\t{botToken}\nBOT_PREFIX\t{prefix}\n"); break; @@ -71,12 +73,14 @@ namespace DiscordBot private static async Task NoGUI(Boot discordbooter) { LoadLanguage(); - if (loadPluginsOnStartup) LoadPlugins(discordbooter); + if (loadPluginsOnStartup) + LoadPlugins(discordbooter); while (true) { Console.ForegroundColor = ConsoleColor.White; - Console.Write('$'); + Functions.WriteColorText("&mConsole > &c", false); string[] data = Console.ReadLine().Split(' '); + if (data[0].Length < 2) continue; switch (data[0]) { @@ -85,7 +89,17 @@ namespace DiscordBot if (discordbooter.client.ConnectionState == ConnectionState.Connected) await discordbooter.ShutDown().ContinueWith(t => { Environment.Exit(0); }); break; - + case "reload": + case "rl": + if (Environment.OSVersion.Platform != PlatformID.Win32NT) + { + Console.WriteLine("This command is for windows users ONLY"); + break; + } + if (discordbooter.client.ConnectionState == ConnectionState.Connected) + await discordbooter.ShutDown(); + Process.Start("./DiscordBot", "--execute:lp"); + break; case "listplugs": await manager.ListAvailablePlugins(); break; @@ -121,7 +135,7 @@ namespace DiscordBot break; case "dwlang": string Lname = data.MergeStrings(1); - string?[] link = await languageManager.GetDownloadLink(Lname); + string[] link = await languageManager.GetDownloadLink(Lname); try { if (link[0] is null || link is null) @@ -180,6 +194,7 @@ namespace DiscordBot default: goto case "help"; } + } } @@ -356,10 +371,11 @@ namespace DiscordBot return; } - if (len == 2 && args[0] == "--encrypt") + if (len >= 2 && args[0] == "--encrypt") { - Console.WriteLine("MD5: " + await Cryptography.CreateMD5(args[1])); - System.Console.WriteLine("SHA356: " + await Cryptography.CreateSHA256(args[1])); + string s2e = args.MergeStrings(1); + Console.WriteLine("MD5: " + await Cryptography.CreateMD5(s2e)); + Console.WriteLine("SHA356: " + await Cryptography.CreateSHA256(s2e)); return; } diff --git a/EVE_LevelingSystem/EVE_LevelingSystem.csproj b/EVE_LevelingSystem/EVE_LevelingSystem.csproj index 1eefd33..bfbd2b9 100644 --- a/EVE_LevelingSystem/EVE_LevelingSystem.csproj +++ b/EVE_LevelingSystem/EVE_LevelingSystem.csproj @@ -5,7 +5,7 @@ - E:\DiscordBot\BUILDS\ + ..\BUILDS\ none false diff --git a/PluginManager/Items/Command.cs b/PluginManager/Items/Command.cs new file mode 100644 index 0000000..a95fe16 --- /dev/null +++ b/PluginManager/Items/Command.cs @@ -0,0 +1,43 @@ +using Discord.WebSocket; + +using PluginManager.Loaders; +using PluginManager.Others; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PluginManager.Items +{ + internal class Command + { + public SocketUser Author; + public List Arguments { get; private set; } + public string CommandName { get; private set; } + public char PrefixUsed { get; private set; } + public Command(SocketMessage message) + { + this.Author = message.Author; + string[] data = message.Content.Split(' '); + if (data.Length > 1) + this.Arguments = new List(data.MergeStrings(1).Split(' ')); + else this.Arguments = new List(); + this.CommandName = data[0].Substring(1); + this.PrefixUsed = data[0][0]; + } + + public Command(string message, bool hasPrefix) + { + string[] data = message.Split(' '); + + this.Author = null; + this.Arguments = new List(data.MergeStrings(1).Split(' ')); + this.CommandName = data[0].Substring(1); + if (hasPrefix) + this.PrefixUsed = data[0][0]; + else this.PrefixUsed = '\0'; //null + } + } +} diff --git a/PluginManager/Others/Functions.cs b/PluginManager/Others/Functions.cs index d8ba88b..6cd2e85 100644 --- a/PluginManager/Others/Functions.cs +++ b/PluginManager/Others/Functions.cs @@ -4,7 +4,8 @@ using System; using System.Threading.Tasks; using System.Linq; using System.Collections.Generic; - +using Discord.WebSocket; +using PluginManager.Items; namespace PluginManager.Others { @@ -167,6 +168,12 @@ namespace PluginManager.Others return OperatingSystem.UNKNOWN; } + public static List GetArguments(SocketMessage message) + { + Command command = new Command(message); + return command.Arguments; + } + /// /// A way to create a table based on input data /// EpicWings (Pasca Robert) este cel mai bun @@ -223,9 +230,10 @@ namespace PluginManager.Others /// /// Write the text using color options( &g-green; &b-blue; &r-red; &c-clear; ) + /// /// /// The text - public static void WriteColorText(string text) + public static void WriteColorText(string text, bool appendNewLine = true) { string[] words = text.Split(' '); Dictionary colors = new Dictionary() @@ -233,6 +241,7 @@ namespace PluginManager.Others {"&g", ConsoleColor.Green }, {"&b", ConsoleColor.Blue }, {"&r", ConsoleColor.Red }, + {"&m", ConsoleColor.Magenta }, {"&c", Console.ForegroundColor } }; foreach (string word in words) @@ -244,10 +253,11 @@ namespace PluginManager.Others Console.ForegroundColor = colors[prefix]; } - string m = word.Replace("&g", "").Replace("&b", "").Replace("&r", "").Replace("&c", ""); + string m = word.Replace("&g", "").Replace("&b", "").Replace("&r", "").Replace("&c", "").Replace("&m", ""); Console.Write(m + " "); } - Console.Write('\n'); + if (appendNewLine) + Console.Write('\n'); } /// diff --git a/StartupEvents/StartupEvents.csproj b/StartupEvents/StartupEvents.csproj index 7cb7c93..8d1c46d 100644 --- a/StartupEvents/StartupEvents.csproj +++ b/StartupEvents/StartupEvents.csproj @@ -5,7 +5,7 @@ - E:\DiscordBot\BUILDS\ + ..\BUILDS\ none false