From 98b2d6d9041fc158d701ab7fa825b4e02b3c8704 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 30 Jul 2022 02:30:34 +0100 Subject: [PATCH] feat(docs): temporarily gave access to dev coordinators --- src/commands/verification/purgeVerifying.ts | 2 +- src/preconditions/DevCoordinatorOnly.ts | 52 +++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/preconditions/DevCoordinatorOnly.ts diff --git a/src/commands/verification/purgeVerifying.ts b/src/commands/verification/purgeVerifying.ts index 29e6d04..f62d786 100644 --- a/src/commands/verification/purgeVerifying.ts +++ b/src/commands/verification/purgeVerifying.ts @@ -27,7 +27,7 @@ export class purgeVerifyingCommand extends Command { ...options, name: 'purgeverifying', description: 'Purges all the users who have the "verify-as-vegan" role', - preconditions: ['VerifierCoordinatorOnly'], + preconditions: [['DevCoordinatorOnly', 'VerifierCoordinatorOnly']], }); } diff --git a/src/preconditions/DevCoordinatorOnly.ts b/src/preconditions/DevCoordinatorOnly.ts new file mode 100644 index 0000000..6d752e7 --- /dev/null +++ b/src/preconditions/DevCoordinatorOnly.ts @@ -0,0 +1,52 @@ +// 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'; +import type { GuildMember } from 'discord.js'; + +export class DevCoordinatorOnlyPrecondition extends AllFlowsPrecondition { + public override async messageRun(message: Message) { + // for message command + return this.checkDevCoordinator(message.member!); + } + + public override async chatInputRun(interaction: CommandInteraction) { + // for slash command + return this.checkDevCoordinator(interaction.member! as GuildMember); + } + + public override async contextMenuRun(interaction: ContextMenuInteraction) { + // for context menu command + return this.checkDevCoordinator(interaction.member! as GuildMember); + } + + private async checkDevCoordinator(user: GuildMember) { + return user.roles.cache.has(IDs.roles.staff.devCoordinator) + ? this.ok() + : this.error({ message: 'Only dev coordinators can run this command!' }); + } +} + +declare module '@sapphire/framework' { + interface Preconditions { + DevCoordinatorOnly: never; + } +}