diff --git a/.env.example b/.env.example index a729d73..9d242c9 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ DISCORD_TOKEN= GUILD_ID= DISCORD_CLIENT_ID= -DATABASE_URI= \ No newline at end of file +DATABASE_URI= +MOD_CHANNEL_ID= \ No newline at end of file diff --git a/src/commands/announce.ts b/src/commands/announce.ts index 500554d..bb9390d 100644 --- a/src/commands/announce.ts +++ b/src/commands/announce.ts @@ -6,6 +6,7 @@ import { SlashCommandChannelOption, TextInputBuilder, TextInputStyle, + PermissionFlagsBits, } from "discord.js"; import { Command } from "../interface"; @@ -14,6 +15,7 @@ export default { .setName("announce") .setDescription("announcement the world something") .setDMPermission(false) + .setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages) .addChannelOption((option: SlashCommandChannelOption) => { return option .setName("channel") @@ -25,6 +27,7 @@ export default { option.setName("mention").setDescription("Who to mention").setRequired(false), ) as SlashCommandBuilder, + isMod: true, async execute(interaction) { if (!interaction.guild) return; diff --git a/src/commands/echo.ts b/src/commands/echo.ts index fbe1f73..2c81292 100644 --- a/src/commands/echo.ts +++ b/src/commands/echo.ts @@ -6,6 +6,7 @@ import { SlashCommandChannelOption, TextInputBuilder, TextInputStyle, + PermissionFlagsBits, } from "discord.js"; import { Command } from "../interface"; @@ -14,6 +15,7 @@ export default { .setName("echo") .setDescription("Announce a message to a channel") .setDMPermission(false) + .setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages) .addChannelOption((option: SlashCommandChannelOption) => { return option .setName("channel") @@ -25,6 +27,8 @@ export default { option.setName("mention").setDescription("Who to mention").setRequired(false), ) as SlashCommandBuilder, + isMod: true, + async execute(interaction) { if (!interaction.guild) return; const channelId = (interaction.options.getChannel("channel")?.id || interaction.channelId) as string; diff --git a/src/commands/images.ts b/src/commands/images.ts index 143c3c0..b0d7004 100644 --- a/src/commands/images.ts +++ b/src/commands/images.ts @@ -6,6 +6,7 @@ import { SlashCommandChannelOption, TextInputBuilder, TextInputStyle, + PermissionFlagsBits, } from "discord.js"; import { Command } from "../interface"; @@ -14,6 +15,7 @@ export default { .setName("images") .setDescription("send images") .setDMPermission(false) + .setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages) .addChannelOption((option: SlashCommandChannelOption) => { return option .setName("channel") @@ -22,6 +24,8 @@ export default { .addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement); }) as SlashCommandBuilder, + isMod: true, + async execute(interaction) { if (!interaction.guild) return; const channelId = (interaction.options.getChannel("channel")?.id || interaction.channelId) as string; diff --git a/src/commands/ping.ts b/src/commands/ping.ts index 9b94701..4192459 100644 --- a/src/commands/ping.ts +++ b/src/commands/ping.ts @@ -4,6 +4,8 @@ import { Command } from "../interface"; export default { data: new SlashCommandBuilder().setName("ping").setDescription("Replies with Pong!").setDMPermission(false), + isMod: true, + async execute(interaction) { const message = await interaction.reply({ content: "Pong!", fetchReply: true }); await interaction.editReply(`Pong! Latency is ${Math.abs(Date.now() - message.createdTimestamp)}ms.`); diff --git a/src/commands/template.ts b/src/commands/template.ts index cd02915..ee4fd5a 100644 --- a/src/commands/template.ts +++ b/src/commands/template.ts @@ -7,6 +7,7 @@ import { StringSelectMenuBuilder, SlashCommandSubcommandBuilder, ChannelType, + PermissionFlagsBits, } from "discord.js"; import { Command } from "../interface"; import db from "../utils/database"; @@ -16,6 +17,7 @@ export default { .setName("template") .setDescription("provides us with the templates") .setDMPermission(false) + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) .addSubcommand((subcommand: SlashCommandSubcommandBuilder) => subcommand.setName("create").setDescription("Creates Templates"), ) @@ -35,6 +37,8 @@ export default { subcommand.setName("delete").setDescription("Deletes the Templates"), ) as SlashCommandBuilder, + isMod: true, + async execute(interaction) { if (!interaction.guild) return; const subcommand = interaction.options.getSubcommand(); diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 42b789c..3286980 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -14,15 +14,27 @@ export default { await interaction.reply({ content: "Command not found", ephemeral: true }); return; } + if (command.isMod) { + const interactionChannelId = interaction.channelId; + const envChannelId = process.env.CHANNEL_ID; - try { - command.execute(interaction); - } catch (err) { - console.error(err); - await interaction.reply({ - content: "There was an error while executing this command!", - ephemeral: true, - }); + if (interactionChannelId !== envChannelId) { + await interaction.reply({ + content: "This command can only be executed in a specific channel.", + ephemeral: true, + }); + return; + } + + try { + command.execute(interaction); + } catch (err) { + console.error(err); + await interaction.reply({ + content: "There was an error while executing this command!", + ephemeral: true, + }); + } } }, }; diff --git a/src/interface/command.ts b/src/interface/command.ts index 27cc638..16d3bd7 100644 --- a/src/interface/command.ts +++ b/src/interface/command.ts @@ -2,6 +2,7 @@ import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js"; export interface Command { data: SlashCommandBuilder; + isMod: boolean; execute(interaction: ChatInputCommandInteraction): void; }