SupportChild/Commands/RemoveStaffCommand.cs

58 lines
1.9 KiB
C#
Raw Normal View History

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;
2024-12-26 05:57:41 +00:00
using DSharpPlus.Exceptions;
using MySqlConnector;
2022-02-21 08:40:09 +00:00
2022-08-21 07:34:11 +00:00
namespace SupportChild.Commands;
public class RemoveStaffCommand
2022-02-21 08:40:09 +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)
{
if (!Database.IsStaff(user.Id))
{
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "User is already not registered as staff."
}, true);
return;
}
2022-02-21 08:40:09 +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);
await deletion.PrepareAsync();
deletion.ExecuteNonQuery();
2022-02-21 08:40:09 +00:00
await command.RespondAsync(new DiscordEmbedBuilder
{
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-12-26 05:57:41 +00:00
// Log it if the log channel exists
DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel);
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = user.Mention + " was removed from staff by " + command.User.Mention + "."
});
}
2024-12-26 05:57:41 +00:00
catch (NotFoundException)
{
Logger.Error("Could not find the log channel.");
}
}
2022-05-19 11:38:59 +00:00
}