feat(arabot): add type checking and made footers for existing embeds better

This commit is contained in:
Anthony 2024-01-09 19:10:29 +00:00
parent 7943a2d1b8
commit 5bbc5057fc
8 changed files with 157 additions and 46 deletions

View File

@ -18,7 +18,7 @@
*/ */
import { Command, RegisterBehavior } from '@sapphire/framework'; import { Command, RegisterBehavior } from '@sapphire/framework';
import { EmbedBuilder } from 'discord.js'; import { EmbedBuilder, GuildMember } from 'discord.js';
import { N1984 } from '#utils/gifs'; import { N1984 } from '#utils/gifs';
import { addFunLog, countTotal } from '#utils/database/fun'; import { addFunLog, countTotal } from '#utils/database/fun';
@ -45,10 +45,26 @@ export class N1984Command extends Command {
// Command run // Command run
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// Get the user // Get the user
const { user } = interaction; const { member } = interaction;
await addFunLog(user.id, '1984'); // Type checks
const count = await countTotal(user.id, '1984'); if (!(member instanceof GuildMember)) {
await interaction.reply({
ephemeral: true,
content: 'Failed to fetch your user on the bot!',
});
return;
}
await addFunLog(member.id, '1984');
const count = await countTotal(member.id, '1984');
let embedFooter: string;
if (count === 1) {
embedFooter = `${member.displayName} 1984'd the server for the first time!`;
} else {
embedFooter = `${member.displayName} 1984'd the server ${count} times!`;
}
// Creates the embed for the 1984 reaction // Creates the embed for the 1984 reaction
// Add a 1 in 1000 chance of Dantas literally making ARA 1984 // Add a 1 in 1000 chance of Dantas literally making ARA 1984
@ -58,9 +74,9 @@ export class N1984Command extends Command {
: N1984[Math.floor(Math.random() * N1984.length)]; : N1984[Math.floor(Math.random() * N1984.length)];
const n1984Embed = new EmbedBuilder() const n1984Embed = new EmbedBuilder()
.setColor('#ffffff') .setColor('#ffffff')
.setTitle(`${user.username} is happy!`) .setTitle(`${member.displayName} is happy!`)
.setImage(random1984) .setImage(random1984)
.setFooter({ text: `${user.username}'s 1984 count: ${count}` }); .setFooter({ text: embedFooter });
// Send the embed // Send the embed
await interaction.reply({ embeds: [n1984Embed], fetchReply: true }); await interaction.reply({ embeds: [n1984Embed], fetchReply: true });

View File

@ -18,7 +18,7 @@
*/ */
import { Command, RegisterBehavior } from '@sapphire/framework'; import { Command, RegisterBehavior } from '@sapphire/framework';
import { EmbedBuilder } from 'discord.js'; import { EmbedBuilder, GuildMember } from 'discord.js';
import { Cringe } from '#utils/gifs'; import { Cringe } from '#utils/gifs';
import { addFunLog, countTotal } from '#utils/database/fun'; import { addFunLog, countTotal } from '#utils/database/fun';
@ -44,19 +44,34 @@ export class CringeCommand extends Command {
// Command run // Command run
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// Get the user // Get the user
// TODO exception handling const { member } = interaction;
const { user } = interaction;
await addFunLog(user.id, 'cringe'); // Type check
const count = await countTotal(user.id, 'cringe'); if (!(member instanceof GuildMember)) {
await interaction.reply({
ephemeral: true,
content: 'Failed to fetch your user on the bot!',
});
return;
}
await addFunLog(member.id, 'cringe');
const count = await countTotal(member.id, 'cringe');
let embedFooter: string;
if (count === 1) {
embedFooter = `${member.displayName} cringed for the first time!`;
} else {
embedFooter = `${member.displayName} cringed ${count} times!`;
}
// Creates the embed for the cringe reaction // Creates the embed for the cringe reaction
const randomCringe = Cringe[Math.floor(Math.random() * Cringe.length)]; const randomCringe = Cringe[Math.floor(Math.random() * Cringe.length)];
const cringeEmbed = new EmbedBuilder() const cringeEmbed = new EmbedBuilder()
.setColor('#001148') .setColor('#001148')
.setTitle(`${user.username} feels immense cringe...`) .setTitle(`${member.displayName} feels immense cringe...`)
.setImage(randomCringe) .setImage(randomCringe)
.setFooter({ text: `${user.username}'s cringe count: ${count}` }); .setFooter({ text: embedFooter });
// Send the embed // Send the embed
await interaction.reply({ embeds: [cringeEmbed], fetchReply: true }); await interaction.reply({ embeds: [cringeEmbed], fetchReply: true });

View File

@ -18,7 +18,7 @@
*/ */
import { Command, RegisterBehavior } from '@sapphire/framework'; import { Command, RegisterBehavior } from '@sapphire/framework';
import { EmbedBuilder } from 'discord.js'; import { EmbedBuilder, GuildMember } from 'discord.js';
import { Happy } from '#utils/gifs'; import { Happy } from '#utils/gifs';
export class HappyCommand extends Command { export class HappyCommand extends Command {
@ -44,15 +44,22 @@ export class HappyCommand extends Command {
// Command run // Command run
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// Get the user // Get the user
// TODO exception handling const { member } = interaction;
const member = interaction.member!.user;
const memberGuildMember = interaction.guild!.members.cache.get(member.id)!; // Type checks
if (!(member instanceof GuildMember)) {
await interaction.reply({
ephemeral: true,
content: 'Failed to fetch your user on the bot!',
});
return;
}
// Creates the embed for the happy reaction // Creates the embed for the happy reaction
const randomHappy = Happy[Math.floor(Math.random() * Happy.length)]; const randomHappy = Happy[Math.floor(Math.random() * Happy.length)];
const happyEmbed = new EmbedBuilder() const happyEmbed = new EmbedBuilder()
.setColor('#40ff00') .setColor('#40ff00')
.setTitle(`${memberGuildMember.displayName} is happy!`) .setTitle(`${member.displayName} is happy!`)
.setImage(randomHappy); .setImage(randomHappy);
// Send the embed // Send the embed

View File

@ -18,7 +18,7 @@
*/ */
import { Command, RegisterBehavior } from '@sapphire/framework'; import { Command, RegisterBehavior } from '@sapphire/framework';
import { EmbedBuilder } from 'discord.js'; import { EmbedBuilder, GuildMember } from 'discord.js';
import { Hugs } from '#utils/gifs'; import { Hugs } from '#utils/gifs';
import { addFunLog, countTotal } from '#utils/database/fun'; import { addFunLog, countTotal } from '#utils/database/fun';
@ -54,20 +54,43 @@ export class HugCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// Get the users // Get the users
const user = interaction.options.getUser('user', true); const user = interaction.options.getUser('user', true);
const hugger = interaction.user; const hugger = interaction.member;
// Type Checks
if (!(hugger instanceof GuildMember)) {
await interaction.reply({
ephemeral: true,
content: 'Failed to fetch your user on the bot!',
});
return;
}
await addFunLog(hugger.id, 'hug', user.id); await addFunLog(hugger.id, 'hug', user.id);
const count = await countTotal(hugger.id, 'hug', user.id); const count = await countTotal(hugger.id, 'hug', user.id);
let embedFooter: string;
if (hugger.id === user.id) {
if (count === 1) {
embedFooter = `You hugged yourself for the first time!`;
} else {
embedFooter = `You hugged yourself ${count} times!`;
}
} else {
if (count === 1) {
embedFooter = `${hugger.displayName} hugged you for the first time!`;
} else {
embedFooter = `${hugger.displayName} hugged you ${count} times!`;
}
}
// Creates the embed for the hug // Creates the embed for the hug
const randomHug = Hugs[Math.floor(Math.random() * Hugs.length)]; const randomHug = Hugs[Math.floor(Math.random() * Hugs.length)];
const hugEmbed = new EmbedBuilder() const hugEmbed = new EmbedBuilder()
.setColor('#0099ff') .setColor('#0099ff')
.setTitle(`Hug from ${hugger.username}`) .setTitle(`Hug from ${hugger.displayName}`)
.setImage(randomHug) .setImage(randomHug)
.setFooter({ .setFooter({ text: embedFooter });
text: `Amount of hugs given from ${hugger.username} to you: ${count}`,
});
// Send the hug // Send the hug
await interaction.reply({ await interaction.reply({

View File

@ -18,7 +18,7 @@
*/ */
import { Command, RegisterBehavior } from '@sapphire/framework'; import { Command, RegisterBehavior } from '@sapphire/framework';
import { EmbedBuilder } from 'discord.js'; import { EmbedBuilder, GuildMember } from 'discord.js';
import { Kill } from '#utils/gifs'; import { Kill } from '#utils/gifs';
import { addFunLog, countTotal } from '#utils/database/fun'; import { addFunLog, countTotal } from '#utils/database/fun';
@ -54,7 +54,16 @@ export class KillCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// Get the users // Get the users
const user = interaction.options.getUser('user', true)!; const user = interaction.options.getUser('user', true)!;
const sender = interaction.user; const sender = interaction.member;
// Type checks
if (!(sender instanceof GuildMember)) {
await interaction.reply({
ephemeral: true,
content: 'Failed to fetch your user on the bot!',
});
return;
}
if (user.id === sender.id) { if (user.id === sender.id) {
await interaction.reply('You changed your mind'); await interaction.reply('You changed your mind');
@ -64,15 +73,20 @@ export class KillCommand extends Command {
await addFunLog(sender.id, 'kill', user.id); await addFunLog(sender.id, 'kill', user.id);
const count = await countTotal(sender.id, 'kill', user.id); const count = await countTotal(sender.id, 'kill', user.id);
let embedFooter: string;
if (count === 1) {
embedFooter = `${sender.displayName} killed you for the first time!`;
} else {
embedFooter = `${sender.displayName} killed you ${count} times!`;
}
// Creates the embed for the kill // Creates the embed for the kill
const randomKill = Kill[Math.floor(Math.random() * Kill.length)]; const randomKill = Kill[Math.floor(Math.random() * Kill.length)];
const killEmbed = new EmbedBuilder() const killEmbed = new EmbedBuilder()
.setColor('#ff0000') .setColor('#ff0000')
.setTitle(`Kill from ${sender.username}`) .setTitle(`Kill from ${sender.displayName}`)
.setImage(randomKill) .setImage(randomKill)
.setFooter({ .setFooter({ text: embedFooter });
text: `Amount of kills from ${sender.username} to you: ${count}`,
});
// Send the kill // Send the kill
await interaction.reply({ await interaction.reply({

View File

@ -18,7 +18,7 @@
*/ */
import { Command, RegisterBehavior } from '@sapphire/framework'; import { Command, RegisterBehavior } from '@sapphire/framework';
import { EmbedBuilder } from 'discord.js'; import { EmbedBuilder, GuildMember } from 'discord.js';
import { Poke } from '#utils/gifs'; import { Poke } from '#utils/gifs';
import { addFunLog, countTotal } from '#utils/database/fun'; import { addFunLog, countTotal } from '#utils/database/fun';
@ -54,20 +54,42 @@ export class PokeCommand extends Command {
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// Get the users // Get the users
const user = interaction.options.getUser('user', true)!; const user = interaction.options.getUser('user', true)!;
const sender = interaction.user; const sender = interaction.member;
// Type checks
if (!(sender instanceof GuildMember)) {
await interaction.reply({
ephemeral: true,
content: 'Failed to fetch your user on the bot!',
});
return;
}
await addFunLog(sender.id, 'poke', user.id); await addFunLog(sender.id, 'poke', user.id);
const count = await countTotal(sender.id, 'poke', user.id); const count = await countTotal(sender.id, 'poke', user.id);
let embedFooter: string;
if (sender.id === user.id) {
if (count === 1) {
embedFooter = `You poked yourself for the first time!`;
} else {
embedFooter = `You poked yourself ${count} times!`;
}
} else {
if (count === 1) {
embedFooter = `${sender.displayName} poked you for the first time!`;
} else {
embedFooter = `${sender.displayName} poked you ${count} times!`;
}
}
// Creates the embed for the poke // Creates the embed for the poke
const randomPoke = Poke[Math.floor(Math.random() * Poke.length)]; const randomPoke = Poke[Math.floor(Math.random() * Poke.length)];
const pokeEmbed = new EmbedBuilder() const pokeEmbed = new EmbedBuilder()
.setColor('#0099ff') .setColor('#0099ff')
.setTitle(`Poke from ${sender.username}`) .setTitle(`Poke from ${sender.displayName}`)
.setImage(randomPoke) .setImage(randomPoke)
.setFooter({ .setFooter({ text: embedFooter });
text: `Amount of pokes from ${sender.username} to you: ${count}`,
});
// Send the poke // Send the poke
await interaction.reply({ await interaction.reply({

View File

@ -18,7 +18,7 @@
*/ */
import { Command, RegisterBehavior } from '@sapphire/framework'; import { Command, RegisterBehavior } from '@sapphire/framework';
import { EmbedBuilder } from 'discord.js'; import { EmbedBuilder, GuildMember } from 'discord.js';
import { Sad } from '#utils/gifs'; import { Sad } from '#utils/gifs';
export class SadCommand extends Command { export class SadCommand extends Command {
@ -44,15 +44,22 @@ export class SadCommand extends Command {
// Command run // Command run
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// Get the user // Get the user
// TODO exception handling const { member } = interaction;
const member = interaction.member!.user;
const memberGuildMember = interaction.guild!.members.cache.get(member.id)!; // Type checks
if (!(member instanceof GuildMember)) {
await interaction.reply({
ephemeral: true,
content: 'Failed to fetch your user on the bot!',
});
return;
}
// Creates the embed for the sad reaction // Creates the embed for the sad reaction
const randomSad = Sad[Math.floor(Math.random() * Sad.length)]; const randomSad = Sad[Math.floor(Math.random() * Sad.length)];
const sadEmbed = new EmbedBuilder() const sadEmbed = new EmbedBuilder()
.setColor('#001148') .setColor('#001148')
.setTitle(`${memberGuildMember.displayName} is sad...`) .setTitle(`${member.displayName} is sad...`)
.setImage(randomSad); .setImage(randomSad);
// Send the embed // Send the embed

View File

@ -18,7 +18,7 @@
*/ */
import { Command, RegisterBehavior } from '@sapphire/framework'; import { Command, RegisterBehavior } from '@sapphire/framework';
import { EmbedBuilder } from 'discord.js'; import { EmbedBuilder, GuildMember } from 'discord.js';
import { Shrug } from '#utils/gifs'; import { Shrug } from '#utils/gifs';
export class ShrugCommand extends Command { export class ShrugCommand extends Command {
@ -44,15 +44,22 @@ export class ShrugCommand extends Command {
// Command run // Command run
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// Get the user // Get the user
// TODO exception handling const { member } = interaction;
const member = interaction.member!.user;
const memberGuildMember = interaction.guild!.members.cache.get(member.id)!; // Type checks
if (!(member instanceof GuildMember)) {
await interaction.reply({
ephemeral: true,
content: 'Failed to fetch your user on the bot!',
});
return;
}
// Creates the embed for the shrug reaction // Creates the embed for the shrug reaction
const randomShrug = Shrug[Math.floor(Math.random() * Shrug.length)]; const randomShrug = Shrug[Math.floor(Math.random() * Shrug.length)];
const shrugEmbed = new EmbedBuilder() const shrugEmbed = new EmbedBuilder()
.setColor('#001980') .setColor('#001980')
.setTitle(`${memberGuildMember.displayName} shrugs`) .setTitle(`${member.displayName} shrugs`)
.setImage(randomShrug); .setImage(randomShrug);
// Send the embed // Send the embed