From c82d256be4099586daabdc0c390a13ac44c85f6d Mon Sep 17 00:00:00 2001 From: Anthony Berg Date: Tue, 13 Feb 2024 19:31:49 +0000 Subject: [PATCH] refactor(arabot): change outreach command for outreach leader only --- src/commands/outreach/outreach.ts | 11 +++-- src/preconditions/OutreachLeaderOnly.ts | 58 +++++++++++++++++++++++++ src/utils/devIDs.ts | 1 + src/utils/ids.ts | 1 + 4 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 src/preconditions/OutreachLeaderOnly.ts diff --git a/src/commands/outreach/outreach.ts b/src/commands/outreach/outreach.ts index 58424e7..d32d142 100644 --- a/src/commands/outreach/outreach.ts +++ b/src/commands/outreach/outreach.ts @@ -66,7 +66,6 @@ export class OutreachCommand extends Subcommand { ], }, ], - preconditions: ['ModOnly'], }); } @@ -200,13 +199,13 @@ export class OutreachCommand extends Subcommand { if (mod === undefined) { await interaction.reply({ - content: 'Mod was not found!', + content: 'Outreach Leader was not found!', ephemeral: true, }); return; } - if (!mod.roles.cache.has(IDs.roles.staff.outreachCoordinator)) { + if (!mod.roles.cache.has(IDs.roles.staff.outreachLeader)) { await interaction.reply({ content: 'You need to be an Outreach Coordinator to run this command!', ephemeral: true, @@ -254,9 +253,9 @@ export class OutreachCommand extends Subcommand { return; } - if (!mod.roles.cache.has(IDs.roles.staff.outreachCoordinator)) { + if (!mod.roles.cache.has(IDs.roles.staff.outreachLeader)) { await interaction.reply({ - content: 'You need to be an Outreach Coordinator to run this command!', + content: 'You need to be an Outreach Leader to run this command!', ephemeral: true, }); return; @@ -442,7 +441,7 @@ export class OutreachCommand extends Subcommand { if ( leader.id !== stat.stat.leaderId && - !leaderMember.roles.cache.has(IDs.roles.staff.outreachCoordinator) + !leaderMember.roles.cache.has(IDs.roles.staff.outreachLeader) ) { await interaction.editReply({ content: `You are not the leader for ${group}`, diff --git a/src/preconditions/OutreachLeaderOnly.ts b/src/preconditions/OutreachLeaderOnly.ts new file mode 100644 index 0000000..7de74b3 --- /dev/null +++ b/src/preconditions/OutreachLeaderOnly.ts @@ -0,0 +1,58 @@ +// 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, + ContextMenuCommandInteraction, + Message, + GuildMember, +} from 'discord.js'; +import IDs from '#utils/ids'; + +export class OutreachLeaderOnlyPrecondition extends AllFlowsPrecondition { + public override async messageRun(message: Message) { + // for message command + return this.checkCoordinator(message.member!); + } + + public override async chatInputRun(interaction: CommandInteraction) { + // for slash command + return this.checkCoordinator(interaction.member! as GuildMember); + } + + public override async contextMenuRun( + interaction: ContextMenuCommandInteraction, + ) { + // for context menu command + return this.checkCoordinator(interaction.member! as GuildMember); + } + + private async checkCoordinator(user: GuildMember) { + return user.roles.cache.has(IDs.roles.staff.outreachLeader) + ? this.ok() + : this.error({ message: 'Only outreach leaders can run this command!' }); + } +} + +declare module '@sapphire/framework' { + interface Preconditions { + OutreachLeaderOnly: never; + } +} diff --git a/src/utils/devIDs.ts b/src/utils/devIDs.ts index 32f61cf..087eb24 100644 --- a/src/utils/devIDs.ts +++ b/src/utils/devIDs.ts @@ -60,6 +60,7 @@ const devIDs = { outreachCoordinator: '999431675140382807', mediaCoordinator: '1204801056404676618', hrCoordinator: '1204795893480431657', + outreachLeader: '999431675123597409', restricted: '999431675123597407', moderator: '999431675123597408', trialModerator: '999431675123597404', diff --git a/src/utils/ids.ts b/src/utils/ids.ts index 2a062e8..456e13a 100644 --- a/src/utils/ids.ts +++ b/src/utils/ids.ts @@ -62,6 +62,7 @@ let IDs = { outreachCoordinator: '954804769476730890', mediaCoordinator: '1203778509449723914', hrCoordinator: '1203802120180989993', + outreachLeader: '730915698544607232', restricted: '851624392928264222', moderator: '826157475815489598', trialModerator: '982074555596152904',