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

17 lines
665 B
C#
Raw Normal View History

2017-07-17 19:42:36 +00:00
using System;
using System.Threading.Tasks;
using Discord.Commands;
2017-05-22 23:59:31 +00:00
using NadekoBot.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
{
2017-05-22 23:59:31 +00:00
public override Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo executingCommand, IServiceProvider services)
{
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
}
}
}