Skip to content

Commit

Permalink
Merge pull request #5 from edgedb/only-moderators-can-run-cmds
Browse files Browse the repository at this point in the history
Only moderators can run commands
  • Loading branch information
diksipav authored Oct 7, 2024
2 parents aae17a6 + e07de71 commit 7aac8df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
24 changes: 19 additions & 5 deletions app/lib/discord/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class Bot extends REST {
super(options);

this.applicationId = getEnvironment().discordClientId;

this.edgedb = edgedb;
this.token = token;
this.setToken(this.token);
Expand All @@ -57,6 +56,19 @@ export class Bot extends REST {
processInteraction(
interaction: APIBaseInteraction<InteractionType, any>
): InteractionPromise {
if (
!interaction?.member?.roles.some((role) =>
getEnvironment().authorizedRoleIds.includes(role)
)
) {
return InteractionPromise.resolve(
this.errorResponse(
`You do not have permission to run this command`,
true
)
);
}

switch (interaction.type) {
case InteractionType.ApplicationCommand:
const command = interaction as APIBaseInteraction<
Expand All @@ -65,16 +77,18 @@ export class Bot extends REST {
>;

if (!command.data) {
console.error("No command data found");
return InteractionPromise.resolve(this.errorResponse());
return InteractionPromise.resolve(
this.errorResponse("No command data found", true)
);
}

const handler = this.commands.get(command.data.name);
//map is empty
if (!handler) {
return InteractionPromise.resolve(
this.errorResponse(
`No command found with the name \`${command.data.name}\``
`No command found with the name \`${command.data.name}\``,
true
)
);
}
Expand All @@ -93,7 +107,7 @@ export class Bot extends REST {
});
default:
return InteractionPromise.resolve(
this.errorResponse("Unhandled or unimplemented action")
this.errorResponse("Unhandled or unimplemented action", true)
);
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/lib/discord/commands/helpful.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export default class HelpfulCommand
`${threadChannel.parent_id}, ${bot["help-channels"].size}, ${ids}}`
),
],
flags: MessageFlags.Ephemeral,
},
});
}
Expand All @@ -107,6 +108,7 @@ export default class HelpfulCommand
embeds: [
bot.errorEmbed("This thread has already been marked as helpful!"),
],
flags: MessageFlags.Ephemeral,
});
return;
}
Expand Down Expand Up @@ -137,6 +139,7 @@ export default class HelpfulCommand

await bot.editReply(interaction, {
content: "Your feedback has been recorded! Thank you!",
flags: MessageFlags.Ephemeral,
});
}
}

0 comments on commit 7aac8df

Please sign in to comment.