* initial * Interaction glossary entry * Sharded Interaction sample * Renames into solution * Debugging samples * Modify target location for webhookclient * Finalizing docs work, resolving docfx errors. * Adding threaduser to user chart * Add branch info to readme. * Edits to user chart * Resolve format for glossary entries * Patch sln target * Issue with file naming fixed * Patch 1/x for builds * Appending suggestions
28 lines
1.1 KiB
C#
28 lines
1.1 KiB
C#
using Discord;
|
|
using Discord.Interactions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace InteractionFramework.Attributes
|
|
{
|
|
public class RequireOwnerAttribute : PreconditionAttribute
|
|
{
|
|
public override async Task<PreconditionResult> CheckRequirementsAsync (IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services)
|
|
{
|
|
switch (context.Client.TokenType)
|
|
{
|
|
case TokenType.Bot:
|
|
var application = await context.Client.GetApplicationInfoAsync().ConfigureAwait(false);
|
|
if (context.User.Id != application.Owner.Id)
|
|
return PreconditionResult.FromError(ErrorMessage ?? "Command can only be run by the owner of the bot.");
|
|
return PreconditionResult.FromSuccess();
|
|
default:
|
|
return PreconditionResult.FromError($"{nameof(RequireOwnerAttribute)} is not supported by this {nameof(TokenType)}.");
|
|
}
|
|
}
|
|
}
|
|
}
|