refactor(arabot): change role command structures

This commit is contained in:
smyalygames 2023-03-03 17:45:42 +00:00
parent 6bfe57c135
commit 873afcd4d6
16 changed files with 742 additions and 1074 deletions

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class BookClubCommand extends Command { export class BookClubCommand extends Command {
@ -50,67 +50,39 @@ export class BookClubCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mod = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || mod === null || guild === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const bookClub = guild.roles.cache.get(IDs.roles.bookClub);
// Checks if guildMember is null const info = await this.manageBookClub(user, mod, guild);
if (guildMember === undefined || bookClub === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user has Book Club and to give them or remove them based on if they have it await interaction.editReply(info.message);
if (guildMember.roles.cache.has(IDs.roles.bookClub)) {
// Remove the Book Club role from the user
await guildMember.roles.remove(bookClub);
await interaction.reply({
content: `Removed the ${bookClub.name} role from ${user}`,
fetchReply: true,
});
return;
}
// Give Book Club role to the user
await guildMember.roles.add(bookClub);
await interaction.reply({
content: `Gave ${user} the ${bookClub.name} role!`,
fetchReply: true,
});
await user.send(`You have been given the ${bookClub.name} role by ${mod}!`)
.catch(() => {});
} }
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mod = message.member; const mod = message.author;
if (mod === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
@ -126,31 +98,45 @@ export class BookClubCommand extends Command {
return; return;
} }
const info = await this.manageBookClub(user, mod, guild);
await message.reply(info.message);
await message.react(info.success ? '✅' : '❌');
}
private async manageBookClub(user: User, mod: User, guild: Guild) {
const info = {
message: '',
success: false,
};
const member = guild.members.cache.get(user.id);
const bookClub = guild.roles.cache.get(IDs.roles.bookClub); const bookClub = guild.roles.cache.get(IDs.roles.bookClub);
// Checks if user's GuildMember was found in cache
if (member === undefined) {
info.message = 'Error fetching guild member for the user!';
return info;
}
if (bookClub === undefined) { if (bookClub === undefined) {
await message.react('❌'); info.message = 'Error fetching book club role from cache!';
await message.reply('Role not found! Try again or contact a developer!'); return info;
return;
} }
// Checks if the user has Book Club and to give them or remove them based on if they have it // Checks if the user has Book Club and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.bookClub)) { if (member.roles.cache.has(IDs.roles.bookClub)) {
// Remove the Book Club role from the user // Remove the Book Club role from the user
await user.roles.remove(bookClub); await member.roles.remove(bookClub);
await message.reply({ info.message = `Removed the ${bookClub.name} role from ${user}`;
content: `Removed the ${bookClub.name} role from ${user}`, return info;
}); }
} else { // Add Book Club role to the user
// Give Book Club role to the user await member.roles.add(bookClub);
await user.roles.add(bookClub); info.message = `Gave ${user} the ${bookClub.name} role!`;
await message.reply({
content: `Gave ${user} the ${bookClub.name} role!`,
});
await user.send(`You have been given the ${bookClub.name} role by ${mod}!`) await user.send(`You have been given the ${bookClub.name} role by ${mod}!`)
.catch(() => {}); .catch(() => {});
} info.success = true;
return info;
await message.react('✅');
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class DebateHostCommand extends Command { export class DebateHostCommand extends Command {
@ -50,67 +50,39 @@ export class DebateHostCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mod = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || mod === null || guild === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const debate = guild.roles.cache.get(IDs.roles.debateHost);
// Checks if guildMember is null const info = await this.manageDebateHost(user, mod, guild);
if (guildMember === undefined || debate === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user has Debate Host and to give them or remove them based on if they have it await interaction.editReply(info.message);
if (guildMember.roles.cache.has(IDs.roles.debateHost)) {
// Remove the Debate Host role from the user
await guildMember.roles.remove(debate);
await interaction.reply({
content: `Removed the ${debate.name} role from ${user}`,
fetchReply: true,
});
return;
}
// Give Debate Host role to the user
await guildMember.roles.add(debate);
await interaction.reply({
content: `Gave ${user} the ${debate.name} role!`,
fetchReply: true,
});
await user.send(`You have been given the ${debate.name} role by ${mod}!`)
.catch(() => {});
} }
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mod = message.member; const mod = message.author;
if (mod === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
@ -126,31 +98,45 @@ export class DebateHostCommand extends Command {
return; return;
} }
const debate = guild.roles.cache.get(IDs.roles.debateHost); const info = await this.manageDebateHost(user, mod, guild);
if (debate === undefined) { await message.reply(info.message);
await message.react('❌'); await message.react(info.success ? '✅' : '❌');
await message.reply('Role not found! Try again or contact a developer!'); }
return;
private async manageDebateHost(user: User, mod: User, guild: Guild) {
const info = {
message: '',
success: false,
};
const member = guild.members.cache.get(user.id);
const debateHost = guild.roles.cache.get(IDs.roles.debateHost);
// Checks if user's GuildMember was found in cache
if (member === undefined) {
info.message = 'Error fetching guild member for the user!';
return info;
}
if (debateHost === undefined) {
info.message = 'Error fetching debate host role from cache!';
return info;
} }
// Checks if the user has Debate Host and to give them or remove them based on if they have it // Checks if the user has Debate Host and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.debateHost)) { if (member.roles.cache.has(IDs.roles.debateHost)) {
// Remove the Debate Host role from the user // Remove the Debate Host role from the user
await user.roles.remove(debate); await member.roles.remove(debateHost);
await message.reply({ info.message = `Removed the ${debateHost.name} role from ${user}`;
content: `Removed the ${debate.name} role from ${user}`, return info;
});
} else {
// Give Debate Host role to the user
await user.roles.add(debate);
await message.reply({
content: `Gave ${user} the ${debate.name} role!`,
});
await user.send(`You have been given the ${debate.name} role by ${mod}!`)
.catch(() => {});
} }
// Add Debate Host role to the user
await member.roles.add(debateHost);
info.message = `Gave ${user} the ${debateHost.name} role!`;
await message.react('✅'); await user.send(`You have been given the ${debateHost.name} role by ${mod}!`)
.catch(() => {});
info.success = true;
return info;
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class GameNightHostCommand extends Command { export class GameNightHostCommand extends Command {
@ -50,67 +50,39 @@ export class GameNightHostCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mod = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || mod === null || guild === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const game = guild.roles.cache.get(IDs.roles.gameNightHost);
// Checks if guildMember is null const info = await this.manageGameNight(user, mod, guild);
if (guildMember === undefined || game === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user has Game Night and to give them or remove them based on if they have it await interaction.editReply(info.message);
if (guildMember.roles.cache.has(IDs.roles.gameNightHost)) {
// Remove the Game Night Host role from the user
await guildMember.roles.remove(game);
await interaction.reply({
content: `Removed the ${game.name} role from ${user}`,
fetchReply: true,
});
return;
}
// Give Game Night Host role to the user
await guildMember.roles.add(game);
await interaction.reply({
content: `Gave ${user} the ${game.name} role!`,
fetchReply: true,
});
await user.send(`You have been given the ${game.name} role by ${mod}!`)
.catch(() => {});
} }
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mod = message.member; const mod = message.author;
if (mod === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
@ -126,31 +98,45 @@ export class GameNightHostCommand extends Command {
return; return;
} }
const game = guild.roles.cache.get(IDs.roles.gameNightHost); const info = await this.manageGameNight(user, mod, guild);
if (game === undefined) { await message.reply(info.message);
await message.react('❌'); await message.react(info.success ? '✅' : '❌');
await message.reply('Role not found! Try again or contact a developer!'); }
return;
private async manageGameNight(user: User, mod: User, guild: Guild) {
const info = {
message: '',
success: false,
};
const member = guild.members.cache.get(user.id);
const gameNightHost = guild.roles.cache.get(IDs.roles.gameNightHost);
// Checks if user's GuildMember was found in cache
if (member === undefined) {
info.message = 'Error fetching guild member for the user!';
return info;
}
if (gameNightHost === undefined) {
info.message = 'Error fetching game night host role from cache!';
return info;
} }
// Checks if the user has Game Night and to give them or remove them based on if they have it // Checks if the user has Game Night and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.gameNightHost)) { if (member.roles.cache.has(IDs.roles.gameNightHost)) {
// Remove the Game Night Host role from the user // Remove the Game Night Host role from the user
await user.roles.remove(game); await member.roles.remove(gameNightHost);
await message.reply({ info.message = `Removed the ${gameNightHost.name} role from ${user}`;
content: `Removed the ${game.name} role from ${user}`, return info;
});
} else {
// Give Game Night Host role to the user
await user.roles.add(game);
await message.reply({
content: `Gave ${user} the ${game.name} role!`,
});
await user.send(`You have been given the ${game.name} role by ${mod}!`)
.catch(() => {});
} }
// Add Game Night Host role to the user
await member.roles.add(gameNightHost);
info.message = `Gave ${user} the ${gameNightHost.name} role!`;
await message.react('✅'); await user.send(`You have been given the ${gameNightHost.name} role by ${mod}!`)
.catch(() => {});
info.success = true;
return info;
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class GuestCommand extends Command { export class GuestCommand extends Command {
@ -50,67 +50,39 @@ export class GuestCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mod = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || mod === null || guild === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const guest = guild.roles.cache.get(IDs.roles.guest);
// Checks if guildMember is null const info = await this.manageGuest(user, mod, guild);
if (guildMember === undefined || guest === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user has Guest and to give them or remove them based on if they have it await interaction.editReply(info.message);
if (guildMember.roles.cache.has(IDs.roles.guest)) {
// Remove the Guest role from the user
await guildMember.roles.remove(guest);
await interaction.reply({
content: `Removed the ${guest.name} role from ${user}`,
fetchReply: true,
});
return;
}
// Give Guest role to the user
await guildMember.roles.add(guest);
await interaction.reply({
content: `Gave ${user} the ${guest.name} role!`,
fetchReply: true,
});
await user.send(`You have been given the ${guest.name} role by ${mod}!`)
.catch(() => {});
} }
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mod = message.member; const mod = message.author;
if (mod === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
@ -126,31 +98,45 @@ export class GuestCommand extends Command {
return; return;
} }
const info = await this.manageGuest(user, mod, guild);
await message.reply(info.message);
await message.react(info.success ? '✅' : '❌');
}
private async manageGuest(user: User, mod: User, guild: Guild) {
const info = {
message: '',
success: false,
};
const member = guild.members.cache.get(user.id);
const guest = guild.roles.cache.get(IDs.roles.guest); const guest = guild.roles.cache.get(IDs.roles.guest);
// Checks if user's GuildMember was found in cache
if (member === undefined) {
info.message = 'Error fetching guild member for the user!';
return info;
}
if (guest === undefined) { if (guest === undefined) {
await message.react('❌'); info.message = 'Error fetching guest role from cache!';
await message.reply('Role not found! Try again or contact a developer!'); return info;
return;
} }
// Checks if the user has Guest and to give them or remove them based on if they have it // Checks if the user has Guest and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.guest)) { if (member.roles.cache.has(IDs.roles.guest)) {
// Remove the Guest role from the user // Remove the Guest role from the user
await user.roles.remove(guest); await member.roles.remove(guest);
await message.reply({ info.message = `Removed the ${guest.name} role from ${user}`;
content: `Removed the ${guest.name} role from ${user}`, return info;
}); }
} else { // Add Guest role to the user
// Give Guest role to the user await member.roles.add(guest);
await user.roles.add(guest); info.message = `Gave ${user} the ${guest.name} role!`;
await message.reply({
content: `Gave ${user} the ${guest.name} role!`,
});
await user.send(`You have been given the ${guest.name} role by ${mod}!`) await user.send(`You have been given the ${guest.name} role by ${mod}!`)
.catch(() => {}); .catch(() => {});
} info.success = true;
return info;
await message.react('✅');
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class MentorCommand extends Command { export class MentorCommand extends Command {
@ -51,66 +51,39 @@ export class MentorCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mod = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || guild === null || mod === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const mentor = guild.roles.cache.get(IDs.roles.staff.mentor);
// Checks if guildMember is null const info = await this.manageMentor(user, mod, guild);
if (guildMember === undefined || mentor === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user has Mentor and to give them or remove them based on if they have it await interaction.editReply(info.message);
if (guildMember.roles.cache.has(IDs.roles.staff.mentor)) {
// Remove the Mentor role from the user
await guildMember.roles.remove(mentor);
await interaction.reply({
content: `Removed the ${mentor.name} role from ${user}`,
fetchReply: true,
});
return;
}
// Add Mentor role to the user
await guildMember.roles.add(mentor);
await interaction.reply({
content: `Gave ${user} the ${mentor.name} role!`,
fetchReply: true,
});
await user.send(`You have been given the ${mentor.name} role by ${mod}!`)
.catch(() => {});
} }
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mod = message.member; const mod = message.author;
if (mod === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
@ -126,31 +99,45 @@ export class MentorCommand extends Command {
return; return;
} }
const info = await this.manageMentor(user, mod, guild);
await message.reply(info.message);
await message.react(info.success ? '✅' : '❌');
}
private async manageMentor(user: User, mod: User, guild: Guild) {
const info = {
message: '',
success: false,
};
const member = guild.members.cache.get(user.id);
const mentor = guild.roles.cache.get(IDs.roles.staff.mentor); const mentor = guild.roles.cache.get(IDs.roles.staff.mentor);
// Checks if user's GuildMember was found in cache
if (member === undefined) {
info.message = 'Error fetching guild member for the user!';
return info;
}
if (mentor === undefined) { if (mentor === undefined) {
await message.react('❌'); info.message = 'Error fetching mentor role from cache!';
await message.reply('Role not found! Try again or contact a developer!'); return info;
return;
} }
// Checks if the user has Mentor and to give them or remove them based on if they have it // Checks if the user has Mentor and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.staff.mentor)) { if (member.roles.cache.has(IDs.roles.staff.mentor)) {
// Remove the Mentor role from the user // Remove the Mentor role from the user
await user.roles.remove(mentor); await member.roles.remove(mentor);
await message.reply({ info.message = `Removed the ${mentor.name} role from ${user}`;
content: `Removed the ${mentor.name} role from ${user}`, return info;
}); }
} else { // Add Mentor role to the user
// Give Mentor role to the user await member.roles.add(mentor);
await user.roles.add(mentor); info.message = `Gave ${user} the ${mentor.name} role!`;
await message.reply({
content: `Gave ${user} the ${mentor.name} role!`,
});
await user.send(`You have been given the ${mentor.name} role by ${mod}!`) await user.send(`You have been given the ${mentor.name} role by ${mod}!`)
.catch(() => {}); .catch(() => {});
} info.success = true;
return info;
await message.react('✅');
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class ModCommand extends Command { export class ModCommand extends Command {
@ -50,70 +50,43 @@ export class ModCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mod = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || guild === null || mod === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const modRole = guild.roles.cache.get(IDs.roles.staff.moderator);
// Checks if guildMember is null const info = await this.manageMod(user, mod, guild);
if (guildMember === undefined || modRole === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user has Mod and to give them or remove them based on if they have it await interaction.editReply(info.message);
if (guildMember.roles.cache.has(IDs.roles.staff.moderator)) {
// Remove the Mod role from the user
await guildMember.roles.remove(modRole);
await interaction.reply({
content: `Removed the ${modRole.name} role from ${user}`,
fetchReply: true,
});
return;
}
// Add Mod role to the user
await guildMember.roles.add(modRole);
await interaction.reply({
content: `Gave ${user} the ${modRole.name} role!`,
fetchReply: true,
});
await user.send(`You have been given the ${modRole.name} role by ${mod}!`)
.catch(() => {});
} }
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mod = message.member; const mod = message.author;
if (mod === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
await message.reply('Moderator coordinator not found! Try again or contact a developer!'); await message.reply('Mod coordinator not found! Try again or contact a developer!');
return; return;
} }
@ -125,31 +98,45 @@ export class ModCommand extends Command {
return; return;
} }
const modRole = guild.roles.cache.get(IDs.roles.staff.moderator); const info = await this.manageMod(user, mod, guild);
if (modRole === undefined) { await message.reply(info.message);
await message.react('❌'); await message.react(info.success ? '✅' : '❌');
await message.reply('Role not found! Try again or contact a developer!'); }
return;
private async manageMod(user: User, mod: User, guild: Guild) {
const info = {
message: '',
success: false,
};
const member = guild.members.cache.get(user.id);
const moderator = guild.roles.cache.get(IDs.roles.staff.moderator);
// Checks if user's GuildMember was found in cache
if (member === undefined) {
info.message = 'Error fetching guild member for the user!';
return info;
}
if (moderator === undefined) {
info.message = 'Error fetching the moderator role from cache!';
return info;
} }
// Checks if the user has Mod and to give them or remove them based on if they have it // Checks if the user has Mod and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.staff.moderator)) { if (member.roles.cache.has(IDs.roles.staff.moderator)) {
// Remove the Mod role from the user // Remove the Mod role from the user
await user.roles.remove(modRole); await member.roles.remove(moderator);
await message.reply({ info.message = `Removed the ${moderator.name} role from ${user}`;
content: `Removed the ${modRole.name} role from ${user}`, return info;
});
} else {
// Give Mod role to the user
await user.roles.add(modRole);
await message.reply({
content: `Gave ${user} the ${modRole.name} role!`,
});
await user.send(`You have been given the ${modRole.name} role by ${mod}!`)
.catch(() => {});
} }
// Add Mod role to the user
await member.roles.add(moderator);
info.message = `Gave ${user} the ${moderator.name} role!`;
await message.react('✅'); await user.send(`You have been given the ${moderator.name} role by ${mod}!`)
.catch(() => {});
info.success = true;
return info;
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class RestrictedAccessCommand extends Command { export class RestrictedAccessCommand extends Command {
@ -51,70 +51,43 @@ export class RestrictedAccessCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mod = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || guild === null || mod === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const restrictedAccess = guild.roles.cache.get(IDs.roles.staff.restricted);
// Checks if guildMember is null const info = await this.manageRestrictedAccess(user, mod, guild);
if (guildMember === undefined || restrictedAccess === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user has RA and to give them or remove them based on if they have it await interaction.editReply(info.message);
if (guildMember.roles.cache.has(IDs.roles.staff.restricted)) {
// Remove the Restricted Access role from the user
await guildMember.roles.remove(restrictedAccess);
await interaction.reply({
content: `Removed the ${restrictedAccess.name} role from ${user}`,
fetchReply: true,
});
return;
}
// Add Restricted Access role to the user
await guildMember.roles.add(restrictedAccess);
await interaction.reply({
content: `Gave ${user} the ${restrictedAccess.name} role!`,
fetchReply: true,
});
await user.send(`You have been given the ${restrictedAccess.name} role by ${mod}!`)
.catch(() => {});
} }
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mod = message.member; const mod = message.author;
if (mod === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
await message.reply('Moderator coordinator not found! Try again or contact a developer!'); await message.reply('Mod coordinator not found! Try again or contact a developer!');
return; return;
} }
@ -126,31 +99,45 @@ export class RestrictedAccessCommand extends Command {
return; return;
} }
const restrictedAccess = guild.roles.cache.get(IDs.roles.staff.restricted); const info = await this.manageRestrictedAccess(user, mod, guild);
if (restrictedAccess === undefined) { await message.reply(info.message);
await message.react('❌'); await message.react(info.success ? '✅' : '❌');
await message.reply('Role not found! Try again or contact a developer!'); }
return;
private async manageRestrictedAccess(user: User, mod: User, guild: Guild) {
const info = {
message: '',
success: false,
};
const member = guild.members.cache.get(user.id);
const restricted = guild.roles.cache.get(IDs.roles.staff.restricted);
// Checks if user's GuildMember was found in cache
if (member === undefined) {
info.message = 'Error fetching guild member for the user!';
return info;
}
if (restricted === undefined) {
info.message = 'Error fetching the restricted access role from cache!';
return info;
} }
// Checks if the user has RA and to give them or remove them based on if they have it // Checks if the user has RA and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.staff.restricted)) { if (member.roles.cache.has(IDs.roles.staff.restricted)) {
// Remove the Restricted Access role from the user // Remove the Restricted Access role from the user
await user.roles.remove(restrictedAccess); await member.roles.remove(restricted);
await message.reply({ info.message = `Removed the ${restricted.name} role from ${user}`;
content: `Removed the ${restrictedAccess.name} role from ${user}`, return info;
});
} else {
// Give Restricted Access role to the user
await user.roles.add(restrictedAccess);
await message.reply({
content: `Gave ${user} the ${restrictedAccess.name} role!`,
});
await user.send(`You have been given the ${restrictedAccess.name} role by ${mod}!`)
.catch(() => {});
} }
// Add Restricted Access role to the user
await member.roles.add(restricted);
info.message = `Gave ${user} the ${restricted.name} role!`;
await message.react('✅'); await user.send(`You have been given the ${restricted.name} role by ${mod}!`)
.catch(() => {});
info.success = true;
return info;
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class StageHostCommand extends Command { export class StageHostCommand extends Command {
@ -50,67 +50,39 @@ export class StageHostCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mod = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || mod === null || guild === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const stageHost = guild.roles.cache.get(IDs.roles.stageHost);
// Checks if guildMember is null const info = await this.manageStageHost(user, mod, guild);
if (guildMember === undefined || stageHost === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user has Stage Host and to give them or remove them based on if they have it await interaction.editReply(info.message);
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;
}
// Give Stage Host role to the user
await guildMember.roles.add(stageHost);
await interaction.reply({
content: `Gave ${user} the ${stageHost.name} role!`,
fetchReply: true,
});
await user.send(`You have been given the ${stageHost.name} role by ${mod}!`)
.catch(() => {});
} }
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mod = message.member; const mod = message.author;
if (mod === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
@ -126,31 +98,45 @@ export class StageHostCommand extends Command {
return; return;
} }
const info = await this.manageStageHost(user, mod, guild);
await message.reply(info.message);
await message.react(info.success ? '✅' : '❌');
}
private async manageStageHost(user: User, mod: User, guild: Guild) {
const info = {
message: '',
success: false,
};
const member = guild.members.cache.get(user.id);
const stageHost = guild.roles.cache.get(IDs.roles.stageHost); const stageHost = guild.roles.cache.get(IDs.roles.stageHost);
// Checks if user's GuildMember was found in cache
if (member === undefined) {
info.message = 'Error fetching guild member for the user!';
return info;
}
if (stageHost === undefined) { if (stageHost === undefined) {
await message.react('❌'); info.message = 'Error fetching stage host role from cache!';
await message.reply('Role not found! Try again or contact a developer!'); return info;
return;
} }
// Checks if the user has Stage Host and to give them or remove them based on if they have it // Checks if the user has Stage Host and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.stageHost)) { if (member.roles.cache.has(IDs.roles.stageHost)) {
// Remove the Stage Host role from the user // Remove the Stage Host role from the user
await user.roles.remove(stageHost); await member.roles.remove(stageHost);
await message.reply({ info.message = `Removed the ${stageHost.name} role from ${user}`;
content: `Removed the ${stageHost.name} role from ${user}`, return info;
}); }
} else { // Add Stage Host role to the user
// Give Stage Host role to the user await member.roles.add(stageHost);
await user.roles.add(stageHost); info.message = `Gave ${user} the ${stageHost.name} role!`;
await message.reply({
content: `Gave ${user} the ${stageHost.name} role!`,
});
await user.send(`You have been given the ${stageHost.name} role by ${mod}!`) await user.send(`You have been given the ${stageHost.name} role by ${mod}!`)
.catch(() => {}); .catch(() => {});
} info.success = true;
return info;
await message.react('✅');
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class TrialVerifierCommand extends Command { export class TrialVerifierCommand extends Command {
@ -50,66 +50,39 @@ export class TrialVerifierCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mod = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || guild === null || mod === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const verifier = guild.roles.cache.get(IDs.roles.staff.trialVerifier);
// Checks if guildMember is null const info = await this.manageTrialVerifier(user, mod, guild);
if (guildMember === undefined || verifier === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user has TV and to give them or remove them based on if they have it await interaction.editReply(info.message);
if (guildMember.roles.cache.has(IDs.roles.staff.trialVerifier)) {
// Remove the Trial Verifier role from the user
await guildMember.roles.remove(verifier);
await interaction.reply({
content: `Removed the ${verifier.name} role from ${user}`,
fetchReply: true,
});
return;
}
// Add Trial Verifier role to the user
await guildMember.roles.add(verifier);
await interaction.reply({
content: `Gave ${user} the ${verifier.name} role!`,
fetchReply: true,
});
await user.send(`You have been given the ${verifier.name} role by ${mod}!`)
.catch(() => {});
} }
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mod = message.member; const mod = message.author;
if (mod === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
@ -125,31 +98,45 @@ export class TrialVerifierCommand extends Command {
return; return;
} }
const verifier = guild.roles.cache.get(IDs.roles.staff.trialVerifier); const info = await this.manageTrialVerifier(user, mod, guild);
if (verifier === undefined) { await message.reply(info.message);
await message.react('❌'); await message.react(info.success ? '✅' : '❌');
await message.reply('Role not found! Try again or contact a developer!'); }
return;
private async manageTrialVerifier(user: User, mod: User, guild: Guild) {
const info = {
message: '',
success: false,
};
const member = guild.members.cache.get(user.id);
const trialVerifier = guild.roles.cache.get(IDs.roles.staff.trialVerifier);
// Checks if user's GuildMember was found in cache
if (member === undefined) {
info.message = 'Error fetching guild member for the user!';
return info;
}
if (trialVerifier === undefined) {
info.message = 'Error fetching the trial verifier role from cache!';
return info;
} }
// Checks if the user has TV and to give them or remove them based on if they have it // Checks if the user has TV and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.staff.trialVerifier)) { if (member.roles.cache.has(IDs.roles.staff.trialVerifier)) {
// Remove the Trial Verifier role from the user // Remove the Trial Verifier role from the user
await user.roles.remove(verifier); await member.roles.remove(trialVerifier);
await message.reply({ info.message = `Removed the ${trialVerifier.name} role from ${user}`;
content: `Removed the ${verifier.name} role from ${user}`, return info;
});
} else {
// Give Trial Verifier role to the user
await user.roles.add(verifier);
await message.reply({
content: `Gave ${user} the ${verifier.name} role!`,
});
await user.send(`You have been given the ${verifier.name} role by ${mod}!`)
.catch(() => {});
} }
// Add Trial Verifier role to the user
await member.roles.add(trialVerifier);
info.message = `Gave ${user} the ${trialVerifier.name} role!`;
await message.react('✅'); await user.send(`You have been given the ${trialVerifier.name} role by ${mod}!`)
.catch(() => {});
info.success = true;
return info;
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class VerifierCommand extends Command { export class VerifierCommand extends Command {
@ -50,70 +50,39 @@ export class VerifierCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mod = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || guild === null || mod === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const verifier = guild.roles.cache.get(IDs.roles.staff.verifier);
// Checks if guildMember is null const info = await this.manageVerifier(user, mod, guild);
if (guildMember === undefined || verifier === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user has Verifier and to give them or remove them based on if they have it await interaction.editReply(info.message);
if (guildMember.roles.cache.has(IDs.roles.staff.verifier)) {
// Remove the Verifier role from the user
await guildMember.roles.remove(verifier);
await interaction.reply({
content: `Removed the ${verifier.name} role from ${user}`,
fetchReply: true,
});
return;
}
// Add Verifier role to the user
await guildMember.roles.add(verifier);
await interaction.reply({
content: `Gave ${user} the ${verifier.name} role!`,
fetchReply: true,
});
await user.send(`You have been given the ${verifier.name} role by ${mod}!`)
.catch(() => {});
if (guildMember.roles.cache.has(IDs.roles.staff.trialVerifier)) {
await guildMember.roles.remove(IDs.roles.staff.trialVerifier);
}
} }
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mod = message.member; const mod = message.author;
if (mod === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
@ -129,35 +98,45 @@ export class VerifierCommand extends Command {
return; return;
} }
const info = await this.manageVerifier(user, mod, guild);
await message.reply(info.message);
await message.react(info.success ? '✅' : '❌');
}
private async manageVerifier(user: User, mod: User, guild: Guild) {
const info = {
message: '',
success: false,
};
const member = guild.members.cache.get(user.id);
const verifier = guild.roles.cache.get(IDs.roles.staff.verifier); const verifier = guild.roles.cache.get(IDs.roles.staff.verifier);
// Checks if user's GuildMember was found in cache
if (member === undefined) {
info.message = 'Error fetching guild member for the user!';
return info;
}
if (verifier === undefined) { if (verifier === undefined) {
await message.react('❌'); info.message = 'Error fetching verifier role from cache!';
await message.reply('Role not found! Try again or contact a developer!'); return info;
return;
} }
// Checks if the user has Verifier and to give them or remove them based on if they have it // Checks if the user has Verifier and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.staff.verifier)) { if (member.roles.cache.has(IDs.roles.staff.verifier)) {
// Remove the Verifier role from the user // Remove the Verifier role from the user
await user.roles.remove(verifier); await member.roles.remove(verifier);
await message.reply({ info.message = `Removed the ${verifier.name} role from ${user}`;
content: `Removed the ${verifier.name} role from ${user}`, return info;
}); }
} else { // Add Verifier role to the user
// Give Verifier role to the user await member.roles.add(verifier);
await user.roles.add(verifier); info.message = `Gave ${user} the ${verifier.name} role!`;
await message.reply({
content: `Gave ${user} the ${verifier.name} role!`,
});
await user.send(`You have been given the ${verifier.name} role by ${mod}!`) await user.send(`You have been given the ${verifier.name} role by ${mod}!`)
.catch(() => {}); .catch(() => {});
info.success = true;
if (user.roles.cache.has(IDs.roles.staff.trialVerifier)) { return info;
await user.roles.remove(IDs.roles.staff.trialVerifier);
}
}
await message.react('✅');
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class ActivistCommand extends Command { export class ActivistCommand extends Command {
@ -51,98 +51,43 @@ export class ActivistCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mod = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || mod === null || guild === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const modMember = guild.members.cache.get(mod.user.id);
const activist = guild.roles.cache.get(IDs.roles.vegan.activist);
const verCoordinator = guild.roles.cache.get(IDs.roles.staff.verifierCoordinator);
// Checks if guildMember is null const info = await this.manageActivist(user, mod, guild);
if (guildMember === undefined
|| modMember === undefined
|| activist === undefined
|| verCoordinator === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user is an activist await interaction.editReply(info.message);
if (guildMember.roles.cache.has(IDs.roles.vegan.activist)
&& !(modMember.roles.cache.has(IDs.roles.staff.verifierCoordinator)
|| modMember.roles.cache.has(IDs.roles.staff.modCoordinator))) {
await interaction.reply({
content: `${user} is an activist, only ${verCoordinator.name} can run this!`,
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user has Activist and to give them or remove them based on if they have it
if (guildMember.roles.cache.has(IDs.roles.vegan.activist)) {
// Remove the Activist role from the user
await guildMember.roles.remove(activist);
await interaction.reply({
content: `Removed the ${activist.name} role from ${user}`,
ephemeral: true,
fetchReply: true,
});
return;
}
// Add Activist role to the user
await guildMember.roles.add(activist);
await interaction.reply({
content: `Gave ${user} the ${activist.name} role!`,
ephemeral: true,
fetchReply: true,
});
const activistMsg = `${user} you have been given the ${activist.name} role by ${mod}! `
+ `This means that if you'd wish to engage with non-vegans in <#${IDs.channels.nonVegan.general}>, you should follow these rules:\n\n`
+ '1. Try to move conversations with non-vegans towards veganism/animal ethics\n'
+ '2. Don\'t discuss social topics while activism is happening\n'
+ '3. Have evidence for claims you make. "I don\'t know" is an acceptable answer. Chances are someone here knows or you can take time to find out\n'
+ '4. Don\'t advocate for baby steps towards veganism. Participation in exploitation can stop today\n'
+ '5. Differences in opinion between activists should be resolved in vegan spaces, not in the chat with non-vegans';
await guildMember.send(activistMsg)
.catch(() => {});
} }
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mod = message.member; const mod = message.author;
if (mod === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
await message.reply('Verifier not found! Try again or contact a developer!'); await message.reply('Staff not found! Try again or contact a developer!');
return; return;
} }
@ -154,48 +99,67 @@ export class ActivistCommand extends Command {
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null const info = await this.manageActivist(user, mod, guild);
await message.reply(info.message);
await message.react(info.success ? '✅' : '❌');
}
private async manageActivist(user: User, mod: User, guild: Guild) {
const info = {
message: '',
success: false,
};
const member = guild.members.cache.get(user.id);
const modMember = guild.members.cache.get(mod.id);
const activist = guild.roles.cache.get(IDs.roles.vegan.activist); const activist = guild.roles.cache.get(IDs.roles.vegan.activist);
const verCoordinator = guild.roles.cache.get(IDs.roles.staff.verifierCoordinator);
if (activist === undefined // Checks if user's GuildMember was found in cache
|| verCoordinator === undefined) { if (member === undefined) {
await message.react('❌'); info.message = 'Error fetching guild member for the user!';
await message.reply('Role not found! Try again or contact a developer!'); return info;
return;
} }
// Checks if the user is an activist if (modMember === undefined) {
if (user.roles.cache.has(IDs.roles.vegan.activist) info.message = 'Error fetching the staff\'s guild member!';
&& !(mod.roles.cache.has(IDs.roles.staff.verifierCoordinator) return info;
|| mod.roles.cache.has(IDs.roles.staff.modCoordinator))) { }
await message.reply({
content: `${user} is an activist, only ${verCoordinator.name} can run this!`, if (activist === undefined) {
}); info.message = 'Error fetching activist role from cache!';
await message.react('❌'); return info;
return; }
// Checks if the user is Activist and to give them or remove them based on if they have it
if (member.roles.cache.has(IDs.roles.vegan.activist)) {
if (!modMember.roles.cache.hasAny(
IDs.roles.staff.verifierCoordinator,
IDs.roles.staff.modCoordinator,
)) {
info.message = 'You need to be a verifier coordinator to remove this role!';
return info;
} }
// Checks if the user has Activist and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.vegan.activist)) {
// Remove the Activist role from the user // Remove the Activist role from the user
await user.roles.remove(activist); await member.roles.remove(activist);
await message.react('✅'); info.message = `Removed the ${activist.name} role from ${user}`;
return; return info;
} }
// Add Activist role to the user // Add Activist role to the user
await user.roles.add(activist); await member.roles.add(activist);
await message.react('✅'); info.message = `Gave ${user} the ${activist.name} role!`;
const activistMsg = `${user} you have been given the ${activist.name} role by ${mod}! ` await user.send(
`${user} you have been given the ${activist.name} role by ${mod}! `
+ `This means that if you'd wish to engage with non-vegans in <#${IDs.channels.nonVegan.general}>, you should follow these rules:\n\n` + `This means that if you'd wish to engage with non-vegans in <#${IDs.channels.nonVegan.general}>, you should follow these rules:\n\n`
+ '1. Try to move conversations with non-vegans towards veganism/animal ethics\n' + '1. Try to move conversations with non-vegans towards veganism/animal ethics\n'
+ '2. Don\'t discuss social topics while activism is happening\n' + '2. Don\'t discuss social topics while activism is happening\n'
+ '3. Have evidence for claims you make. "I don\'t know" is an acceptable answer. Chances are someone here knows or you can take time to find out\n' + '3. Have evidence for claims you make. "I don\'t know" is an acceptable answer. Chances are someone here knows or you can take time to find out\n'
+ '4. Don\'t advocate for baby steps towards veganism. Participation in exploitation can stop today\n' + '4. Don\'t advocate for baby steps towards veganism. Participation in exploitation can stop today\n'
+ '5. Differences in opinion between activists should be resolved in vegan spaces, not in the chat with non-vegans'; + '5. Differences in opinion between activists should be resolved in vegan spaces, not in the chat with non-vegans',
await user.send(activistMsg) ).catch(() => {});
.catch(() => {}); info.success = true;
return info;
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class ConvincedCommand extends Command { export class ConvincedCommand extends Command {
@ -51,82 +51,43 @@ export class ConvincedCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mod = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || guild === null || mod === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const convinced = guild.roles.cache.get(IDs.roles.nonvegan.convinced);
// Checks if guildMember is null const info = await this.manageConvinced(user, mod, guild);
if (guildMember === undefined || convinced === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user is vegan await interaction.editReply(info.message);
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) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mod = message.member; const mod = message.author;
if (mod === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
await message.reply('Moderator not found! Try again or contact a developer!'); await message.reply('Mod not found! Try again or contact a developer!');
return; return;
} }
@ -138,48 +99,54 @@ export class ConvincedCommand extends Command {
return; return;
} }
const convinced = guild.roles.cache.get(IDs.roles.nonvegan.convinced); const info = await this.manageConvinced(user, mod, guild);
if (convinced === undefined) { await message.reply(info.message);
await message.react('❌'); await message.react(info.success ? '✅' : '❌');
await message.reply('Role not found! Try again or contact a developer!');
return;
} }
// Checks if the user is vegan private async manageConvinced(user: User, mod: User, guild: Guild) {
if (user.roles.cache.has(IDs.roles.vegan.vegan)) { const info = {
await message.reply({ message: '',
content: `${user} is already vegan!`, success: false,
}); };
await message.react('❌'); const member = guild.members.cache.get(user.id);
return; const convinced = guild.roles.cache.get(IDs.roles.nonvegan.convinced);
// Checks if user's GuildMember was found in cache
if (member === undefined) {
info.message = 'Error fetching guild member for the user!';
return info;
}
if (convinced === undefined) {
info.message = 'Error fetching coordinator role from cache!';
return info;
}
if (member.roles.cache.has(IDs.roles.vegan.vegan)) {
info.message = `${user} is already vegan, cannot give the ${convinced.name} role!`;
return info;
} }
// Checks if the user has Convinced and to give them or remove them based on if they have it // 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)) { if (member.roles.cache.has(IDs.roles.nonvegan.convinced)) {
// Remove the Veg Curious role from the user // Remove the Convinced role from the user
await user.roles.remove(convinced); await member.roles.remove(convinced);
await message.reply({ info.message = `Removed the ${convinced.name} role from ${user}`;
content: `Removed the ${convinced.name} role from ${user}`, return info;
}); }
} else { // Add Convinced role to the user
// Give Convinced role to the user await member.roles.add(convinced);
await user.roles.add(convinced); info.message = `Gave ${user} the ${convinced.name} role!`;
await message.reply({
content: `Gave ${user} the ${convinced.name} role!`,
});
await user.send(`You have been given the ${convinced.name} role by ${mod}!` 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 ' + '\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! :)' + 'and other parts of the server! :)'
+ '\n\nThank you for caring about the animals 💚') + '\n\nThank you for caring about the animals 💚')
.catch(() => message.reply('User\'s DMs are closed.')); .catch(() => {});
}
// Checks if the user is xlevra to send a very kind message info.success = true;
if (mod.id === '259624904746467329') { return info;
await message.reply('Moist!');
}
await message.react('✅');
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class PlusCommand extends Command { export class PlusCommand extends Command {
@ -51,80 +51,43 @@ export class PlusCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mod = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || guild === null || mod === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const plus = guild.roles.cache.get(IDs.roles.vegan.plus);
// Checks if guildMember is null const info = await this.managePlus(user, mod, guild);
if (guildMember === undefined || plus === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user is not vegan await interaction.editReply(info.message);
if (!guildMember.roles.cache.has(IDs.roles.vegan.vegan)) {
await interaction.reply({
content: `${user} is not vegan!`,
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user has Plus and to give them or remove them based on if they have it
if (guildMember.roles.cache.has(IDs.roles.vegan.plus)) {
// Remove the Plus role from the user
await guildMember.roles.remove(plus);
await interaction.reply({
content: `Removed the ${plus.name} role from ${user}`,
fetchReply: true,
});
return;
}
// Add Plus role to the user
await guildMember.roles.add(plus);
await interaction.reply({
content: `Gave ${user} the ${plus.name} role!`,
fetchReply: true,
});
await user.send(`You have been given the ${plus.name} role by ${mod}!`)
.catch(() => {});
} }
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mod = message.member; const mod = message.author;
if (mod === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
await message.reply('Moderator not found! Try again or contact a developer!'); await message.reply('Coordinator not found! Try again or contact a developer!');
return; return;
} }
@ -136,37 +99,45 @@ export class PlusCommand extends Command {
return; return;
} }
const plus = guild.roles.cache.get(IDs.roles.vegan.plus); const info = await this.managePlus(user, mod, guild);
if (plus === undefined) { await message.reply(info.message);
await message.react('❌'); await message.react(info.success ? '✅' : '❌');
await message.reply('Role not found! Try again or contact a developer!');
return;
} }
if (!user.roles.cache.has(IDs.roles.vegan.vegan)) { private async managePlus(user: User, mod: User, guild: Guild) {
await message.react('❌'); const info = {
await message.reply(`${user} is not vegan!`); message: '',
return; success: false,
};
const member = guild.members.cache.get(user.id);
const plus = guild.roles.cache.get(IDs.roles.vegan.plus);
// Checks if user's GuildMember was found in cache
if (member === undefined) {
info.message = 'Error fetching guild member for the user!';
return info;
}
if (plus === undefined) {
info.message = 'Error fetching plus role from cache!';
return info;
} }
// Checks if the user has Plus and to give them or remove them based on if they have it // Checks if the user has Plus and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.vegan.plus)) { if (member.roles.cache.has(IDs.roles.vegan.plus)) {
// Remove the Plus role from the user // Remove the Plus role from the user
await user.roles.remove(plus); await member.roles.remove(plus);
await message.reply({ info.message = `Removed the ${plus.name} role from ${user}`;
content: `Removed the ${plus.name} role from ${user}`, return info;
}); }
} else { // Add Plus role to the user
// Give Plus role to the user await member.roles.add(plus);
await user.roles.add(plus); info.message = `Gave ${user} the ${plus.name} role!`;
await message.reply({
content: `Gave ${user} the ${plus.name} role!`,
});
await user.send(`You have been given the ${plus.name} role by ${mod}!`) await user.send(`You have been given the ${plus.name} role by ${mod}!`)
.catch(() => {}); .catch(() => {});
} info.success = true;
return info;
await message.react('✅');
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class TrustedCommand extends Command { export class TrustedCommand extends Command {
@ -51,73 +51,43 @@ export class TrustedCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mod = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || guild === null || mod === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const trusted = guild.roles.cache.get(IDs.roles.trusted);
// Checks if guildMember is null const info = await this.manageTrusted(user, mod, guild);
if (guildMember === undefined || trusted === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user has Trusted and to give them or remove them based on if they have it await interaction.editReply(info.message);
if (guildMember.roles.cache.has(IDs.roles.trusted)) {
// Remove the Trusted role from the user
await guildMember.roles.remove(trusted);
await interaction.reply({
content: `Removed the ${trusted.name} role from ${user}`,
fetchReply: true,
});
return;
}
// Add Trusted role to the user
await guildMember.roles.add(trusted);
await interaction.reply({
content: `Gave ${user} the ${trusted.name} role!`,
fetchReply: true,
});
await user.send(`You have been given the ${trusted.name} role by ${mod}!`
+ '\n\nThis role allows you to post attachments to the server and stream in VCs.'
+ '\nMake sure that you follow the rules, don\'t post anything NSFW, anything objectifying animals and follow Discord\'s ToS.'
+ `\nNot following these rules can result in the removal of the ${trusted.name} role.`)
.catch(() => {});
} }
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mod = message.member; const mod = message.author;
if (mod === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
await message.reply('Moderator not found! Try again or contact a developer!'); await message.reply('Mod not found! Try again or contact a developer!');
return; return;
} }
@ -129,34 +99,48 @@ export class TrustedCommand extends Command {
return; return;
} }
const info = await this.manageTrusted(user, mod, guild);
await message.reply(info.message);
await message.react(info.success ? '✅' : '❌');
}
private async manageTrusted(user: User, mod: User, guild: Guild) {
const info = {
message: '',
success: false,
};
const member = guild.members.cache.get(user.id);
const trusted = guild.roles.cache.get(IDs.roles.trusted); const trusted = guild.roles.cache.get(IDs.roles.trusted);
// Checks if user's GuildMember was found in cache
if (member === undefined) {
info.message = 'Error fetching guild member for the user!';
return info;
}
if (trusted === undefined) { if (trusted === undefined) {
await message.react('❌'); info.message = 'Error fetching trusted role from cache!';
await message.reply('Role not found! Try again or contact a developer!'); return info;
return;
} }
// Checks if the user has Trusted 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)) { if (member.roles.cache.has(IDs.roles.trusted)) {
// Remove the Veg Curious role from the user // Remove the Trusted role from the user
await user.roles.remove(trusted); await member.roles.remove(trusted);
await message.reply({ info.message = `Removed the ${trusted.name} role from ${user}`;
content: `Removed the ${trusted.name} role from ${user}`, return info;
}); }
} else { // Add Trusted role to the user
// Give Trusted role to the user await member.roles.add(trusted);
await user.roles.add(trusted); info.message = `Gave ${user} the ${trusted.name} role!`;
await message.reply({
content: `Gave ${user} the ${trusted.name} role!`,
});
await user.send(`You have been given the ${trusted.name} role by ${mod}!` await user.send(`You have been given the ${trusted.name} role by ${mod}!`
+ '\n\nThis role allows you to post attachments to the server and stream in VCs.' + '\n\nThis role allows you to post attachments to the server and stream in VCs.'
+ '\nMake sure that you follow the rules, and don\'t post anything NSFW, anything objectifying animals and follow Discord\'s ToS.' + '\nMake sure that you follow the rules, and don\'t post anything NSFW, anything objectifying animals and follow Discord\'s ToS.'
+ `\nNot following these rules can result in the removal of the ${trusted.name} role.`) + `\nNot following these rules can result in the removal of the ${trusted.name} role.`)
.catch(() => {}); .catch(() => {});
} info.success = true;
return info;
await message.react('✅');
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class VeganCommand extends Command { export class VeganCommand extends Command {
@ -51,104 +51,43 @@ export class VeganCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mod = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || mod === null || guild === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const modMember = guild.members.cache.get(mod.user.id);
const vegan = guild.roles.cache.get(IDs.roles.vegan.vegan);
const verCoordinator = guild.roles.cache.get(IDs.roles.staff.verifierCoordinator);
// Checks if guildMember is null const info = await this.manageVegan(user, mod, guild);
if (guildMember === undefined
|| modMember === undefined
|| vegan === undefined
|| verCoordinator === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user is vegan await interaction.editReply(info.message);
if (guildMember.roles.cache.has(IDs.roles.vegan.vegan)
&& !(modMember.roles.cache.has(IDs.roles.staff.verifierCoordinator)
|| modMember.roles.cache.has(IDs.roles.staff.modCoordinator))) {
await interaction.reply({
content: `${user} is vegan, only ${verCoordinator.name} can run this!`,
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user has Vegan and to give them or remove them based on if they have it
if (guildMember.roles.cache.has(IDs.roles.vegan.vegan)) {
// Remove the Vegan role from the user
await guildMember.roles.add(IDs.roles.nonvegan.nonvegan);
await guildMember.roles.remove([
vegan,
IDs.roles.vegan.activist,
IDs.roles.vegan.nvAccess,
]);
await interaction.reply({
content: `Removed the ${vegan.name} role from ${user}`,
ephemeral: true,
fetchReply: true,
});
return;
}
// Add Vegan role to the user
await guildMember.roles.add([
vegan,
IDs.roles.vegan.nvAccess,
]);
await guildMember.roles.remove([
IDs.roles.nonvegan.nonvegan,
IDs.roles.nonvegan.convinced,
IDs.roles.nonvegan.vegCurious,
]);
await interaction.reply({
content: `Gave ${user} the ${vegan.name} role!`,
ephemeral: true,
fetchReply: true,
});
await guildMember.send(`You have been given the ${vegan.name} role by ${mod.user}!`)
.catch(() => {});
} }
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mod = message.member; const mod = message.author;
if (mod === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
await message.reply('Verifier not found! Try again or contact a developer!'); await message.reply('Staff not found! Try again or contact a developer!');
return; return;
} }
@ -160,50 +99,69 @@ export class VeganCommand extends Command {
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null const info = await this.manageVegan(user, mod, guild);
await message.reply(info.message);
await message.react(info.success ? '✅' : '❌');
}
private async manageVegan(user: User, mod: User, guild: Guild) {
const info = {
message: '',
success: false,
};
const member = guild.members.cache.get(user.id);
const modMember = guild.members.cache.get(mod.id);
const vegan = guild.roles.cache.get(IDs.roles.vegan.vegan); const vegan = guild.roles.cache.get(IDs.roles.vegan.vegan);
const verCoordinator = guild.roles.cache.get(IDs.roles.staff.verifierCoordinator);
if (vegan === undefined // Checks if user's GuildMember was found in cache
|| verCoordinator === undefined) { if (member === undefined) {
await message.react('❌'); info.message = 'Error fetching guild member for the user!';
await message.reply('Role not found! Try again or contact a developer!'); return info;
return;
} }
// Checks if the user is vegan if (modMember === undefined) {
if (user.roles.cache.has(IDs.roles.vegan.vegan) info.message = 'Error fetching the staff\'s guild member!';
|| !(mod.roles.cache.has(IDs.roles.staff.verifierCoordinator) return info;
|| mod.roles.cache.has(IDs.roles.staff.modCoordinator))) {
await message.reply({
content: `${user} is vegan, only ${verCoordinator.name} can run this!`,
});
await message.react('❌');
return;
} }
// Checks if the user has Vegan and to give them or remove them based on if they have it if (vegan === undefined) {
if (user.roles.cache.has(IDs.roles.vegan.vegan)) { info.message = 'Error fetching vegan role from cache!';
// Remove the Veg Curious role from the user return info;
await user.roles.add(IDs.roles.nonvegan.nonvegan); }
await user.roles.remove([
// Checks if the user is Vegan and to give them or remove them based on if they have it
if (member.roles.cache.has(IDs.roles.vegan.vegan)) {
if (!modMember.roles.cache.hasAny(
IDs.roles.staff.verifierCoordinator,
IDs.roles.staff.modCoordinator,
)) {
info.message = 'You need to be a verifier coordinator to remove these roles!';
return info;
}
// Remove the Vegan role from the user
await member.roles.add(IDs.roles.nonvegan.nonvegan);
await member.roles.remove([
vegan, vegan,
IDs.roles.vegan.activist, IDs.roles.vegan.activist,
]); ]);
await message.react('✅'); info.message = `Removed the ${vegan.name} role from ${user}`;
return; return info;
} }
// Add Vegan role to the user // Add Vegan role to the user
await user.roles.add(vegan); await member.roles.add(vegan);
await user.roles.remove([ await member.roles.remove([
IDs.roles.nonvegan.nonvegan, IDs.roles.nonvegan.nonvegan,
IDs.roles.nonvegan.convinced, IDs.roles.nonvegan.convinced,
IDs.roles.nonvegan.vegCurious, IDs.roles.nonvegan.vegCurious,
]); ]);
await message.react('✅'); info.message = `Gave ${user} the ${vegan.name} role!`;
await user.send(`You have been given the ${vegan.name} role by ${mod.user}!`) await user.send(`You have been given the ${vegan.name} role by ${mod}!`)
.catch(() => {}); .catch(() => {});
info.success = true;
return info;
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
import { Args, Command, RegisterBehavior } from '@sapphire/framework'; import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { GuildMember, Message } from 'discord.js'; import type { Guild, User, Message } from 'discord.js';
import IDs from '#utils/ids'; import IDs from '#utils/ids';
export class VegCuriousCommand extends Command { export class VegCuriousCommand extends Command {
@ -51,92 +51,43 @@ export class VegCuriousCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// TODO add database updates // TODO add database updates
// Get the arguments // Get the arguments
const user = interaction.options.getUser('user'); const user = interaction.options.getUser('user', true);
const mentor = interaction.member; const mod = interaction.user;
const { guild } = interaction; const { guild } = interaction;
// Checks if all the variables are of the right type // Checks if all the variables are of the right type
if (user === null || mentor === null || guild === null) { if (guild === null) {
await interaction.reply({ await interaction.reply({
content: 'Error fetching user!', content: 'Error fetching guild!',
ephemeral: true, ephemeral: true,
fetchReply: true, fetchReply: true,
}); });
return; return;
} }
// Gets guildMember whilst removing the ability of each other variables being null await interaction.deferReply({ ephemeral: true });
const guildMember = guild.members.cache.get(user.id);
const mentorMember = guild.members.cache.get(mentor.user.id);
const vegCurious = guild.roles.cache.get(IDs.roles.nonvegan.vegCurious);
const mentorCoordinator = guild.roles.cache.get(IDs.roles.staff.mentorCoordinator);
const dietSupport = guild.channels.cache.get(IDs.channels.dietSupport.main);
// Checks if guildMember is null const info = await this.manageVegCurious(user, mod, guild);
if (guildMember === undefined
|| mentorMember === undefined
|| vegCurious === undefined
|| mentorCoordinator === undefined
|| dietSupport === undefined) {
await interaction.reply({
content: 'Error fetching user!',
ephemeral: true,
fetchReply: true,
});
return;
}
// Checks if the user is vegan await interaction.editReply(info.message);
if (guildMember.roles.cache.has(IDs.roles.vegan.vegan)
&& !mentorMember.roles.cache.has(IDs.roles.staff.mentorCoordinator)) {
await interaction.reply({
content: `${user} is vegan, only ${mentorCoordinator.name} can run this!`,
ephemeral: true,
fetchReply: true,
});
return;
}
// 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,
});
await guildMember.send(`You have been given the ${vegCurious.name} role by ${mentor.user} `
+ `which gives you access to ${dietSupport}`).catch(() => {});
} }
public async messageRun(message: Message, args: Args) { public async messageRun(message: Message, args: Args) {
// Get arguments // Get arguments
let user: GuildMember; let user: User;
try { try {
user = await args.pick('member'); user = await args.pick('user');
} catch { } catch {
await message.react('❌'); await message.react('❌');
await message.reply('User was not provided!'); await message.reply('User was not provided!');
return; return;
} }
const mentor = message.member; const mod = message.author;
if (mentor === null) { if (mod === null) {
await message.react('❌'); await message.react('❌');
await message.reply('Mentor not found! Try again or contact a developer!'); await message.reply('Staff not found! Try again or contact a developer!');
return; return;
} }
@ -148,41 +99,57 @@ export class VegCuriousCommand extends Command {
return; return;
} }
const info = await this.manageVegCurious(user, mod, guild);
await message.reply(info.message);
await message.react(info.success ? '✅' : '❌');
}
private async manageVegCurious(user: User, mod: User, guild: Guild) {
const info = {
message: '',
success: false,
};
const member = guild.members.cache.get(user.id);
const modMember = guild.members.cache.get(mod.id);
const vegCurious = guild.roles.cache.get(IDs.roles.nonvegan.vegCurious); const vegCurious = guild.roles.cache.get(IDs.roles.nonvegan.vegCurious);
const mentorCoordinator = guild.roles.cache.get(IDs.roles.staff.mentorCoordinator);
const dietSupport = guild.channels.cache.get(IDs.channels.dietSupport.main);
if (vegCurious === undefined // Checks if user's GuildMember was found in cache
|| mentorCoordinator === undefined if (member === undefined) {
|| dietSupport === undefined) { info.message = 'Error fetching guild member for the user!';
await message.react('❌'); return info;
await message.reply('Role not found! Try again or contact a developer!');
return;
} }
// Checks if the user is vegan if (modMember === undefined) {
if (user.roles.cache.has(IDs.roles.vegan.vegan) info.message = 'Error fetching the staff\'s guild member!';
&& !mentor.roles.cache.has(IDs.roles.staff.mentorCoordinator)) { return info;
await message.reply({ }
content: `${user} is vegan, only ${mentorCoordinator.name} can run this!`,
}); if (vegCurious === undefined) {
await message.react('❌'); info.message = 'Error fetching veg curious role from cache!';
return; return info;
}
// Checks if the user is Veg Curious and to give them or remove them based on if they have it
if (member.roles.cache.has(IDs.roles.nonvegan.vegCurious)) {
if (!modMember.roles.cache.has(IDs.roles.staff.mentorCoordinator)) {
info.message = 'You need to be a mentor coordinator to remove this role!';
return info;
} }
// Checks if the user has Veg Curious and to give them or remove them based on if they have it
if (user.roles.cache.has(IDs.roles.nonvegan.vegCurious)) {
// Remove the Veg Curious role from the user // Remove the Veg Curious role from the user
await user.roles.remove(vegCurious); await member.roles.remove(vegCurious);
await message.react('✅'); info.message = `Removed the ${vegCurious.name} role from ${user}`;
return; return info;
} }
// Add Veg Curious role to the user // Add Veg Curious role to the user
await user.roles.add(vegCurious); await member.roles.add(vegCurious);
await message.react('✅'); info.message = `Gave ${user} the ${vegCurious.name} role!`;
await user.send(`You have been given the ${vegCurious.name} role by ${mentor.user} ` await user.send(`You have been given the ${vegCurious.name} role by ${mod} `
+ `which gives you access to ${dietSupport}`).catch(() => {}); + 'which gives you access to the diet support section').catch(() => {});
info.success = true;
return info;
} }
} }