diff --git a/src/commands/roles/stagehost.ts b/src/commands/roles/stagehost.ts new file mode 100644 index 0000000..a4da8d8 --- /dev/null +++ b/src/commands/roles/stagehost.ts @@ -0,0 +1,100 @@ +// 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 { Command, RegisterBehavior } from '@sapphire/framework'; +import IDs from '../../utils/ids'; + +export class StageHostCommand extends Command { + public constructor(context: Command.Context, options: Command.Options) { + super(context, { + ...options, + name: 'stagehost', + description: 'Gives the Stage Host role', + preconditions: ['EventCoordinatorOnly'], + }); + } + + // Registers that this is a slash command + public override registerApplicationCommands(registry: Command.Registry) { + registry.registerChatInputCommand( + (builder) => builder + .setName(this.name) + .setDescription(this.description) + .addUserOption((option) => option.setName('user') + .setDescription('User to give Stage Host to') + .setRequired(true)), + { + behaviorWhenNotIdentical: RegisterBehavior.Overwrite, + }, + ); + } + + // Command run + public async chatInputRun(interaction: Command.ChatInputInteraction) { + // TODO add database updates + // Get the arguments + const user = interaction.options.getUser('user'); + const { guild } = interaction; + + // Checks if all the variables are of the right type + if (user === null || guild === null) { + await interaction.reply({ + content: 'Error fetching user!', + ephemeral: true, + fetchReply: true, + }); + return; + } + + // Gets guildMember whilst removing the ability of each other variables being null + let guildMember = guild!.members.cache.get(user!.id); + let stageHost = guild!.roles.cache.get(IDs.roles.stageHost); + + // Checks if guildMember is null + if (guildMember === null || stageHost === undefined) { + await interaction.reply({ + content: 'Error fetching user!', + ephemeral: true, + fetchReply: true, + }); + return; + } + + // Removes the possibility of guildMember being null + guildMember = guildMember!; + stageHost = stageHost!; + + // Checks if the user has Veg Curious and to give them or remove them based on if they have it + if (guildMember.roles.cache.has(IDs.roles.stageHost)) { + // Remove the Veg Curious role from the user + await guildMember.roles.remove(stageHost); + await interaction.reply({ + content: `Removed the ${stageHost.name} role from ${user!}`, + fetchReply: true, + }); + return; + } + // Add Veg Curious role to the user + await guildMember.roles.add(stageHost); + await interaction.reply({ + content: `Gave ${user!} the ${stageHost.name} role!`, + fetchReply: true, + }); + } +} diff --git a/src/preconditions/CoordinatorOnly.ts b/src/preconditions/CoordinatorOnly.ts index 726a881..c067410 100644 --- a/src/preconditions/CoordinatorOnly.ts +++ b/src/preconditions/CoordinatorOnly.ts @@ -18,9 +18,13 @@ */ import { AllFlowsPrecondition } from '@sapphire/framework'; -import type { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'; +import type { + CommandInteraction, + ContextMenuInteraction, + Message, + GuildMember, +} from 'discord.js'; import IDs from '../utils/ids'; -import type { GuildMember } from 'discord.js'; export class CoordinatorOnlyPrecondition extends AllFlowsPrecondition { public override async messageRun(message: Message) { diff --git a/src/preconditions/DevCoordinatorOnly.ts b/src/preconditions/DevCoordinatorOnly.ts index 13989cd..aeeb3cd 100644 --- a/src/preconditions/DevCoordinatorOnly.ts +++ b/src/preconditions/DevCoordinatorOnly.ts @@ -18,9 +18,13 @@ */ import { AllFlowsPrecondition } from '@sapphire/framework'; -import type { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'; +import type { + CommandInteraction, + ContextMenuInteraction, + Message, + GuildMember, +} 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) { diff --git a/src/preconditions/DiversityCoordinatorOnly.ts b/src/preconditions/DiversityCoordinatorOnly.ts index 09e6e8d..4e3ebbb 100644 --- a/src/preconditions/DiversityCoordinatorOnly.ts +++ b/src/preconditions/DiversityCoordinatorOnly.ts @@ -18,9 +18,13 @@ */ import { AllFlowsPrecondition } from '@sapphire/framework'; -import type { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'; +import type { + CommandInteraction, + ContextMenuInteraction, + Message, + GuildMember, +} from 'discord.js'; import IDs from '../utils/ids'; -import type { GuildMember } from 'discord.js'; export class DiversityCoordinatorOnlyPrecondition extends AllFlowsPrecondition { public override async messageRun(message: Message) { diff --git a/src/preconditions/EventCoordinatorOnly.ts b/src/preconditions/EventCoordinatorOnly.ts new file mode 100644 index 0000000..bdc76e0 --- /dev/null +++ b/src/preconditions/EventCoordinatorOnly.ts @@ -0,0 +1,56 @@ +// 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, + GuildMember, +} from 'discord.js'; +import IDs from '../utils/ids'; + +export class EventCoordinatorOnlyPrecondition extends AllFlowsPrecondition { + public override async messageRun(message: Message) { + // for message command + return this.checkEventCoordinator(message.member!); + } + + public override async chatInputRun(interaction: CommandInteraction) { + // for slash command + return this.checkEventCoordinator(interaction.member! as GuildMember); + } + + public override async contextMenuRun(interaction: ContextMenuInteraction) { + // for context menu command + return this.checkEventCoordinator(interaction.member! as GuildMember); + } + + private async checkEventCoordinator(user: GuildMember) { + return user.roles.cache.has(IDs.roles.staff.eventCoordinator) + ? this.ok() + : this.error({ message: 'Only event coordinators can run this command!' }); + } +} + +declare module '@sapphire/framework' { + interface Preconditions { + EventCoordinatorOnly: never; + } +} diff --git a/src/preconditions/MentorCoordinatorOnly.ts b/src/preconditions/MentorCoordinatorOnly.ts index 514ab54..d0ebf7e 100644 --- a/src/preconditions/MentorCoordinatorOnly.ts +++ b/src/preconditions/MentorCoordinatorOnly.ts @@ -18,9 +18,13 @@ */ import { AllFlowsPrecondition } from '@sapphire/framework'; -import type { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'; +import type { + CommandInteraction, + ContextMenuInteraction, + Message, + GuildMember, +} from 'discord.js'; import IDs from '../utils/ids'; -import type { GuildMember } from 'discord.js'; export class MentorCoordinatorOnlyPrecondition extends AllFlowsPrecondition { public override async messageRun(message: Message) { diff --git a/src/preconditions/ModOnly.ts b/src/preconditions/ModOnly.ts index 8756ad6..3436688 100644 --- a/src/preconditions/ModOnly.ts +++ b/src/preconditions/ModOnly.ts @@ -18,9 +18,13 @@ */ import { AllFlowsPrecondition } from '@sapphire/framework'; -import type { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'; +import type { + CommandInteraction, + ContextMenuInteraction, + Message, + GuildMember, +} 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) { diff --git a/src/preconditions/PatreonOnly.ts b/src/preconditions/PatreonOnly.ts index d44a2b0..54ddc61 100644 --- a/src/preconditions/PatreonOnly.ts +++ b/src/preconditions/PatreonOnly.ts @@ -18,9 +18,13 @@ */ import { AllFlowsPrecondition } from '@sapphire/framework'; -import type { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'; +import type { + CommandInteraction, + ContextMenuInteraction, + Message, + GuildMember, +} 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) { diff --git a/src/preconditions/VerifierCoordinatorOnly.ts b/src/preconditions/VerifierCoordinatorOnly.ts index 61c270a..bf9a347 100644 --- a/src/preconditions/VerifierCoordinatorOnly.ts +++ b/src/preconditions/VerifierCoordinatorOnly.ts @@ -18,9 +18,13 @@ */ import { AllFlowsPrecondition } from '@sapphire/framework'; -import type { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'; +import type { + CommandInteraction, + ContextMenuInteraction, + Message, + GuildMember, +} from 'discord.js'; import IDs from '../utils/ids'; -import type { GuildMember } from 'discord.js'; export class VerifierCoordinatorOnlyPrecondition extends AllFlowsPrecondition { public override async messageRun(message: Message) { diff --git a/src/preconditions/VerifierOnly.ts b/src/preconditions/VerifierOnly.ts index b14a267..e415bd3 100644 --- a/src/preconditions/VerifierOnly.ts +++ b/src/preconditions/VerifierOnly.ts @@ -18,9 +18,13 @@ */ import { AllFlowsPrecondition } from '@sapphire/framework'; -import type { CommandInteraction, ContextMenuInteraction, Message } from 'discord.js'; +import type { + CommandInteraction, + ContextMenuInteraction, + Message, + GuildMember, +} 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) { diff --git a/src/utils/devIDs.ts b/src/utils/devIDs.ts index f4ba1ef..a6ba359 100644 --- a/src/utils/devIDs.ts +++ b/src/utils/devIDs.ts @@ -44,10 +44,12 @@ const devIDs = { diversityCoordinator: '999431675140382808', mentorCoordinator: '999431675140382809', verifierCoordinator: '999431675140382810', + eventCoordinator: '999431675165556817', restricted: '999431675123597407', moderator: '999431675123597408', verifier: '999431675123597406', }, + stageHost: '999431675123597411', patron: '999431675098447935', patreon: '999431675098447936', verifyingAsVegan: '999431675081666597', diff --git a/src/utils/ids.ts b/src/utils/ids.ts index ad4d6e7..87f0b69 100644 --- a/src/utils/ids.ts +++ b/src/utils/ids.ts @@ -47,10 +47,12 @@ let IDs = { diversityCoordinator: '948284375827640321', mentorCoordinator: '947905630939807785', verifierCoordinator: '940721280376778822', + eventCoordinator: '944732860554817586', restricted: '851624392928264222', moderator: '826157475815489598', verifier: '871802735031373856', }, + stageHost: '854893757593419786', patron: '765370219207852055', patreon: '993848684640997406', verifyingAsVegan: '854725899576279060',