2024-12-27 03:43:55 +00:00
using System ;
2024-12-26 05:36:20 +00:00
using System.ComponentModel ;
2022-08-21 07:34:11 +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-08-21 07:34:11 +00:00
using DSharpPlus.Entities ;
2024-12-26 05:57:41 +00:00
using DSharpPlus.Exceptions ;
2024-12-27 03:22:30 +00:00
using SupportChild.Interviews ;
2022-08-21 07:34:11 +00:00
namespace SupportChild.Commands ;
2024-12-26 05:36:20 +00:00
[Command("admin")]
[Description("Administrative commands.")]
public class AdminCommands
2022-08-21 07:34:11 +00:00
{
2024-12-26 05:36:20 +00:00
[RequireGuild]
[Command("setticket")]
[Description("Turns a channel into a ticket. WARNING: Anyone will be able to delete the channel using /close.")]
public async Task SetTicket ( SlashCommandContext command ,
2024-12-27 07:17:14 +00:00
[Parameter("user")] [ Description ( "(Optional) The owner of the ticket." ) ] DiscordUser user = null )
2024-10-29 09:10:37 +00:00
{
// Check if ticket exists in the database
if ( Database . IsOpenTicket ( command . Channel . Id ) )
{
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 = "This channel is already a ticket."
} , true ) ;
return ;
}
2024-12-26 13:09:08 +00:00
DiscordUser ticketUser = user = = null ? command . User : user ;
2024-10-29 09:10:37 +00:00
long id = Database . NewTicket ( ticketUser . Id , 0 , command . Channel . Id ) ;
2024-12-26 05:36:20 +00:00
await command . RespondAsync ( new DiscordEmbedBuilder
2024-10-29 09:10:37 +00:00
{
Color = DiscordColor . Green ,
2024-12-26 12:21:37 +00:00
Description = "Channel has been designated ticket " + id . ToString ( "00000" ) + "."
2024-10-29 09:10:37 +00:00
} ) ;
2024-12-27 07:17:14 +00:00
await LogChannel . Success ( command . Channel . Mention + " has been designated ticket " + id . ToString ( "00000" ) + " by " + command . Member ? . Mention + "." , ( uint ) id ) ;
2024-10-29 09:10:37 +00:00
}
2024-12-26 05:36:20 +00:00
[RequireGuild]
[Command("unsetticket")]
[Description("Deletes a ticket from the ticket system without deleting the channel.")]
public async Task UnsetTicket ( SlashCommandContext command ,
2024-12-27 07:17:14 +00:00
[Parameter("ticket-id")] [ Description ( "(Optional) Ticket to unset. Uses the channel you are in by default. Use ticket ID, not channel ID!" ) ] long ticketID = 0 )
2024-10-29 09:10:37 +00:00
{
Database . Ticket ticket ;
2024-12-27 03:43:55 +00:00
DiscordChannel channel = null ;
await command . DeferResponseAsync ( true ) ;
2024-10-29 09:10:37 +00:00
if ( ticketID = = 0 )
{
// Check if ticket exists in the database
if ( ! Database . TryGetOpenTicket ( command . Channel . Id , out ticket ) )
{
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 = "This channel is not a ticket!"
} , true ) ;
return ;
}
2024-12-27 03:43:55 +00:00
channel = command . Channel ;
2024-10-29 09:10:37 +00:00
}
else
{
// Check if ticket exists in the database
if ( ! Database . TryGetOpenTicketByID ( ( uint ) ticketID , out ticket ) )
{
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 = "There is no ticket with this ticket ID."
} , true ) ;
return ;
}
2024-12-27 03:43:55 +00:00
// Find the channel if it still exists
try
{
channel = await command . Guild . GetChannelAsync ( ticket . channelID ) ;
}
catch ( Exception ) { /*ignored*/ }
2024-10-29 09:10:37 +00:00
}
2024-12-27 03:43:55 +00:00
// If the channel exists, stop any ongoing interview
if ( channel ! = null )
{
await Interviewer . StopInterview ( channel ) ;
}
2024-10-29 09:10:37 +00:00
2024-12-27 03:43:55 +00:00
// Delete the ticket from the database and respond to command
2024-10-29 09:10:37 +00:00
if ( Database . DeleteOpenTicket ( ticket . id ) )
{
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 = "Channel has been undesignated as a ticket."
} ) ;
2024-12-27 07:17:14 +00:00
await LogChannel . Success ( command . Channel . Mention + " has been undesignated as a ticket by " + command . User . Mention + "." , ticket . id ) ;
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: Failed removing ticket from database."
} , true ) ;
}
}
2024-12-26 07:47:07 +00:00
[RequireGuild]
2024-12-26 05:36:20 +00:00
[Command("reload")]
[Description("Reloads the bot config.")]
public async Task Reload ( SlashCommandContext command )
2024-10-29 09:10:37 +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 = "Reloading bot application..."
2024-12-27 05:15:54 +00:00
} , true ) ;
2024-12-26 12:21:37 +00:00
2024-12-27 07:17:14 +00:00
await LogChannel . Success ( command . Channel . Mention + " reloaded the bot." ) ;
2024-12-26 12:21:37 +00:00
2024-10-29 09:10:37 +00:00
Logger . Log ( "Reloading bot..." ) ;
2024-12-26 07:12:50 +00:00
await SupportChild . Reload ( ) ;
2024-10-29 09:10:37 +00:00
}
2022-08-21 07:34:11 +00:00
}