SupportChild/Commands/UnblacklistCommand.cs

54 lines
1.5 KiB
C#
Raw Normal View History

2022-04-18 10:52:03 +00:00
using System;
2022-02-21 08:40:09 +00:00
using System.Threading.Tasks;
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 UnblacklistCommand : ApplicationCommandModule
2022-02-21 08:40:09 +00:00
{
2022-08-21 07:34:11 +00:00
[SlashRequireGuild]
[SlashCommand("unblacklist", "Unblacklists a user from opening tickets.")]
public async Task OnExecute(InteractionContext command, [Option("User", "User to remove from blacklist.")] DiscordUser user)
2022-05-19 11:38:59 +00:00
{
2022-08-21 07:34:11 +00:00
try
2022-05-19 11:38:59 +00:00
{
2022-08-21 07:34:11 +00:00
if (!Database.Unblacklist(user.Id))
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 = user.Mention + " is not blacklisted."
}, true);
2022-05-19 11:38:59 +00:00
return;
}
2022-02-21 08:40:09 +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.Green,
Description = "Removed " + user.Mention + " from blacklist."
}, true);
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
{
Color = DiscordColor.Green,
Description = user.Mention + " was unblacklisted from opening tickets by " + command.Member.Mention + "."
});
2022-05-19 11:38:59 +00:00
}
}
2022-08-21 07:34:11 +00:00
catch (Exception)
{
await command.CreateResponseAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error occured while removing " + user.Mention + " from blacklist."
}, true);
throw;
}
2022-05-19 11:38:59 +00:00
}
}