2024-12-26 05:36:20 +00:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
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-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:36:20 +00:00
|
|
|
|
// TODO: This throws an exception instead of returning null now
|
2024-10-29 09:10:37 +00:00
|
|
|
|
// Log it if the log channel exists
|
2024-12-26 05:36:20 +00:00
|
|
|
|
DiscordChannel logChannel = await command.Guild.GetChannelAsync(Config.logChannel);
|
2024-10-29 09:10:37 +00:00
|
|
|
|
if (logChannel != null)
|
|
|
|
|
{
|
|
|
|
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
|
|
|
|
{
|
|
|
|
|
Color = DiscordColor.Green,
|
|
|
|
|
Description = "User was removed from staff.\n"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-19 11:38:59 +00:00
|
|
|
|
}
|