Unassign staff member from tickets when they are removed from staff
This commit is contained in:
parent
0ee12cb1ec
commit
f5d044512a
2 changed files with 42 additions and 2 deletions
|
@ -1,4 +1,6 @@
|
||||||
using System.ComponentModel;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.Commands;
|
using DSharpPlus.Commands;
|
||||||
using DSharpPlus.Commands.ContextChecks;
|
using DSharpPlus.Commands.ContextChecks;
|
||||||
|
@ -27,6 +29,44 @@ public class RemoveStaffCommand
|
||||||
return;
|
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();
|
await using MySqlConnection c = Database.GetConnection();
|
||||||
c.Open();
|
c.Open();
|
||||||
MySqlCommand deletion = new MySqlCommand(@"DELETE FROM staff WHERE user_id=@user_id", c);
|
MySqlCommand deletion = new MySqlCommand(@"DELETE FROM staff WHERE user_id=@user_id", c);
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class UnassignCommand
|
||||||
await command.RespondAsync(new DiscordEmbedBuilder
|
await command.RespondAsync(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Green,
|
Color = DiscordColor.Green,
|
||||||
Description = "Unassigned staff member from ticket."
|
Description = "Unassigned <@\" + ticket.assignedStaffID + \"> from ticket."
|
||||||
});
|
});
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
Loading…
Reference in a new issue