feat(arabot): add diversity command

This commit is contained in:
smyalygames 2023-01-15 12:09:38 +00:00
parent 88b7ef269d
commit 442822dcf2
4 changed files with 165 additions and 5 deletions

View File

@ -0,0 +1,158 @@
// 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 TrustedCommand extends Command {
public constructor(context: Command.Context, options: Command.Options) {
super(context, {
...options,
name: 'diversity',
aliases: ['di', 'div'],
description: 'Gives/removes the diversity role',
preconditions: ['DiversityCoordinatorOnly'],
});
}
// 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/remove diversity to')
.setRequired(true)),
{
behaviorWhenNotIdentical: RegisterBehavior.Overwrite,
},
);
}
// Command run
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// 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 diversity = guild.roles.cache.get(IDs.roles.staff.diversity);
// Checks if guildMember is null
if (guildMember === undefined || diversity === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user has Diversity and to give them or remove them based on if they have it
if (guildMember.roles.cache.has(IDs.roles.staff.diversity)) {
// Remove the Veg Curious role from the user
await guildMember.roles.remove(diversity);
await interaction.reply({
content: `Removed the ${diversity.name} role from ${user}`,
fetchReply: true,
});
return;
}
// Add Diversity Team role to the user
await guildMember.roles.add(diversity);
await interaction.reply({
content: `Gave ${user} the ${diversity.name} role!`,
fetchReply: true,
});
await user.send(`You have been given the ${diversity.name} role by ${mod}!`)
.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('Diversity coordinator 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 diversity = guild.roles.cache.get(IDs.roles.staff.diversity);
if (diversity === undefined) {
await message.react('❌');
await message.reply('Role not found! Try again or contact a developer!');
return;
}
// Checks if the user has Diversity and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.staff.diversity)) {
// Remove the Diversity Team role from the user
await user.roles.remove(diversity);
await message.reply({
content: `Removed the ${diversity.name} role from ${user}`,
});
} else {
// Give Diversity Team role to the user
await user.roles.add(diversity);
await message.reply({
content: `Gave ${user} the ${diversity.name} role!`,
});
await user.send(`You have been given the ${diversity.name} role by ${mod}!`)
.catch(() => {});
}
await message.react('✅');
}
}
export default TrustedCommand;

View File

@ -79,9 +79,9 @@ class TrustedCommand extends Command {
return;
}
// Checks if the user has Convinced and to give them or remove them based on if they have it
// Checks if the user has Trusted and to give them or remove them based on if they have it
if (guildMember.roles.cache.has(IDs.roles.trusted)) {
// Remove the Veg Curious role from the user
// Remove the Trusted role from the user
await guildMember.roles.remove(trusted);
await interaction.reply({
content: `Removed the ${trusted.name} role from ${user}`,
@ -89,7 +89,7 @@ class TrustedCommand extends Command {
});
return;
}
// Add Convinced role to the user
// Add Trusted role to the user
await guildMember.roles.add(trusted);
await interaction.reply({
content: `Gave ${user} the ${trusted.name} role!`,
@ -137,7 +137,7 @@ class TrustedCommand extends Command {
return;
}
// Checks if the user has Convinced and to give them or remove them based on if they have it
// Checks if the user has Trusted and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.trusted)) {
// Remove the Veg Curious role from the user
await user.roles.remove(trusted);
@ -145,7 +145,7 @@ class TrustedCommand extends Command {
content: `Removed the ${trusted.name} role from ${user}`,
});
} else {
// Give Convinced role to the user
// Give Trusted role to the user
await user.roles.add(trusted);
await message.reply({
content: `Gave ${user} the ${trusted.name} role!`,

View File

@ -51,6 +51,7 @@ const devIDs = {
verifier: '999431675123597406',
trialVerifier: '999431675123597405',
mentor: '999431675140382801',
diversity: '999431675123597410',
},
stageHost: '999431675123597411',
patron: '999431675098447935',

View File

@ -54,6 +54,7 @@ let IDs = {
verifier: '871802735031373856',
trialVerifier: '982635638010572850',
mentor: '802752882831130624',
diversity: '965482239913762826',
},
stageHost: '854893757593419786',
patron: '765370219207852055',