Added new functions into Functions.cs and added help command for slash Commands.
This commit is contained in:
@@ -4,7 +4,7 @@ using PluginManager;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace DiscordBot.Discord.Actions;
|
||||
namespace DiscordBot.Bot.Actions;
|
||||
|
||||
public class Exit : ICommandAction
|
||||
{
|
||||
@@ -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
|
||||
{
|
||||
@@ -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
|
||||
{
|
||||
@@ -7,7 +7,7 @@ using PluginManager.Interfaces;
|
||||
using PluginManager.Loaders;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace DiscordBot.Discord.Commands;
|
||||
namespace DiscordBot.Bot.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// The help command
|
||||
62
DiscordBot/Bot/Commands/SlashCommands/Help.cs
Normal file
62
DiscordBot/Bot/Commands/SlashCommands/Help.cs
Normal file
@@ -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<SlashCommandOptionBuilder> 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());
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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<T> ()
|
||||
{
|
||||
var enums = Enum.GetValues(typeof(T));
|
||||
var random = new Random();
|
||||
return (T)enums.GetValue(random.Next(enums.Length));
|
||||
}
|
||||
|
||||
public static T RandomValue<T>(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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user