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;
|
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 AddCommand
|
2022-02-21 08:40:09 +00:00
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
|
[RequireGuild]
|
|
|
|
|
[Command("add")]
|
|
|
|
|
[Description("Adds a user to this ticket.")]
|
|
|
|
|
public async Task OnExecute(SlashCommandContext command,
|
|
|
|
|
[Parameter("user")][Description("User to add to ticket.")] DiscordUser user)
|
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 not a ticket."
|
|
|
|
|
}, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-21 08:40:09 +00:00
|
|
|
|
|
2024-10-29 09:10:37 +00:00
|
|
|
|
DiscordMember member;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
member = (user == null ? command.Member : await command.Guild.GetMemberAsync(user.Id));
|
2022-08-21 07:34:11 +00:00
|
|
|
|
|
2024-10-29 09:10:37 +00:00
|
|
|
|
if (member == 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
|
|
|
|
try
|
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
|
await command.Channel.AddOverwriteAsync(member, DiscordPermissions.AccessChannels);
|
|
|
|
|
await command.RespondAsync(new DiscordEmbedBuilder
|
2024-10-29 09:10:37 +00:00
|
|
|
|
{
|
|
|
|
|
Color = DiscordColor.Green,
|
|
|
|
|
Description = "Added " + member.Mention + " to ticket."
|
|
|
|
|
});
|
2022-02-21 08:40:09 +00:00
|
|
|
|
|
2024-10-29 09:10:37 +00:00
|
|
|
|
// Log it if the log channel exists
|
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
|
|
|
|
DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel);
|
2024-10-29 09:10:37 +00:00
|
|
|
|
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
|
|
|
|
|
{
|
|
|
|
|
Color = DiscordColor.Green,
|
|
|
|
|
Description = member.Mention + " was added to " + command.Channel.Mention +
|
2024-12-26 05:36:20 +00:00
|
|
|
|
" by " + command.Member?.Mention + "."
|
2024-10-29 09:10:37 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2024-12-26 05:57:41 +00:00
|
|
|
|
catch (NotFoundException)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error("Could not find the log channel.");
|
|
|
|
|
}
|
2024-10-29 09:10:37 +00:00
|
|
|
|
}
|
|
|
|
|
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 add " + member.Mention + " to ticket, unknown error occured."
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-17 13:09:25 +00:00
|
|
|
|
}
|