SupportChild/Commands/BlacklistCommand.cs

63 lines
2.1 KiB
C#
Raw Normal View History

2022-04-18 22:52:03 +12:00
using System;
using System.ComponentModel;
2022-02-21 21:40:09 +13:00
using System.Threading.Tasks;
using DSharpPlus.Commands;
using DSharpPlus.Commands.ContextChecks;
using DSharpPlus.Commands.Processors.SlashCommands;
2022-02-21 21:40:09 +13:00
using DSharpPlus.Entities;
2024-12-26 18:57:41 +13:00
using DSharpPlus.Exceptions;
2022-02-21 21:40:09 +13:00
2022-08-21 19:34:11 +12:00
namespace SupportChild.Commands;
public class BlacklistCommand
2022-02-21 21:40:09 +13:00
{
[RequireGuild]
[Command("blacklist")]
[Description("Blacklists a user from opening tickets.")]
public async Task OnExecute(SlashCommandContext command,
[Parameter("user")][Description("User to blacklist.")] DiscordUser user)
{
try
{
if (!Database.Blacklist(user.Id, command.User.Id))
{
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = user.Mention + " is already blacklisted."
}, true);
return;
}
2022-02-21 21:40:09 +13:00
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = "Blocked " + user.Mention + " from opening new tickets."
}, true);
2022-02-21 21:40:09 +13:00
2024-12-26 18:57:41 +13:00
try
{
2024-12-26 18:57:41 +13:00
// Log it if the log channel exists
DiscordChannel logChannel = await SupportChild.client.GetChannelAsync(Config.logChannel);
await logChannel.SendMessageAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Green,
Description = user.Mention + " was blocked from opening tickets by " + command.User.Mention + "."
});
}
2024-12-26 18:57:41 +13:00
catch (NotFoundException)
{
2024-12-27 16:53:40 +13:00
Logger.Error("Could not send message in log channel.");
2024-12-26 18:57:41 +13:00
}
}
catch (Exception)
{
await command.RespondAsync(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "Error occured while blacklisting " + user.Mention + "."
}, true);
throw;
}
}
2022-05-19 23:38:59 +12:00
}