feat(arabot): add convinced command

This commit is contained in:
smyalygames 2022-10-27 02:29:14 +01:00
parent ac50b96ba8
commit 28e06a3b88
4 changed files with 244 additions and 0 deletions

View File

@ -0,0 +1,184 @@
// 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 { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js';
import IDs from '../../utils/ids';
class ConvincedCommand extends Command {
public constructor(context: Command.Context, options: Command.Options) {
super(context, {
...options,
name: 'convinced',
description: 'Gives the convinced role',
preconditions: ['MentorOnly', 'VerifierOnly', 'ModOnly'],
});
}
// 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 convinced 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 mod = interaction.member;
const { guild } = interaction;
// Checks if all the variables are of the right type
if (user === null || guild === null || mod === 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
const guildMember = guild.members.cache.get(user.id);
const convinced = guild.roles.cache.get(IDs.roles.nonvegan.convinced);
// Checks if guildMember is null
if (guildMember === undefined || convinced === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user is vegan
if (guildMember.roles.cache.has(IDs.roles.vegan.vegan)) {
await interaction.reply({
content: `${user} is already vegan!`,
ephemeral: true,
fetchReply: true,
});
}
// Checks if the user has Convinced and to give them or remove them based on if they have it
if (guildMember.roles.cache.has(IDs.roles.nonvegan.convinced)) {
// Remove the Veg Curious role from the user
await guildMember.roles.remove(convinced);
await interaction.reply({
content: `Removed the ${convinced.name} role from ${user}`,
fetchReply: true,
});
return;
}
// Add Convinced role to the user
await guildMember.roles.add(convinced);
await interaction.reply({
content: `Gave ${user} the ${convinced.name} role!`,
fetchReply: true,
});
await user.send(`You have been given the ${convinced.name} role by ${mod}!`
+ '\n\nThis role allows you to get access to the Diet Support section in this server that can help you go vegan '
+ 'and other parts of the server! :)'
+ '\n\nThank you for caring about the animals 💚')
.catch();
}
public async messageRun(message: Message, args: Args) {
// Get arguments
let user: GuildMember;
try {
user = await args.pick('member');
} catch {
await message.react('❌');
await message.reply('User was not provided!');
return;
}
const mod = message.member;
if (mod === null) {
await message.react('❌');
await message.reply('Moderator not found! Try again or contact a developer!');
return;
}
const { guild } = message;
if (guild === null) {
await message.react('❌');
await message.reply('Guild not found! Try again or contact a developer!');
return;
}
const convinced = guild.roles.cache.get(IDs.roles.nonvegan.convinced);
if (convinced === undefined) {
await message.react('❌');
await message.reply('Role not found! Try again or contact a developer!');
return;
}
// Checks if the user is vegan
if (user.roles.cache.has(IDs.roles.vegan.vegan)) {
await message.reply({
content: `${user} is already vegan!`,
});
}
// Checks if the user has Convinced and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.nonvegan.convinced)) {
// Remove the Veg Curious role from the user
await user.roles.remove(convinced);
await message.reply({
content: `Removed the ${convinced.name} role from ${user}`,
});
} else {
// Give Convinced role to the user
await user.roles.add(convinced);
await message.reply({
content: `Gave ${user} the ${convinced.name} role!`,
});
await user.send(`You have been given the ${convinced.name} role by ${mod}!`
+ '\n\nThis role allows you to get access to the Diet Support section in this server that can help you go vegan '
+ 'and other parts of the server! :)'
+ '\n\nThank you for caring about the animals 💚')
.catch(() => message.reply('User\'s DMs are closed.'));
}
// Checks if the user is xlevra to send a very kind message
if (mod.id === '259624904746467329') {
await message.reply('Moist!');
}
await message.react('✅');
}
}
export default ConvincedCommand;

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
import { AllFlowsPrecondition } from '@sapphire/framework';
import type {
CommandInteraction,
ContextMenuInteraction,
Message,
GuildMember,
} from 'discord.js';
import IDs from '../utils/ids';
class MentorOnlyPrecondition extends AllFlowsPrecondition {
public override async messageRun(message: Message) {
// for message command
return this.checkMentor(message.member!);
}
public override async chatInputRun(interaction: CommandInteraction) {
// for slash command
return this.checkMentor(interaction.member! as GuildMember);
}
public override async contextMenuRun(interaction: ContextMenuInteraction) {
// for context menu command
return this.checkMentor(interaction.member! as GuildMember);
}
private async checkMentor(user: GuildMember) {
return user.roles.cache.has(IDs.roles.staff.mentor)
? this.ok()
: this.error({ message: 'Only mentors can run this command!' });
}
}
declare module '@sapphire/framework' {
interface Preconditions {
MentorOnly: never;
}
}
export default MentorOnlyPrecondition;

View File

@ -50,6 +50,7 @@ const devIDs = {
trialModerator: '999431675123597404', trialModerator: '999431675123597404',
verifier: '999431675123597406', verifier: '999431675123597406',
trialVerifier: '999431675123597405', trialVerifier: '999431675123597405',
mentor: '999431675140382801',
}, },
stageHost: '999431675123597411', stageHost: '999431675123597411',
patron: '999431675098447935', patron: '999431675098447935',

View File

@ -53,6 +53,7 @@ let IDs = {
trialModerator: '982074555596152904', trialModerator: '982074555596152904',
verifier: '871802735031373856', verifier: '871802735031373856',
trialVerifier: '982635638010572850', trialVerifier: '982635638010572850',
mentor: '802752882831130624',
}, },
stageHost: '854893757593419786', stageHost: '854893757593419786',
patron: '765370219207852055', patron: '765370219207852055',