2022-08-21 07:34:11 +00:00
|
|
|
|
using System;
|
2022-02-21 08:40:09 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using DSharpPlus.Entities;
|
|
|
|
|
using DSharpPlus.Exceptions;
|
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 AssignCommand : ApplicationCommandModule
|
2022-02-21 08:40:09 +00:00
|
|
|
|
{
|
2022-08-21 07:34:11 +00:00
|
|
|
|
[SlashRequireGuild]
|
|
|
|
|
[SlashCommand("assign", "Assigns a staff member to this ticket.")]
|
|
|
|
|
public async Task OnExecute(InteractionContext command, [Option("User", "(Optional) User to assign to this ticket.")] DiscordUser user = null)
|
2022-05-19 11:38:59 +00:00
|
|
|
|
{
|
2022-08-21 07:34:11 +00:00
|
|
|
|
DiscordMember member = null;
|
|
|
|
|
try
|
2022-05-19 11:38:59 +00:00
|
|
|
|
{
|
2022-08-21 07:34:11 +00:00
|
|
|
|
member = user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id);
|
2022-02-21 08:40:09 +00:00
|
|
|
|
|
2022-08-21 07:34:11 +00:00
|
|
|
|
if (member == null)
|
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
|
|
|
|
{
|
|
|
|
|
Color = DiscordColor.Red,
|
2022-08-21 07:34:11 +00:00
|
|
|
|
Description = "Could not find that user in this server."
|
|
|
|
|
}, true);
|
2022-05-19 11:38:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-08-21 07:34:11 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
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 = "Could not find that user in this server."
|
|
|
|
|
}, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-21 08:40:09 +00:00
|
|
|
|
|
2022-08-21 07:34:11 +00:00
|
|
|
|
// Check if ticket exists in the database
|
|
|
|
|
if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket))
|
|
|
|
|
{
|
|
|
|
|
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 = "This channel is not a ticket."
|
|
|
|
|
}, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-21 08:40:09 +00:00
|
|
|
|
|
2022-08-21 07:34:11 +00:00
|
|
|
|
if (!Database.IsStaff(member.Id))
|
|
|
|
|
{
|
|
|
|
|
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 = "Error: 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.AssignStaff(ticket, member.Id))
|
|
|
|
|
{
|
|
|
|
|
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 = "Error: Failed to assign " + member.Mention + " to ticket."
|
|
|
|
|
}, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-21 08:40:09 +00:00
|
|
|
|
|
2022-08-21 07:34:11 +00:00
|
|
|
|
await command.CreateResponseAsync(new DiscordEmbedBuilder
|
|
|
|
|
{
|
|
|
|
|
Color = DiscordColor.Green,
|
|
|
|
|
Description = "Assigned " + member.Mention + " to ticket."
|
|
|
|
|
});
|
2022-02-21 08:40:09 +00:00
|
|
|
|
|
2022-08-21 07:34:11 +00:00
|
|
|
|
if (Config.assignmentNotifications)
|
|
|
|
|
{
|
|
|
|
|
try
|
2022-05-19 11:38:59 +00:00
|
|
|
|
{
|
2022-08-21 07:34:11 +00:00
|
|
|
|
await member.SendMessageAsync(new DiscordEmbedBuilder
|
2022-05-19 11:38:59 +00:00
|
|
|
|
{
|
2022-08-21 07:34:11 +00:00
|
|
|
|
Color = DiscordColor.Green,
|
|
|
|
|
Description = "You have been assigned to a support ticket: " + command.Channel.Mention
|
|
|
|
|
});
|
2022-05-19 11:38:59 +00:00
|
|
|
|
}
|
2022-08-21 07:34:11 +00:00
|
|
|
|
catch (UnauthorizedException) { }
|
|
|
|
|
}
|
2022-02-21 08:40:09 +00:00
|
|
|
|
|
2022-08-21 07:34:11 +00:00
|
|
|
|
// Log it if the log channel exists
|
|
|
|
|
DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel);
|
|
|
|
|
if (logChannel != null)
|
|
|
|
|
{
|
|
|
|
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
2022-05-19 11:38:59 +00:00
|
|
|
|
{
|
2022-08-21 07:34:11 +00:00
|
|
|
|
Color = DiscordColor.Green,
|
|
|
|
|
Description = member.Mention + " was assigned to " + command.Channel.Mention + " by " + command.Member.Mention + "."
|
|
|
|
|
});
|
2022-05-19 11:38:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|