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 ;
2024-12-26 12:21:37 +00:00
using DSharpPlus.Exceptions ;
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 ToggleActiveCommand
2022-02-21 08:40:09 +00:00
{
2024-12-26 05:36:20 +00:00
[RequireGuild]
[Command("toggleactive")]
[Description("Toggles active status for a staff member.")]
public async Task OnExecute ( SlashCommandContext command , [ Parameter ( "user" ) ] [ Description ( "(Optional) Staff member to toggle activity for." ) ] DiscordUser user = null )
2024-10-29 09:10:37 +00:00
{
DiscordUser staffUser = user = = null ? command . User : user ;
2022-08-21 07:34:11 +00:00
2024-10-29 09:10:37 +00:00
// Check if ticket exists in the database
if ( ! Database . TryGetStaff ( staffUser . Id , out Database . StaffMember staffMember ) )
{
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 = = 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
2024-10-29 09:10:37 +00:00
if ( Database . SetStaffActive ( staffUser . Id , ! staffMember . active ) )
{
2024-12-26 12:21:37 +00:00
if ( user ! = null & & user . Id ! = command . User . Id )
2024-10-29 09:10:37 +00:00
{
2024-12-26 12:21:37 +00:00
await command . RespondAsync ( new DiscordEmbedBuilder
{
Color = DiscordColor . Green ,
Description = staffUser . Mention + ( staffMember . active ? " is now set as inactive and will no longer be randomly assigned any support tickets."
: " is now set as active and will be randomly assigned support tickets again." )
} , true ) ;
}
else
{
await command . RespondAsync ( new DiscordEmbedBuilder
{
Color = DiscordColor . Green ,
Description = staffMember . active ? "You are now set as inactive and will no longer be randomly assigned any support tickets."
: "You are now set as active and will be randomly assigned support tickets again."
} , true ) ;
}
2024-10-29 09:10:37 +00:00
}
else
{
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 = "Error: Unable to update active status in database."
} , true ) ;
}
2024-12-26 12:21:37 +00:00
2024-12-27 07:17:14 +00:00
if ( user ! = null & & user . Id ! = command . User . Id )
2024-12-26 12:21:37 +00:00
{
2024-12-27 07:17:14 +00:00
await LogChannel . Success ( staffUser . Mention + " set " + command . Channel . Mention + "'s status to " + ( staffMember . active ? "active" : "inactive" ) ) ;
2024-12-26 12:21:37 +00:00
}
2024-12-27 07:17:14 +00:00
else
2024-12-26 12:21:37 +00:00
{
2024-12-27 07:17:14 +00:00
await LogChannel . Success ( staffUser . Mention + " set their own status to " + ( staffMember . active ? "active" : "inactive" ) ) ;
2024-12-26 12:21:37 +00:00
}
2024-10-29 09:10:37 +00:00
}
2022-05-19 11:38:59 +00:00
}