From 442822dcf294e15a0cfb38dc7d3aaa405802e336 Mon Sep 17 00:00:00 2001 From: smyalygames Date: Sun, 15 Jan 2023 12:09:38 +0000 Subject: [PATCH] feat(arabot): add diversity command --- src/commands/roles/diversity.ts | 158 ++++++++++++++++++++++++++++++++ src/commands/roles/trusted.ts | 10 +- src/utils/devIDs.ts | 1 + src/utils/ids.ts | 1 + 4 files changed, 165 insertions(+), 5 deletions(-) create mode 100644 src/commands/roles/diversity.ts diff --git a/src/commands/roles/diversity.ts b/src/commands/roles/diversity.ts new file mode 100644 index 0000000..0f0e225 --- /dev/null +++ b/src/commands/roles/diversity.ts @@ -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 . +*/ + +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; diff --git a/src/commands/roles/trusted.ts b/src/commands/roles/trusted.ts index 81adebd..4a35967 100644 --- a/src/commands/roles/trusted.ts +++ b/src/commands/roles/trusted.ts @@ -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!`, diff --git a/src/utils/devIDs.ts b/src/utils/devIDs.ts index d42a685..d590dfb 100644 --- a/src/utils/devIDs.ts +++ b/src/utils/devIDs.ts @@ -51,6 +51,7 @@ const devIDs = { verifier: '999431675123597406', trialVerifier: '999431675123597405', mentor: '999431675140382801', + diversity: '999431675123597410', }, stageHost: '999431675123597411', patron: '999431675098447935', diff --git a/src/utils/ids.ts b/src/utils/ids.ts index 7a8f6b2..e15679e 100644 --- a/src/utils/ids.ts +++ b/src/utils/ids.ts @@ -54,6 +54,7 @@ let IDs = { verifier: '871802735031373856', trialVerifier: '982635638010572850', mentor: '802752882831130624', + diversity: '965482239913762826', }, stageHost: '854893757593419786', patron: '765370219207852055',