mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-11-02 15:59:50 +01:00
feat(arabot): add preconditions for sus
This commit is contained in:
parent
8ab25c6a48
commit
f9deff2def
@ -27,6 +27,7 @@ export class SusCommand extends Command {
|
||||
super(context, {
|
||||
name: 'sus',
|
||||
description: 'Notes about users that are sus',
|
||||
preconditions: ['ModOnly', 'VerifierOnly'],
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
51
src/preconditions/ModOnly.ts
Normal file
51
src/preconditions/ModOnly.ts
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
51
src/preconditions/VerifierOnly.ts
Normal file
51
src/preconditions/VerifierOnly.ts
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user