2021-01-31 14:03:11 +00:00
|
|
|
|
using Myriad.Types;
|
2020-12-22 15:55:13 +00:00
|
|
|
|
|
2020-07-01 16:18:38 +00:00
|
|
|
|
using PluralKit.Core;
|
|
|
|
|
|
|
|
|
|
namespace PluralKit.Bot
|
|
|
|
|
{
|
2020-07-01 16:27:26 +00:00
|
|
|
|
public static class ContextChecksExt
|
2020-07-01 16:18:38 +00:00
|
|
|
|
{
|
|
|
|
|
public static Context CheckGuildContext(this Context ctx)
|
|
|
|
|
{
|
2020-12-22 15:55:13 +00:00
|
|
|
|
if (ctx.ChannelNew.GuildId != null) return ctx;
|
2020-07-01 16:18:38 +00:00
|
|
|
|
throw new PKError("This command can not be run in a DM.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Context CheckSystemPrivacy(this Context ctx, PKSystem target, PrivacyLevel level)
|
|
|
|
|
{
|
|
|
|
|
if (level.CanAccess(ctx.LookupContextFor(target))) return ctx;
|
|
|
|
|
throw new PKError("You do not have permission to access this information.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Context CheckOwnMember(this Context ctx, PKMember member)
|
|
|
|
|
{
|
|
|
|
|
if (member.System != ctx.System?.Id)
|
|
|
|
|
throw Errors.NotOwnMemberError;
|
2020-07-06 17:50:39 +00:00
|
|
|
|
return ctx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Context CheckOwnGroup(this Context ctx, PKGroup group)
|
|
|
|
|
{
|
|
|
|
|
if (group.System != ctx.System?.Id)
|
2020-08-16 10:10:54 +00:00
|
|
|
|
throw Errors.NotOwnGroupError;
|
2020-07-01 16:18:38 +00:00
|
|
|
|
return ctx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Context CheckSystem(this Context ctx)
|
|
|
|
|
{
|
|
|
|
|
if (ctx.System == null)
|
|
|
|
|
throw Errors.NoSystemError;
|
|
|
|
|
return ctx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Context CheckNoSystem(this Context ctx)
|
|
|
|
|
{
|
|
|
|
|
if (ctx.System != null)
|
|
|
|
|
throw Errors.ExistingSystemError;
|
|
|
|
|
return ctx;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-22 15:55:13 +00:00
|
|
|
|
public static Context CheckAuthorPermission(this Context ctx, PermissionSet neededPerms, string permissionName)
|
2020-07-01 16:18:38 +00:00
|
|
|
|
{
|
2020-12-22 15:55:13 +00:00
|
|
|
|
if ((ctx.UserPermissions & neededPerms) != neededPerms)
|
2020-07-01 16:18:38 +00:00
|
|
|
|
throw new PKError($"You must have the \"{permissionName}\" permission in this server to use this command.");
|
|
|
|
|
return ctx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|