SupportChild/Commands/AddCategoryCommand.cs

71 lines
2.3 KiB
C#
Raw Permalink Normal View History

using System.Threading.Tasks;
2022-08-21 07:34:11 +00:00
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using DSharpPlus.SlashCommands.Attributes;
namespace SupportChild.Commands;
public class AddCategoryCommand : ApplicationCommandModule
{
[SlashRequireGuild]
[SlashCommand("addcategory", "Adds a category to the ticket bot letting users open tickets in them.")]
public async Task OnExecute(InteractionContext command, [Option("Title", "The name to display on buttons and in selection boxes.")] string title, [Option("Category", "The category to add.")] DiscordChannel category)
{
if (!category.IsCategory)
{
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "That channel is not a category."
}, true);
return;
}
2022-08-21 07:34:11 +00:00
if (string.IsNullOrWhiteSpace(title))
{
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Invalid category title specified."
}, true);
return;
}
2022-08-21 07:34:11 +00:00
if (Database.TryGetCategory(category.Id, out Database.Category _))
{
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "That category is already registered."
}, true);
return;
}
2022-08-21 07:34:11 +00:00
if (Database.TryGetCategory(title, out Database.Category _))
{
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "There is already a category with that title."
}, true);
return;
}
2022-08-21 07:34:11 +00:00
if (Database.AddCategory(title, category.Id))
{
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Category added."
}, true);
}
else
{
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Failed adding the category to the database."
}, true);
}
}
2022-08-21 07:34:11 +00:00
}