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;
|
2024-12-26 05:57:41 +00:00
|
|
|
|
using DSharpPlus.Exceptions;
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-26 05:57:41 +00:00
|
|
|
|
try
|
2024-10-29 09:10:37 +00:00
|
|
|
|
{
|
2024-12-26 05:57:41 +00:00
|
|
|
|
// Log it if the log channel exists
|
|
|
|
|
DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel);
|
2024-10-29 09:10:37 +00:00
|
|
|
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
|
|
|
|
{
|
|
|
|
|
Color = DiscordColor.Green,
|
2024-12-26 12:21:37 +00:00
|
|
|
|
Description = user.Mention + " was removed from staff by " + command.User.Mention + "."
|
2024-10-29 09:10:37 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2024-12-26 05:57:41 +00:00
|
|
|
|
catch (NotFoundException)
|
|
|
|
|
{
|
2024-12-27 03:53:40 +00:00
|
|
|
|
Logger.Error("Could not send message in log channel.");
|
2024-12-26 05:57:41 +00:00
|
|
|
|
}
|
2024-10-29 09:10:37 +00:00
|
|
|
|
}
|
2022-05-19 11:38:59 +00:00
|
|
|
|
}
|