SupportChild/Commands/AddCategoryCommand.cs

79 lines
2.5 KiB
C#
Raw Normal View History

using System.ComponentModel;
using System.Threading.Tasks;
using DSharpPlus.Commands;
using DSharpPlus.Commands.ContextChecks;
using DSharpPlus.Commands.Processors.SlashCommands;
2022-08-21 07:34:11 +00:00
using DSharpPlus.Entities;
using DSharpPlus.Exceptions;
2022-08-21 07:34:11 +00:00
namespace SupportChild.Commands;
public class AddCategoryCommand
2022-08-21 07:34:11 +00:00
{
[RequireGuild]
[Command("addcategory")]
[Description("Adds a category to the ticket bot letting users open tickets in them.")]
public async Task OnExecute(SlashCommandContext command,
[Parameter("title")][Description("The name to display on buttons and in selection boxes.")] string title,
[Parameter("category")][Description("The category to add.")] DiscordChannel category)
{
if (!category.IsCategory)
{
await command.RespondAsync(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.RespondAsync(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.RespondAsync(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.RespondAsync(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.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Category added."
}, true);
}
else
{
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Failed adding the category to the database."
}, true);
}
2024-12-27 07:17:14 +00:00
await LogChannel.Success(command.User.Mention + " added `" + category.Name + "` as `" + title + "` to the category list.");
}
2022-08-21 07:34:11 +00:00
}