Skip to content

Commit

Permalink
fix: Migrate to permission db
Browse files Browse the repository at this point in the history
  • Loading branch information
andyjjrt committed Oct 5, 2024
1 parent 6b4d4c8 commit e550008
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
9 changes: 8 additions & 1 deletion src/commands/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ErrorEmbed, InfoEmbed, SuccessEmbed } from "../utils/Embed";
import { SlashCommandBuilder, PermissionsBitField, ChatInputCommandInteraction } from "discord.js";
import { client } from "../index";
import { Permissions } from "utils/db/schema";
const { MUSIC_DIR, SERVER_IP } = process.env;
const { OWNER_ID } = process.env;

export default {
data: new SlashCommandBuilder()
Expand All @@ -27,6 +27,13 @@ export default {
async execute(interaction: ChatInputCommandInteraction) {
const subcommand = interaction.options.getSubcommand(true);
await interaction.deferReply({ ephemeral: true });
if (OWNER_ID !== interaction.user.id) {
await interaction.followUp({
embeds: [new ErrorEmbed(interaction.client.user, "Error", `You're not bot owner.`)],
ephemeral: true,
});
return;
}
if (subcommand === "refresh") {
const commands = await client.refreshCommands();
await interaction.followUp({
Expand Down
1 change: 1 addition & 0 deletions src/contextmenus/ask_ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ai from "../commands/ai";

export default {
data: new ContextMenuCommandBuilder().setName("Ask AI").setType(ApplicationCommandType.Message),
featureId: "ai",
async execute(interaction: MessageContextMenuCommandInteraction) {
await ai.execute(interaction);
},
Expand Down
30 changes: 19 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,26 @@ client.on(Events.InteractionCreate, async (interaction) => {
logger.error(`No command matching ${interaction.commandName} was found.`);
return;
}
if (context.allowGuilds && context.allowGuilds.indexOf(interaction.guildId) < 0) {
await interaction.reply({
embeds: [
new ErrorEmbed(
interaction.client.user,
"Error",
"This command is not allowed on this server, please contact bot owner."
),
],
ephemeral: true,
if (context.featureId) {
const permission = await Permissions.findOne({
where: {
guildId: interaction.guildId,
featureId: context.featureId,
},
});
return;
if (!permission) {
await interaction.reply({
embeds: [
new ErrorEmbed(
interaction.client.user,
"Error",
"This command is not allowed on this server, please contact bot owner."
),
],
ephemeral: true,
});
return;
}
}
try {
await context.execute(interaction);
Expand Down

0 comments on commit e550008

Please sign in to comment.