forked from berichan/SysBot.ACNHOrders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequireSudoAttribute.cs
28 lines (24 loc) · 1.17 KB
/
RequireSudoAttribute.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Threading.Tasks;
using Discord.Commands;
using Discord.WebSocket;
namespace SysBot.ACNHOrders
{
public sealed class RequireSudoAttribute : PreconditionAttribute
{
// Override the CheckPermissions method
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
{
var mgr = Globals.Bot.Config;
if (mgr.CanUseSudo(context.User.Id) || context.User.Id == Globals.Self.Owner || mgr.IgnoreAllPermissions)
return Task.FromResult(PreconditionResult.FromSuccess());
// Check if this user is a Guild User, which is the only context where roles exist
if (context.User is not SocketGuildUser gUser)
return Task.FromResult(PreconditionResult.FromError("You must be in a guild to run this command."));
if (mgr.CanUseSudo(gUser.Id))
return Task.FromResult(PreconditionResult.FromSuccess());
// Since it wasn't, fail
return Task.FromResult(PreconditionResult.FromError("You are not permitted to run this command."));
}
}
}