2024-12-27 06:23:54 +00:00
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
2024-12-26 05:36:20 +00:00
using System.Threading.Tasks ;
using DSharpPlus.Commands ;
using DSharpPlus.Commands.ContextChecks ;
using DSharpPlus.Commands.Processors.SlashCommands ;
2022-02-21 08:40:09 +00:00
using DSharpPlus.Entities ;
2023-03-23 12:21:20 +00:00
using MySqlConnector ;
2022-02-21 08:40:09 +00:00
2022-08-21 07:34:11 +00:00
namespace SupportChild.Commands ;
2024-12-26 05:36:20 +00:00
public class RemoveStaffCommand
2022-02-21 08:40:09 +00:00
{
2024-12-26 05:36:20 +00:00
[RequireGuild]
[Command("removestaff")]
[Description("Removes a staff member.")]
public async Task OnExecute ( SlashCommandContext command ,
[Parameter("user")] [ Description ( "User to remove from staff." ) ] DiscordUser user )
2024-10-29 09:10:37 +00:00
{
if ( ! Database . IsStaff ( user . Id ) )
{
2024-12-26 05:36:20 +00:00
await command . RespondAsync ( new DiscordEmbedBuilder
2024-10-29 09:10:37 +00:00
{
Color = DiscordColor . Red ,
Description = "User is already not registered as staff."
} , true ) ;
return ;
}
2022-02-21 08:40:09 +00:00
2024-12-27 06:23:54 +00:00
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 ) ;
}
2024-12-27 07:17:14 +00:00
await LogChannel . Success ( "<@" + assignedTicket . assignedStaffID + "> was unassigned from <#" + assignedTicket . channelID + "> by " + command . User . Mention + "." , assignedTicket . id ) ;
2024-12-27 06:23:54 +00:00
}
}
2024-10-29 09:10:37 +00:00
await using MySqlConnection c = Database . GetConnection ( ) ;
c . Open ( ) ;
MySqlCommand deletion = new MySqlCommand ( @"DELETE FROM staff WHERE user_id=@user_id" , c ) ;
deletion . Parameters . AddWithValue ( "@user_id" , user . Id ) ;
2024-12-26 05:36:20 +00:00
await deletion . PrepareAsync ( ) ;
2024-10-29 09:10:37 +00:00
deletion . ExecuteNonQuery ( ) ;
2022-02-21 08:40:09 +00:00
2024-12-26 05:36:20 +00:00
await command . RespondAsync ( new DiscordEmbedBuilder
2024-10-29 09:10:37 +00:00
{
Color = DiscordColor . Green ,
Description = "User was removed from staff."
} , true ) ;
2022-02-21 08:40:09 +00:00
2024-12-27 07:17:14 +00:00
await LogChannel . Success ( user . Mention + " was removed from staff by " + command . User . Mention + "." ) ;
2024-10-29 09:10:37 +00:00
}
2022-05-19 11:38:59 +00:00
}