diff --git a/src/commands/mod/sus.ts b/src/commands/mod/sus.ts index f652ff1..e0b52e2 100644 --- a/src/commands/mod/sus.ts +++ b/src/commands/mod/sus.ts @@ -27,6 +27,7 @@ export class SusCommand extends Command { super(context, { name: 'sus', description: 'Notes about users that are sus', + preconditions: ['ModOnly', 'VerifierOnly'], }); } diff --git a/src/preconditions/ModOnly.ts b/src/preconditions/ModOnly.ts new file mode 100644 index 0000000..b6cc1d3 --- /dev/null +++ b/src/preconditions/ModOnly.ts @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +/* + Animal Rights Advocates Discord Bot + Copyright (C) 2022 Anthony Berg + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +import { AllFlowsPrecondition } from '@sapphire/framework'; +import type { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'; +import { IDs } from '../utils/ids'; + +export class ModOnlyPrecondition extends AllFlowsPrecondition { + public override async messageRun(message: Message) { + // for message command + return this.checkMod(message.author.id); + } + + public override async chatInputRun(interaction: CommandInteraction) { + // for slash command + return this.checkMod(interaction.user.id); + } + + public override async contextMenuRun(interaction: ContextMenuInteraction) { + // for context menu command + return this.checkMod(interaction.user.id); + } + + private async checkMod(userId: string) { + return userId === IDs.roles.staff.moderator + ? this.ok() + : this.error({ message: 'Only moderators can run this command!' }); + } +} + +declare module '@sapphire/framework' { + interface Preconditions { + ModOnly: never; + } +} diff --git a/src/preconditions/VerifierOnly.ts b/src/preconditions/VerifierOnly.ts new file mode 100644 index 0000000..8aba2d2 --- /dev/null +++ b/src/preconditions/VerifierOnly.ts @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +/* + Animal Rights Advocates Discord Bot + Copyright (C) 2022 Anthony Berg + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +import { AllFlowsPrecondition } from '@sapphire/framework'; +import type { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'; +import { IDs } from '../utils/ids'; + +export class VerifierOnlyPrecondition extends AllFlowsPrecondition { + public override async messageRun(message: Message) { + // for message command + return this.checkVerifier(message.author.id); + } + + public override async chatInputRun(interaction: CommandInteraction) { + // for slash command + return this.checkVerifier(interaction.user.id); + } + + public override async contextMenuRun(interaction: ContextMenuInteraction) { + // for context menu command + return this.checkVerifier(interaction.user.id); + } + + private async checkVerifier(userId: string) { + return userId === IDs.roles.staff.verifier + ? this.ok() + : this.error({ message: 'Only verifiers can run this command!' }); + } +} + +declare module '@sapphire/framework' { + interface Preconditions { + VerifierOnly: never; + } +}