Skip to content

Commit

Permalink
fix(ClientPermissions): check app permissions when used with user apps (
Browse files Browse the repository at this point in the history
#797)

Co-authored-by: Aura <kyradiscord@gmail.com>
Co-authored-by: Jeroen Claassens <support@favware.tech>
  • Loading branch information
3 people authored Nov 4, 2024
1 parent d38fac0 commit ebdf0f7
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/preconditions/ClientPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ export class CorePrecondition extends AllFlowsPrecondition {
): AllFlowsPrecondition.AsyncResult {
const required = context.permissions ?? new PermissionsBitField();

const channel = await this.fetchChannelFromInteraction(interaction);
const availablePermissions = await this.getAvailablePermissions(interaction);

const permissions = await this.getPermissionsForChannel(channel, interaction);

return this.sharedRun(required, permissions, 'chat input');
return this.sharedRun(required, availablePermissions, 'chat input');
}

public async contextMenuRun(
Expand All @@ -69,11 +67,9 @@ export class CorePrecondition extends AllFlowsPrecondition {
): AllFlowsPrecondition.AsyncResult {
const required = context.permissions ?? new PermissionsBitField();

const channel = await this.fetchChannelFromInteraction(interaction);

const permissions = await this.getPermissionsForChannel(channel, interaction);
const availablePermissions = await this.getAvailablePermissions(interaction);

return this.sharedRun(required, permissions, 'context menu');
return this.sharedRun(required, availablePermissions, 'context menu');
}

private async getPermissionsForChannel(channel: TextBasedChannel, messageOrInteraction: Message | BaseInteraction) {
Expand Down Expand Up @@ -113,6 +109,17 @@ export class CorePrecondition extends AllFlowsPrecondition {
});
}

private async getAvailablePermissions(interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction) {
if (interaction.channel) {
if (interaction.channel.isDMBased()) return this.dmChannelPermissions;

const channel = await this.fetchChannelFromInteraction(interaction);
return this.getPermissionsForChannel(channel, interaction);
}

return interaction.appPermissions;
}

public static readonly readablePermissions: Record<PermissionsString, string> = {
AddReactions: 'Add Reactions',
Administrator: 'Administrator',
Expand Down

0 comments on commit ebdf0f7

Please sign in to comment.