2022-08-21 07:34:11 +00:00
using System.Threading.Tasks ;
2022-02-21 08:40:09 +00:00
using DSharpPlus.Entities ;
2022-08-21 07:34:11 +00:00
using DSharpPlus.SlashCommands ;
using DSharpPlus.SlashCommands.Attributes ;
2022-02-21 08:40:09 +00:00
2022-08-21 07:34:11 +00:00
namespace SupportChild.Commands ;
public class ToggleActiveCommand : ApplicationCommandModule
2022-02-21 08:40:09 +00:00
{
2022-08-21 07:34:11 +00:00
[SlashRequireGuild]
[SlashCommand("toggleactive", "Toggles active status for a staff member.")]
public async Task OnExecute ( InteractionContext command , [ Option ( "User" , "(Optional) Staff member to toggle activity for." ) ] DiscordUser user = null )
2022-05-19 11:38:59 +00:00
{
2022-08-21 07:34:11 +00:00
DiscordUser staffUser = user = = null ? command . User : user ;
// Check if ticket exists in the database
if ( ! Database . TryGetStaff ( staffUser . Id , out Database . StaffMember staffMember ) )
2022-05-19 11:38:59 +00:00
{
2022-08-21 07:34:11 +00:00
await command . CreateResponseAsync ( new DiscordEmbedBuilder
2022-05-19 11:38:59 +00:00
{
2022-08-21 07:34:11 +00:00
Color = DiscordColor . Red ,
Description = user = = null ? "You have not been registered as staff." : "The user is not registered as staff."
} , true ) ;
return ;
}
2022-02-21 08:40:09 +00:00
2022-08-21 07:34:11 +00:00
if ( Database . SetStaffActive ( staffUser . Id , ! staffMember . active ) )
{
await command . CreateResponseAsync ( new DiscordEmbedBuilder
{
Color = DiscordColor . Green ,
Description = staffMember . active ? "Staff member is now set as inactive and will no longer be randomly assigned any support tickets." : "Staff member is now set as active and will be randomly assigned support tickets again."
} , true ) ;
}
else
{
await command . CreateResponseAsync ( new DiscordEmbedBuilder
{
Color = DiscordColor . Red ,
Description = "Error: Unable to update active status in database."
} , true ) ;
2022-05-19 11:38:59 +00:00
}
}
}