diff --git a/DiscordBot/Discord/Actions/Exit.cs b/DiscordBot/Bot/Actions/Exit.cs similarity index 97% rename from DiscordBot/Discord/Actions/Exit.cs rename to DiscordBot/Bot/Actions/Exit.cs index 2c4e442..69230f5 100644 --- a/DiscordBot/Discord/Actions/Exit.cs +++ b/DiscordBot/Bot/Actions/Exit.cs @@ -4,7 +4,7 @@ using PluginManager; using PluginManager.Interfaces; using PluginManager.Others; -namespace DiscordBot.Discord.Actions; +namespace DiscordBot.Bot.Actions; public class Exit : ICommandAction { diff --git a/DiscordBot/Discord/Actions/Help.cs b/DiscordBot/Bot/Actions/Help.cs similarity index 98% rename from DiscordBot/Discord/Actions/Help.cs rename to DiscordBot/Bot/Actions/Help.cs index 4420722..441fff6 100644 --- a/DiscordBot/Discord/Actions/Help.cs +++ b/DiscordBot/Bot/Actions/Help.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using PluginManager.Others; using PluginManager.Interfaces; -namespace DiscordBot.Discord.Actions +namespace DiscordBot.Bot.Actions { public class Help : ICommandAction { diff --git a/DiscordBot/Discord/Actions/Plugin.cs b/DiscordBot/Bot/Actions/Plugin.cs similarity index 99% rename from DiscordBot/Discord/Actions/Plugin.cs rename to DiscordBot/Bot/Actions/Plugin.cs index 55bbd71..26b568b 100644 --- a/DiscordBot/Discord/Actions/Plugin.cs +++ b/DiscordBot/Bot/Actions/Plugin.cs @@ -6,7 +6,7 @@ using PluginManager.Loaders; using PluginManager.Online; using PluginManager.Others; -namespace DiscordBot.Discord.Actions; +namespace DiscordBot.Bot.Actions; public class Plugin : ICommandAction { diff --git a/DiscordBot/Discord/Commands/Help.cs b/DiscordBot/Bot/Commands/NormalCommands/Help.cs similarity index 98% rename from DiscordBot/Discord/Commands/Help.cs rename to DiscordBot/Bot/Commands/NormalCommands/Help.cs index ce7a1e1..2434521 100644 --- a/DiscordBot/Discord/Commands/Help.cs +++ b/DiscordBot/Bot/Commands/NormalCommands/Help.cs @@ -7,7 +7,7 @@ using PluginManager.Interfaces; using PluginManager.Loaders; using PluginManager.Others; -namespace DiscordBot.Discord.Commands; +namespace DiscordBot.Bot.Commands; /// /// The help command diff --git a/DiscordBot/Bot/Commands/SlashCommands/Help.cs b/DiscordBot/Bot/Commands/SlashCommands/Help.cs new file mode 100644 index 0000000..f31c91f --- /dev/null +++ b/DiscordBot/Bot/Commands/SlashCommands/Help.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Discord; +using Discord.WebSocket; +using PluginManager.Interfaces; +using PluginManager.Others; + + + +namespace DiscordBot.Bot.Commands.SlashCommands; + +public class Help : DBSlashCommand +{ + public string Name => "help"; + public string Description => "This command allows you to check all loaded commands"; + public bool canUseDM => true; + + public List Options => new() + { + new SlashCommandOptionBuilder() + .WithName("command") + .WithDescription("The command you want to get help for") + .WithRequired(false) + .WithType(ApplicationCommandOptionType.String) + }; + + public async void ExecuteServer(SocketSlashCommand context) + { + EmbedBuilder embedBuilder = new(); + + embedBuilder.WithTitle("Help Command"); + embedBuilder.WithColor(Functions.RandomColor); + var slashCommands = PluginManager.Loaders.PluginLoader.SlashCommands; + var options = context.Data.Options; + + //Console.WriteLine("Options: " + options.Count); + if (options is null || options.Count == 0) + { + foreach (var slashCommand in slashCommands) + { + embedBuilder.AddField(slashCommand.Name, slashCommand.Description, true); + } + } + + if (options.Count > 0) + { + string commandName = options.First().Name; + var slashCommand = slashCommands.FirstOrDefault(x => x.Name == commandName); + if (slashCommand is null) + { + await context.RespondAsync("Unknown Command " + commandName); + return; + } + + embedBuilder.AddField(slashCommand.Name, slashCommand.canUseDM,true).WithDescription(slashCommand.Description); + } + + await context.RespondAsync(embed: embedBuilder.Build()); + } +} \ No newline at end of file diff --git a/DiscordBot/Program.cs b/DiscordBot/Program.cs index d0ed071..37b730f 100644 --- a/DiscordBot/Program.cs +++ b/DiscordBot/Program.cs @@ -128,17 +128,21 @@ public class Program { Console.WriteLine("Loading Core ..."); - + + //Handle arguments here: + + if(args.Contains("--gui")) + { + // GUI not implemented yet + Console.WriteLine("GUI not implemented yet"); + return; + } + + // Starting bot after all arguments are handled + var b = await StartNoGui(); try { - if(args.Contains("--gui")) - { - // GUI not implemented yet - Console.WriteLine("GUI not implemented yet"); - return; - } - internalActionManager = new PluginManager.Others.Actions.InternalActionManager("./Data/Actions", "*.dll"); await internalActionManager.Initialize(); @@ -220,7 +224,7 @@ public class Program Console.WriteLine("Current version: " + currentVersion); Console.WriteLine("Latest version: " + newVersion); - Console.WriteLine($"Download from here: https://github.com/Wizzy69/SethDiscordBot/releases/tag/v{newVersion}"); + Console.WriteLine($"Download from here: https://github.com/andreitdr/SethDiscordBot/releases"); Console.WriteLine("Press any key to continue ..."); Console.ReadKey(); diff --git a/PluginManager/Others/Functions.cs b/PluginManager/Others/Functions.cs index d3401dc..5e2bfab 100644 --- a/PluginManager/Others/Functions.cs +++ b/PluginManager/Others/Functions.cs @@ -5,6 +5,7 @@ using System.Text; using System.Text.Json; using System.Threading; using System.Threading.Tasks; +using Discord; namespace PluginManager.Others; @@ -100,4 +101,26 @@ public static class Functions text.Close(); return (obj ?? default)!; } + + public static T SelectRandomValueOf () + { + var enums = Enum.GetValues(typeof(T)); + var random = new Random(); + return (T)enums.GetValue(random.Next(enums.Length)); + } + + public static T RandomValue(this T[] values) + { + Random random = new(); + return values[random.Next(values.Length)]; + } + + public static Discord.Color RandomColor + { + get + { + Random random = new Random(); + return new Discord.Color(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); + } + } } \ No newline at end of file