Merge pull request #44 from smyalygames/main

feat(arabot): add vegancurious command
This commit is contained in:
Anthony 2022-07-29 03:51:03 +01:00 committed by GitHub
commit 4f99621de2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 164 additions and 0 deletions

View File

@ -0,0 +1,111 @@
// 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 { Command, RegisterBehavior } from '@sapphire/framework';
import { IDs } from '../../utils/ids';
export class VegCuriousCommand extends Command {
public constructor(context: Command.Context, options: Command.Options) {
super(context, {
...options,
name: 'vegancurious',
description: 'Gives the veg curious role for vegans only',
preconditions: ['MentorCoordinatorOnly'],
});
}
// 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 veg curious 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 vegCurious = guild!.roles.cache.get(IDs.roles.nonvegan.vegCurious);
// Checks if guildMember is null
if (guildMember === null || vegCurious === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Removes the possibility of guildMember being null
guildMember = guildMember!;
vegCurious = vegCurious!;
// Checks if the user is vegan
if (!guildMember.roles.cache.has(IDs.roles.vegan.vegan)) {
await interaction.reply({
content: `${user!} is not vegan!`,
ephemeral: true,
fetchReply: true,
});
}
// 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.nonvegan.vegCurious)) {
// Remove the Veg Curious role from the user
await guildMember.roles.remove(vegCurious);
await interaction.reply({
content: `Removed the ${vegCurious.name} role from ${user!}`,
ephemeral: true,
fetchReply: true,
});
return;
}
// Add Veg Curious role to the user
await guildMember.roles.add(vegCurious);
await interaction.reply({
content: `Gave ${user!} the ${vegCurious.name} role!`,
ephemeral: true,
fetchReply: true,
});
}
}

View 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 MentorCoordinatorOnlyPrecondition extends AllFlowsPrecondition {
public override async messageRun(message: Message) {
// for message command
return this.checkMentorCoordinator(message.member!);
}
public override async chatInputRun(interaction: CommandInteraction) {
// for slash command
return this.checkMentorCoordinator(interaction.member! as GuildMember);
}
public override async contextMenuRun(interaction: ContextMenuInteraction) {
// for context menu command
return this.checkMentorCoordinator(interaction.member! as GuildMember);
}
private async checkMentorCoordinator(user: GuildMember) {
return user.roles.cache.has(IDs.roles.staff.mentorCoordinator)
? this.ok()
: this.error({ message: 'Only coordinators can run this command!' });
}
}
declare module '@sapphire/framework' {
interface Preconditions {
MentorCoordinatorOnly: never;
}
}

View File

@ -41,6 +41,7 @@ const IDs = {
staff: {
coordinator: '993636242019323904',
devCoordinator: '966031741099855973',
mentorCoordinator: '947905630939807785',
restricted: '851624392928264222',
moderator: '826157475815489598',
verifier: '871802735031373856',