NadekoBot/NadekoBot.Core/Common/Attributes/OwnerOnlyAttribute.cs

17 lines
675 B
C#
Raw Normal View History

2017-07-17 19:42:36 +00:00
using System;
using System.Threading.Tasks;
using Discord.Commands;
using NadekoBot.Core.Services;
2016-08-20 11:05:57 +00:00
2017-07-17 19:42:36 +00:00
namespace NadekoBot.Common.Attributes
{
public class OwnerOnlyAttribute : PreconditionAttribute
{
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo executingCommand, IServiceProvider services)
2017-05-22 23:59:31 +00:00
{
var creds = (IBotCredentials)services.GetService(typeof(IBotCredentials));
2017-05-24 20:28:16 +00:00
return Task.FromResult((creds.IsOwner(context.User) || context.Client.CurrentUser.Id == context.User.Id ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("Not owner")));
2017-05-22 23:59:31 +00:00
}
}
}