2022-04-18 10:52:03 +00:00
using System ;
2024-12-26 05:36:20 +00:00
using System.ComponentModel ;
2022-02-21 08:40:09 +00:00
using System.Threading.Tasks ;
2024-12-26 05:36:20 +00:00
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 AddStaffCommand
2022-02-21 08:40:09 +00:00
{
2024-12-26 05:36:20 +00: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 09:10:37 +00:00
{
DiscordMember staffMember = null ;
try
{
staffMember = user = = null ? command . Member : await command . Guild . GetMemberAsync ( user . Id ) ;
2022-02-21 08:40:09 +00:00
2024-10-29 09:10:37 +00:00
if ( staffMember = = null )
{
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 = "Could not find that user in this server."
} , true ) ;
return ;
}
}
catch ( Exception )
{
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 = "Could not find that user in this server."
} , true ) ;
return ;
}
2022-02-21 08:40:09 +00:00
2024-10-29 09:10:37 +00:00
await using MySqlConnection c = Database . GetConnection ( ) ;
MySqlCommand cmd = Database . IsStaff ( staffMember . Id ) ? new MySqlCommand ( @"UPDATE staff SET name = @name WHERE user_id = @user_id" , c ) : new MySqlCommand ( @"INSERT INTO staff (user_id, name) VALUES (@user_id, @name);" , c ) ;
2022-02-21 08:40:09 +00:00
2024-10-29 09:10:37 +00:00
c . Open ( ) ;
cmd . Parameters . AddWithValue ( "@user_id" , staffMember . Id ) ;
cmd . Parameters . AddWithValue ( "@name" , staffMember . DisplayName ) ;
cmd . ExecuteNonQuery ( ) ;
cmd . Dispose ( ) ;
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 = staffMember . Mention + " was added to staff."
} ) ;
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 = staffMember . Mention + " was added to 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
}