2022-04-18 22:52:03 +12:00
|
|
|
|
using System;
|
2024-12-26 18:36:20 +13:00
|
|
|
|
using System.ComponentModel;
|
2022-02-21 21:40:09 +13:00
|
|
|
|
using System.Threading.Tasks;
|
2024-12-26 18:36:20 +13:00
|
|
|
|
using DSharpPlus.Commands;
|
|
|
|
|
using DSharpPlus.Commands.ContextChecks;
|
|
|
|
|
using DSharpPlus.Commands.Processors.SlashCommands;
|
2022-02-21 21:40:09 +13:00
|
|
|
|
using DSharpPlus.Entities;
|
2024-12-26 18:57:41 +13:00
|
|
|
|
using DSharpPlus.Exceptions;
|
2023-03-24 01:21:20 +13:00
|
|
|
|
using MySqlConnector;
|
2022-02-21 21:40:09 +13:00
|
|
|
|
|
2022-08-21 19:34:11 +12:00
|
|
|
|
namespace SupportChild.Commands;
|
|
|
|
|
|
2024-12-26 18:36:20 +13:00
|
|
|
|
public class AddStaffCommand
|
2022-02-21 21:40:09 +13:00
|
|
|
|
{
|
2024-12-26 18:36:20 +13:00
|
|
|
|
[RequireGuild]
|
|
|
|
|
[Command("addstaff")]
|
|
|
|
|
[Description("Adds a new staff member.")]
|
|
|
|
|
public async Task OnExecute(SlashCommandContext command,
|
|
|
|
|
[Parameter("user")][Description("User to add to staff.")] DiscordUser user)
|
2024-10-29 22:10:37 +13:00
|
|
|
|
{
|
2025-02-06 15:15:18 +13:00
|
|
|
|
DiscordMember staffMember;
|
2024-10-29 22:10:37 +13:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
staffMember = user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id);
|
2022-02-21 21:40:09 +13:00
|
|
|
|
|
2024-10-29 22:10:37 +13:00
|
|
|
|
if (staffMember == null)
|
|
|
|
|
{
|
2024-12-26 18:36:20 +13:00
|
|
|
|
await command.RespondAsync(new DiscordEmbedBuilder
|
2024-10-29 22:10:37 +13:00
|
|
|
|
{
|
|
|
|
|
Color = DiscordColor.Red,
|
|
|
|
|
Description = "Could not find that user in this server."
|
|
|
|
|
}, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
2024-12-26 18:36:20 +13:00
|
|
|
|
await command.RespondAsync(new DiscordEmbedBuilder
|
2024-10-29 22:10:37 +13:00
|
|
|
|
{
|
|
|
|
|
Color = DiscordColor.Red,
|
|
|
|
|
Description = "Could not find that user in this server."
|
|
|
|
|
}, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-21 21:40:09 +13:00
|
|
|
|
|
2025-02-06 15:15:18 +13:00
|
|
|
|
bool alreadyStaff = Database.StaffMember.IsStaff(staffMember.Id);
|
|
|
|
|
if (!Database.StaffMember.AddStaff(staffMember.DisplayName, staffMember.Id))
|
|
|
|
|
{
|
|
|
|
|
await command.RespondAsync(new DiscordEmbedBuilder
|
|
|
|
|
{
|
|
|
|
|
Color = DiscordColor.Red,
|
|
|
|
|
Description = "Error: Failed to add staff member to database."
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
2022-02-21 21:40:09 +13:00
|
|
|
|
|
2024-12-27 20:22:00 +13:00
|
|
|
|
if (alreadyStaff)
|
2024-10-29 22:10:37 +13:00
|
|
|
|
{
|
2024-12-27 20:22:00 +13:00
|
|
|
|
await command.RespondAsync(new DiscordEmbedBuilder
|
|
|
|
|
{
|
|
|
|
|
Color = DiscordColor.Green,
|
|
|
|
|
Description = staffMember.Mention + " is already a staff member, refreshed username in database."
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await command.RespondAsync(new DiscordEmbedBuilder
|
|
|
|
|
{
|
|
|
|
|
Color = DiscordColor.Green,
|
|
|
|
|
Description = staffMember.Mention + " was added to staff."
|
|
|
|
|
}, true);
|
2022-02-21 21:40:09 +13:00
|
|
|
|
|
2024-12-27 20:22:00 +13:00
|
|
|
|
await LogChannel.Success(staffMember.Mention + " was added to staff by " + command.User.Mention + ".");
|
|
|
|
|
}
|
2024-10-29 22:10:37 +13:00
|
|
|
|
}
|
2022-05-19 23:38:59 +12:00
|
|
|
|
}
|