mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-18 13:24:14 +02:00
fix(arabot): change precondition to look for roles and change precondition in sus from and to or
This commit is contained in:
parent
2259533bf8
commit
f369c2f108
@ -48,6 +48,7 @@ export class HugCommand extends Command {
|
||||
// Command run
|
||||
public async chatInputRun(interaction: Command.ChatInputInteraction) {
|
||||
// Get the users
|
||||
// TODO exception handling
|
||||
const user = interaction.options.getUser('user')!;
|
||||
const hugger = interaction.member!.user;
|
||||
const huggerGuildMember = interaction.guild!.members.cache.get(hugger.id)!;
|
||||
|
@ -27,7 +27,7 @@ export class SusCommand extends Command {
|
||||
super(context, {
|
||||
name: 'sus',
|
||||
description: 'Notes about users that are sus',
|
||||
preconditions: ['ModOnly', 'VerifierOnly'],
|
||||
preconditions: [['ModOnly', 'VerifierOnly']],
|
||||
});
|
||||
}
|
||||
|
||||
@ -83,6 +83,7 @@ export class SusCommand extends Command {
|
||||
// Subcommand to add sus note
|
||||
public async addNote(interaction: Command.ChatInputInteraction) {
|
||||
// Get the arguments
|
||||
// TODO exception handling
|
||||
const user = interaction.options.getUser('user')!;
|
||||
const mod = interaction.member!.user;
|
||||
const note = interaction.options.getString('note')!;
|
||||
@ -90,6 +91,7 @@ export class SusCommand extends Command {
|
||||
// Add the data to the database
|
||||
|
||||
// Check if the user exists on the database
|
||||
// TODO exception handling
|
||||
const userGuildMember = interaction.guild!.members.cache.get(user.id)!;
|
||||
if (!await userExists(userGuildMember)) {
|
||||
await addExistingUser(userGuildMember);
|
||||
@ -99,7 +101,6 @@ export class SusCommand extends Command {
|
||||
if (!await userExists(modGuildMember)) {
|
||||
await addExistingUser(modGuildMember);
|
||||
}
|
||||
// TODO check if user is on the database and if not, add them to the database
|
||||
await addToDatabase(user.id, mod.id, note);
|
||||
|
||||
await interaction.reply({
|
||||
@ -116,6 +117,7 @@ export class SusCommand extends Command {
|
||||
const notes = await findNote(user.id, true);
|
||||
// Gets the username of the mod
|
||||
const modId = notes[notes.length - 1].modId;
|
||||
// TODO exception handling
|
||||
const mod = interaction.guild!.members.cache.get(modId)!.user.username;
|
||||
|
||||
// Creates the embed to display the sus note
|
||||
|
@ -20,25 +20,26 @@
|
||||
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 ModOnlyPrecondition extends AllFlowsPrecondition {
|
||||
public override async messageRun(message: Message) {
|
||||
// for message command
|
||||
return this.checkMod(message.author.id);
|
||||
return this.checkMod(message.member!);
|
||||
}
|
||||
|
||||
public override async chatInputRun(interaction: CommandInteraction) {
|
||||
// for slash command
|
||||
return this.checkMod(interaction.user.id);
|
||||
return this.checkMod(interaction.member! as GuildMember);
|
||||
}
|
||||
|
||||
public override async contextMenuRun(interaction: ContextMenuInteraction) {
|
||||
// for context menu command
|
||||
return this.checkMod(interaction.user.id);
|
||||
return this.checkMod(interaction.member! as GuildMember);
|
||||
}
|
||||
|
||||
private async checkMod(userId: string) {
|
||||
return userId === IDs.roles.staff.moderator
|
||||
private async checkMod(user: GuildMember) {
|
||||
return user.roles.cache.has(IDs.roles.staff.moderator)
|
||||
? this.ok()
|
||||
: this.error({ message: 'Only moderators can run this command!' });
|
||||
}
|
||||
|
52
src/preconditions/PatreonOnly.ts
Normal file
52
src/preconditions/PatreonOnly.ts
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 PatreonOnlyPrecondition extends AllFlowsPrecondition {
|
||||
public override async messageRun(message: Message) {
|
||||
// for message command
|
||||
return this.checkPatreon(message.member!);
|
||||
}
|
||||
|
||||
public override async chatInputRun(interaction: CommandInteraction) {
|
||||
// for slash command
|
||||
return this.checkPatreon(interaction.member! as GuildMember);
|
||||
}
|
||||
|
||||
public override async contextMenuRun(interaction: ContextMenuInteraction) {
|
||||
// for context menu command
|
||||
return this.checkPatreon(interaction.member! as GuildMember);
|
||||
}
|
||||
|
||||
private async checkPatreon(user: GuildMember) {
|
||||
return user.roles.cache.has(IDs.roles.patron)
|
||||
? this.ok()
|
||||
: this.error({ message: 'Only Patreon members can run this command!' });
|
||||
}
|
||||
}
|
||||
|
||||
declare module '@sapphire/framework' {
|
||||
interface Preconditions {
|
||||
PatreonOnly: never;
|
||||
}
|
||||
}
|
@ -20,25 +20,26 @@
|
||||
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 VerifierOnlyPrecondition extends AllFlowsPrecondition {
|
||||
public override async messageRun(message: Message) {
|
||||
// for message command
|
||||
return this.checkVerifier(message.author.id);
|
||||
return this.checkVerifier(message.member!);
|
||||
}
|
||||
|
||||
public override async chatInputRun(interaction: CommandInteraction) {
|
||||
// for slash command
|
||||
return this.checkVerifier(interaction.user.id);
|
||||
return this.checkVerifier(interaction.member! as GuildMember);
|
||||
}
|
||||
|
||||
public override async contextMenuRun(interaction: ContextMenuInteraction) {
|
||||
// for context menu command
|
||||
return this.checkVerifier(interaction.user.id);
|
||||
return this.checkVerifier(interaction.member! as GuildMember);
|
||||
}
|
||||
|
||||
private async checkVerifier(userId: string) {
|
||||
return userId === IDs.roles.staff.verifier
|
||||
private async checkVerifier(user: GuildMember) {
|
||||
return user.roles.cache.has(IDs.roles.staff.verifier)
|
||||
? this.ok()
|
||||
: this.error({ message: 'Only verifiers can run this command!' });
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user