Browse Source

Add RequireOwner Precondition

This precondition will require that the invoker of the command is the owner of the bot.
tags/1.0-rc
Christopher F 8 years ago
parent
commit
fdecfe6bd4
1 changed files with 22 additions and 0 deletions
  1. +22
    -0
      src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs

+ 22
- 0
src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Discord;

namespace Discord.Commands
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class RequireOwnerAttribute : PreconditionAttribute
{
private IApplication application;

public override async Task<PreconditionResult> CheckPermissions(CommandContext context, CommandInfo command, IDependencyMap map)
{
if (application == null)
application = await context.Client.GetApplicationInfoAsync();
if (context.User.Id == application.Owner.Id) return PreconditionResult.FromSuccess();
return PreconditionResult.FromError("Command can only be run by the owner of the bot");
}
}
}

Loading…
Cancel
Save