SupportChild/Commands/UnassignCommand.cs

64 lines
2.1 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-05-19 11:38:59 +00:00
using DSharpPlus.Entities;
2024-12-26 05:57:41 +00:00
using DSharpPlus.Exceptions;
2022-05-19 11:38:59 +00:00
2022-08-21 07:34:11 +00:00
namespace SupportChild.Commands;
public class UnassignCommand
2022-05-19 11:38:59 +00:00
{
[RequireGuild]
[Command("unassign")]
[Description("Unassigns a staff member from a ticket.")]
public async Task OnExecute(SlashCommandContext command)
{
// Check if ticket exists in the database
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
{
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "This channel is not a ticket."
}, true);
return;
}
2022-05-19 11:38:59 +00:00
if (!Database.UnassignStaff(ticket))
{
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error: Failed to unassign staff member from ticket."
}, true);
return;
}
2022-05-19 11:38:59 +00:00
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Unassigned staff member from ticket."
});
2022-05-19 11:38:59 +00:00
2024-12-26 05:57:41 +00:00
try
{
2024-12-26 05:57:41 +00:00
// Log it if the log channel exists
DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel);
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Staff member was unassigned from " + command.Channel.Mention + " by " + command.User.Mention + ".",
Footer = new DiscordEmbedBuilder.EmbedFooter
{
Text = "Ticket: " + ticket.id.ToString("00000")
}
});
}
2024-12-26 05:57:41 +00:00
catch (NotFoundException)
{
Logger.Error("Could not find the log channel.");
}
}
2022-05-19 11:38:59 +00:00
}