diff --git a/Commands/RemoveStaffCommand.cs b/Commands/RemoveStaffCommand.cs index 0fda411..f9c61fa 100644 --- a/Commands/RemoveStaffCommand.cs +++ b/Commands/RemoveStaffCommand.cs @@ -1,4 +1,6 @@ -using System.ComponentModel; +using System; +using System.Collections.Generic; +using System.ComponentModel; using System.Threading.Tasks; using DSharpPlus.Commands; using DSharpPlus.Commands.ContextChecks; @@ -27,6 +29,44 @@ public class RemoveStaffCommand return; } + await command.DeferResponseAsync(true); + + if (Database.TryGetAssignedTickets(user.Id, out List assignedTickets)) + { + foreach (Database.Ticket assignedTicket in assignedTickets) + { + Database.UnassignStaff(assignedTicket); + try + { + DiscordChannel ticketChannel = await SupportChild.client.GetChannelAsync(assignedTicket.channelID); + await ticketChannel.SendMessageAsync(new DiscordEmbedBuilder + { + Color = DiscordColor.Green, + Description = "Unassigned <@" + assignedTicket.assignedStaffID + "> from ticket." + }); + } + catch (Exception e) + { + Logger.Error("Error when trying to send message about unassigning staff member from ticket-" + assignedTicket.id.ToString("00000"), e); + } + + 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 = "Staff member was unassigned from " + command.Channel.Mention + " by " + command.User.Mention + "." + }); + } + catch (Exception e) + { + Logger.Error("Could not send message in log channel.", e); + } + } + } + await using MySqlConnection c = Database.GetConnection(); c.Open(); MySqlCommand deletion = new MySqlCommand(@"DELETE FROM staff WHERE user_id=@user_id", c); diff --git a/Commands/UnassignCommand.cs b/Commands/UnassignCommand.cs index b73772e..321ba5e 100644 --- a/Commands/UnassignCommand.cs +++ b/Commands/UnassignCommand.cs @@ -39,7 +39,7 @@ public class UnassignCommand await command.RespondAsync(new DiscordEmbedBuilder { Color = DiscordColor.Green, - Description = "Unassigned staff member from ticket." + Description = "Unassigned <@\" + ticket.assignedStaffID + \"> from ticket." }); try