2024-12-26 05:36:20 +00:00
|
|
|
using System.ComponentModel;
|
2024-10-29 09:10:37 +00:00
|
|
|
using System.Threading.Tasks;
|
2024-12-26 05:36:20 +00:00
|
|
|
using DSharpPlus.Commands;
|
|
|
|
using DSharpPlus.Commands.ContextChecks;
|
|
|
|
using DSharpPlus.Commands.Processors.SlashCommands;
|
2022-08-21 07:34:11 +00:00
|
|
|
using DSharpPlus.Entities;
|
2024-12-26 12:21:37 +00:00
|
|
|
using DSharpPlus.Exceptions;
|
2022-08-21 07:34:11 +00:00
|
|
|
|
|
|
|
namespace SupportChild.Commands;
|
|
|
|
|
2024-12-26 05:36:20 +00:00
|
|
|
public class AddCategoryCommand
|
2022-08-21 07:34:11 +00:00
|
|
|
{
|
2024-12-26 05:36:20 +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)
|
2024-10-29 09:10:37 +00:00
|
|
|
{
|
|
|
|
if (!category.IsCategory)
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
await command.RespondAsync(new DiscordEmbedBuilder
|
2024-10-29 09:10:37 +00:00
|
|
|
{
|
|
|
|
Color = DiscordColor.Red,
|
|
|
|
Description = "That channel is not a category."
|
|
|
|
}, true);
|
|
|
|
return;
|
|
|
|
}
|
2022-08-21 07:34:11 +00:00
|
|
|
|
2024-10-29 09:10:37 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(title))
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
await command.RespondAsync(new DiscordEmbedBuilder
|
2024-10-29 09:10:37 +00:00
|
|
|
{
|
|
|
|
Color = DiscordColor.Red,
|
|
|
|
Description = "Invalid category title specified."
|
|
|
|
}, true);
|
|
|
|
return;
|
|
|
|
}
|
2022-08-21 07:34:11 +00:00
|
|
|
|
2024-10-29 09:10:37 +00:00
|
|
|
if (Database.TryGetCategory(category.Id, out Database.Category _))
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
await command.RespondAsync(new DiscordEmbedBuilder
|
2024-10-29 09:10:37 +00:00
|
|
|
{
|
|
|
|
Color = DiscordColor.Red,
|
|
|
|
Description = "That category is already registered."
|
|
|
|
}, true);
|
|
|
|
return;
|
|
|
|
}
|
2022-08-21 07:34:11 +00:00
|
|
|
|
2024-10-29 09:10:37 +00:00
|
|
|
if (Database.TryGetCategory(title, out Database.Category _))
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
await command.RespondAsync(new DiscordEmbedBuilder
|
2024-10-29 09:10:37 +00:00
|
|
|
{
|
|
|
|
Color = DiscordColor.Red,
|
|
|
|
Description = "There is already a category with that title."
|
|
|
|
}, true);
|
|
|
|
return;
|
|
|
|
}
|
2022-08-21 07:34:11 +00:00
|
|
|
|
2024-10-29 09:10:37 +00:00
|
|
|
if (Database.AddCategory(title, category.Id))
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
await command.RespondAsync(new DiscordEmbedBuilder
|
2024-10-29 09:10:37 +00:00
|
|
|
{
|
|
|
|
Color = DiscordColor.Green,
|
|
|
|
Description = "Category added."
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
await command.RespondAsync(new DiscordEmbedBuilder
|
2024-10-29 09:10:37 +00:00
|
|
|
{
|
|
|
|
Color = DiscordColor.Red,
|
|
|
|
Description = "Error: Failed adding the category to the database."
|
|
|
|
}, true);
|
|
|
|
}
|
2024-12-26 12:21:37 +00:00
|
|
|
|
2024-12-27 07:17:14 +00:00
|
|
|
await LogChannel.Success(command.User.Mention + " added `" + category.Name + "` as `" + title + "` to the category list.");
|
2024-10-29 09:10:37 +00:00
|
|
|
}
|
2022-08-21 07:34:11 +00:00
|
|
|
}
|