Files
archived-discord-bot/CompatBot/Commands/Attributes/CheckBaseAttributeWithReactions.cs
13xforever 92751ba6e9 use file-scoped namespaces to reduce nesting
some formatting might be fucked
2022-06-30 00:59:46 +05:00

38 lines
1.4 KiB
C#

using System.Threading.Tasks;
using CompatBot.Utils;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
namespace CompatBot.Commands.Attributes;
internal abstract class CheckBaseAttributeWithReactions: CheckBaseAttribute
{
protected abstract Task<bool> IsAllowed(CommandContext ctx, bool help);
public DiscordEmoji? ReactOnSuccess { get; }
public DiscordEmoji? ReactOnFailure { get; }
public CheckBaseAttributeWithReactions(DiscordEmoji? reactOnSuccess = null, DiscordEmoji? reactOnFailure = null)
{
ReactOnSuccess = reactOnSuccess;
ReactOnFailure = reactOnFailure;
}
public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
{
var result = await IsAllowed(ctx, help);
Config.Log.Debug($"Check for {GetType().Name} and user {ctx.User.Username}#{ctx.User.Discriminator} ({ctx.User.Id}) resulted in {result}");
if (result)
{
if (ReactOnSuccess != null && !help)
await ctx.ReactWithAsync(ReactOnSuccess).ConfigureAwait(false);
}
else
{
if (ReactOnFailure != null && !help)
await ctx.ReactWithAsync(ReactOnFailure, $"{ReactOnFailure} {ctx.Message.Author.Mention} you do not have required permissions, this incident will be reported").ConfigureAwait(false);
}
return result;
}
}