mirror of
https://github.com/RPCS3/discord-bot.git
synced 2026-01-31 01:25:22 +01:00
relax some permissions for context menus
This commit is contained in:
@@ -11,14 +11,17 @@ internal abstract class CheckAttributeWithReactions(
|
||||
public DiscordEmoji? ReactOnFailure { get; } = reactOnFailure;
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
|
||||
internal class RequiresBotModRoleAttribute(): CheckAttributeWithReactions(reactOnFailure: Config.Reactions.Denied);
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
|
||||
internal class RequiresBotSudoerRoleAttribute(): CheckAttributeWithReactions(reactOnFailure: Config.Reactions.Denied);
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
|
||||
internal class RequiresSupporterRoleAttribute(): CheckAttributeWithReactions(reactOnFailure: Config.Reactions.Denied);
|
||||
internal class RequiresBotModRoleAttribute(): CheckAttributeWithReactions(reactOnFailure: Config.Reactions.Denied);
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
|
||||
internal class RequiresWhitelistedRoleAttribute(): CheckAttributeWithReactions(reactOnFailure: Config.Reactions.Denied);
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
|
||||
internal class RequiresSmartlistedRoleAttribute(): CheckAttributeWithReactions(reactOnFailure: Config.Reactions.Denied);
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
|
||||
internal class RequiresSupporterRoleAttribute(): CheckAttributeWithReactions(reactOnFailure: Config.Reactions.Denied);
|
||||
|
||||
@@ -5,10 +5,11 @@ using DSharpPlus.Commands.Processors.TextCommands;
|
||||
namespace CompatBot.Commands.Checks;
|
||||
|
||||
internal class RequiredRoleContextCheck:
|
||||
IContextCheck<RequiresBotModRoleAttribute>,
|
||||
IContextCheck<RequiresBotSudoerRoleAttribute>,
|
||||
IContextCheck<RequiresSupporterRoleAttribute>,
|
||||
IContextCheck<RequiresWhitelistedRoleAttribute>
|
||||
IContextCheck<RequiresBotModRoleAttribute>,
|
||||
IContextCheck<RequiresWhitelistedRoleAttribute>,
|
||||
IContextCheck<RequiresSmartlistedRoleAttribute>,
|
||||
IContextCheck<RequiresSupporterRoleAttribute>
|
||||
{
|
||||
private async ValueTask<string?> CheckAsync<T>(T attr, CommandContext ctx, bool isAllowed)
|
||||
where T: CheckAttributeWithReactions
|
||||
@@ -29,19 +30,16 @@ internal class RequiredRoleContextCheck:
|
||||
}
|
||||
}
|
||||
|
||||
public ValueTask<string?> ExecuteCheckAsync(RequiresBotModRoleAttribute attr, CommandContext ctx)
|
||||
=> CheckAsync(attr, ctx, ModProvider.IsMod(ctx.User.Id));
|
||||
|
||||
public async ValueTask<string?> ExecuteCheckAsync(RequiresBotSudoerRoleAttribute attr, CommandContext ctx)
|
||||
{
|
||||
var isAllowed = await ctx.User.IsModeratorAsync(ctx.Client, ctx.Guild).ConfigureAwait(false);
|
||||
return await CheckAsync(attr, ctx, isAllowed).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async ValueTask<string?> ExecuteCheckAsync(RequiresSupporterRoleAttribute attr, CommandContext ctx)
|
||||
public async ValueTask<string?> ExecuteCheckAsync(RequiresBotModRoleAttribute attr, CommandContext ctx)
|
||||
{
|
||||
var isAllowed = await ctx.User.IsWhitelistedAsync(ctx.Client, ctx.Guild).ConfigureAwait(false)
|
||||
|| await ctx.User.IsSupporterAsync(ctx.Client, ctx.Guild).ConfigureAwait(false);
|
||||
var isAllowed = await ctx.User.IsModeratorAsync(ctx.Client, ctx.Guild).ConfigureAwait(false)
|
||||
|| ModProvider.IsMod(ctx.User.Id);
|
||||
return await CheckAsync(attr, ctx, isAllowed).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -50,4 +48,19 @@ internal class RequiredRoleContextCheck:
|
||||
var isAllowed = await ctx.User.IsWhitelistedAsync(ctx.Client, ctx.Guild).ConfigureAwait(false);
|
||||
return await CheckAsync(attr, ctx, isAllowed).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async ValueTask<string?> ExecuteCheckAsync(RequiresSmartlistedRoleAttribute attr, CommandContext ctx)
|
||||
{
|
||||
var isAllowed = await ctx.User.IsWhitelistedAsync(ctx.Client, ctx.Guild).ConfigureAwait(false)
|
||||
|| await ctx.User.IsSmartlistedAsync(ctx.Client, ctx.Guild).ConfigureAwait(false);
|
||||
return await CheckAsync(attr, ctx, isAllowed).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async ValueTask<string?> ExecuteCheckAsync(RequiresSupporterRoleAttribute attr, CommandContext ctx)
|
||||
{
|
||||
var isAllowed = await ctx.User.IsWhitelistedAsync(ctx.Client, ctx.Guild).ConfigureAwait(false)
|
||||
|| await ctx.User.IsSmartlistedAsync(ctx.Client, ctx.Guild).ConfigureAwait(false)
|
||||
|| await ctx.User.IsSupporterAsync(ctx.Client, ctx.Guild).ConfigureAwait(false);
|
||||
return await CheckAsync(attr, ctx, isAllowed).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ internal static class MessageMenuCommands
|
||||
}
|
||||
|
||||
// non-whitenames can use these
|
||||
[Command("👮 Report to mods"), RequiresWhitelistedRole, SlashCommandTypes(DiscordApplicationCommandType.MessageContextMenu)]
|
||||
[Command("👮 Report to mods"), RequiresSupporterRole, SlashCommandTypes(DiscordApplicationCommandType.MessageContextMenu)]
|
||||
public static async ValueTask Report(MessageCommandContext ctx, DiscordMessage message)
|
||||
{
|
||||
try
|
||||
@@ -111,7 +111,7 @@ internal static class MessageMenuCommands
|
||||
}
|
||||
}
|
||||
|
||||
[Command("🔍 Analyze log"), RequiresWhitelistedRole, SlashCommandTypes(DiscordApplicationCommandType.MessageContextMenu)]
|
||||
[Command("🔍 Analyze log"), RequiresSupporterRole, SlashCommandTypes(DiscordApplicationCommandType.MessageContextMenu)]
|
||||
public static async ValueTask Reanalyze(MessageCommandContext ctx, DiscordMessage message)
|
||||
{
|
||||
try
|
||||
@@ -160,7 +160,7 @@ internal static class MessageMenuCommands
|
||||
*/
|
||||
|
||||
// only bot mods can use this
|
||||
[Command("👎 Toggle bad update"), RequiresBotModRole, SlashCommandTypes(DiscordApplicationCommandType.MessageContextMenu)]
|
||||
[Command("👎 Toggle bad update"), RequiresSmartlistedRole, SlashCommandTypes(DiscordApplicationCommandType.MessageContextMenu)]
|
||||
public static async ValueTask BadUpdate(MessageCommandContext ctx, DiscordMessage message)
|
||||
{
|
||||
if (message.Embeds is not [DiscordEmbed embed]
|
||||
|
||||
Reference in New Issue
Block a user