SupportChild/Commands/RemoveCategoryCommand.cs

61 lines
2 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 RemoveCategoryCommand
2022-08-21 07:34:11 +00:00
{
[RequireGuild]
[Command("removecategory")]
[Description("Removes the ability for users to open tickets in a specific category.")]
public async Task OnExecute(SlashCommandContext command,
[Parameter("category")][Description("The category to remove.")] DiscordChannel category)
{
if (!Database.TryGetCategory(category.Id, out Database.Category _))
{
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "That category is not registered."
}, true);
return;
}
2022-08-21 07:34:11 +00:00
if (Database.RemoveCategory(category.Id))
{
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Category removed."
}, true);
}
else
{
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Failed removing the category from the database."
}, true);
}
try
{
// Log it if the log channel exists
DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel);
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "`" + category.Name + "` was removed by " + command.User.Mention + "."
});
}
catch (NotFoundException)
{
2024-12-27 03:53:40 +00:00
Logger.Error("Could not send message in log channel.");
}
}
2022-08-21 07:34:11 +00:00
}