Unassign staff member from tickets when they are removed from staff

This commit is contained in:
Toastie 2024-12-27 19:23:54 +13:00
parent 0ee12cb1ec
commit f5d044512a
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
2 changed files with 42 additions and 2 deletions

View file

@ -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<Database.Ticket> 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);

View file

@ -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