move admin check to ContextChecksExt, allow pk;debug proxy for staff in support server
This commit is contained in:
parent
94f4f970ea
commit
fa66fbe247
@ -1,3 +1,7 @@
|
|||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
using Autofac;
|
||||||
|
|
||||||
using Myriad.Types;
|
using Myriad.Types;
|
||||||
|
|
||||||
using PluralKit.Core;
|
using PluralKit.Core;
|
||||||
@ -52,5 +56,19 @@ namespace PluralKit.Bot
|
|||||||
throw new PKError($"You must have the \"{permissionName}\" permission in this server to use this command.");
|
throw new PKError($"You must have the \"{permissionName}\" permission in this server to use this command.");
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool CheckBotAdmin(this Context ctx)
|
||||||
|
{
|
||||||
|
var botConfig = ctx.Services.Resolve<BotConfig>();
|
||||||
|
return botConfig.AdminRole != null && ctx.Member != null && ctx.Member.Roles.Contains(botConfig.AdminRole.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Context AssertBotAdmin(this Context ctx)
|
||||||
|
{
|
||||||
|
if (!ctx.CheckBotAdmin())
|
||||||
|
throw new PKError("This command is only usable by bot admins.");
|
||||||
|
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,7 +21,7 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
public async Task UpdateSystemId(Context ctx)
|
public async Task UpdateSystemId(Context ctx)
|
||||||
{
|
{
|
||||||
AssertBotAdmin(ctx);
|
ctx.AssertBotAdmin();
|
||||||
|
|
||||||
var target = await ctx.MatchSystem();
|
var target = await ctx.MatchSystem();
|
||||||
if (target == null)
|
if (target == null)
|
||||||
@ -44,7 +44,7 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
public async Task UpdateMemberId(Context ctx)
|
public async Task UpdateMemberId(Context ctx)
|
||||||
{
|
{
|
||||||
AssertBotAdmin(ctx);
|
ctx.AssertBotAdmin();
|
||||||
|
|
||||||
var target = await ctx.MatchMember();
|
var target = await ctx.MatchMember();
|
||||||
if (target == null)
|
if (target == null)
|
||||||
@ -67,7 +67,7 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
public async Task UpdateGroupId(Context ctx)
|
public async Task UpdateGroupId(Context ctx)
|
||||||
{
|
{
|
||||||
AssertBotAdmin(ctx);
|
ctx.AssertBotAdmin();
|
||||||
|
|
||||||
var target = await ctx.MatchGroup();
|
var target = await ctx.MatchGroup();
|
||||||
if (target == null)
|
if (target == null)
|
||||||
@ -90,7 +90,7 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
public async Task SystemMemberLimit(Context ctx)
|
public async Task SystemMemberLimit(Context ctx)
|
||||||
{
|
{
|
||||||
AssertBotAdmin(ctx);
|
ctx.AssertBotAdmin();
|
||||||
|
|
||||||
var target = await ctx.MatchSystem();
|
var target = await ctx.MatchSystem();
|
||||||
if (target == null)
|
if (target == null)
|
||||||
@ -120,7 +120,7 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
public async Task SystemGroupLimit(Context ctx)
|
public async Task SystemGroupLimit(Context ctx)
|
||||||
{
|
{
|
||||||
AssertBotAdmin(ctx);
|
ctx.AssertBotAdmin();
|
||||||
|
|
||||||
var target = await ctx.MatchSystem();
|
var target = await ctx.MatchSystem();
|
||||||
if (target == null)
|
if (target == null)
|
||||||
@ -147,16 +147,5 @@ namespace PluralKit.Bot
|
|||||||
});
|
});
|
||||||
await ctx.Reply($"{Emojis.Success} Group limit updated.");
|
await ctx.Reply($"{Emojis.Success} Group limit updated.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AssertBotAdmin(Context ctx)
|
|
||||||
{
|
|
||||||
if (!IsBotAdmin(ctx))
|
|
||||||
throw new PKError("This command is only usable by bot admins.");
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsBotAdmin(Context ctx)
|
|
||||||
{
|
|
||||||
return _botConfig.AdminRole != null && ctx.Member.Roles.Contains(_botConfig.AdminRole.Value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -263,10 +263,12 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
if ((_botConfig.Prefixes ?? BotConfig.DefaultPrefixes).Any(p => msg.Content.StartsWith(p)))
|
if ((_botConfig.Prefixes ?? BotConfig.DefaultPrefixes).Any(p => msg.Content.StartsWith(p)))
|
||||||
await ctx.Reply("This message starts with the bot's prefix, and was parsed as a command.");
|
await ctx.Reply("This message starts with the bot's prefix, and was parsed as a command.");
|
||||||
|
if (msg.Author.Bot)
|
||||||
|
throw new PKError("You cannot check messages sent by a bot.");
|
||||||
if (msg.WebhookId != null)
|
if (msg.WebhookId != null)
|
||||||
await ctx.Reply("You cannot check messages sent by a webhook.");
|
throw new PKError("You cannot check messages sent by a webhook.");
|
||||||
if (msg.Author.Id != ctx.Author.Id)
|
if (msg.Author.Id != ctx.Author.Id && !ctx.CheckBotAdmin())
|
||||||
await ctx.Reply("You can only check your own messages.");
|
throw new PKError("You can only check your own messages.");
|
||||||
|
|
||||||
// get the channel info
|
// get the channel info
|
||||||
var channel = _cache.GetChannel(channelId.Value);
|
var channel = _cache.GetChannel(channelId.Value);
|
||||||
|
Loading…
Reference in New Issue
Block a user