From 1173e6e629d41a8e797747b0578dd735c768cbe5 Mon Sep 17 00:00:00 2001 From: Atridad Lahiji <88056492+atridadl@users.noreply.github.com> Date: Thu, 15 Jun 2023 12:49:31 -0600 Subject: [PATCH] Quik updates --- src/commands/borf.ts | 2 +- src/commands/joke.ts | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/commands/joke.ts diff --git a/src/commands/borf.ts b/src/commands/borf.ts index ff6d5c7..bd29258 100644 --- a/src/commands/borf.ts +++ b/src/commands/borf.ts @@ -34,7 +34,7 @@ export class UserCommand extends Command { content: dogData.status === 'success' ? dogData.message : 'Error: I had troubles fetching perfect puppies for you... :(' }) : await interactionOrMessage.reply({ - content: 'success' ? dogData.message : 'Error: I had troubles fetching perfect puppies for you... :(', + content: dogData.status === 'success' ? dogData.message : 'Error: I had troubles fetching perfect puppies for you... :(', fetchReply: true }); } diff --git a/src/commands/joke.ts b/src/commands/joke.ts new file mode 100644 index 0000000..cec2de1 --- /dev/null +++ b/src/commands/joke.ts @@ -0,0 +1,45 @@ +import { ApplyOptions } from '@sapphire/decorators'; +import { Command } from '@sapphire/framework'; +import { Message } from 'discord.js'; + +@ApplyOptions({ + description: 'Dad joke for daddies only!' +}) +export class UserCommand extends Command { + // Register Chat Input and Context Menu command + public override registerApplicationCommands(registry: Command.Registry) { + // Register Chat Input command + registry.registerChatInputCommand({ + name: this.name, + description: this.description + }); + } + + // Message command + public async messageRun(message: Message) { + return this.sendJoke(message); + } + + // Chat Input (slash) command + public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { + return this.sendJoke(interaction); + } + + private async sendJoke(interactionOrMessage: Message | Command.ChatInputCommandInteraction | Command.ContextMenuCommandInteraction) { + const jokeResponse = await fetch('https://icanhazdadjoke.com/', { + headers: { + Accept: 'application/json' + } + }); + const jokeData = await jokeResponse.json(); + + interactionOrMessage instanceof Message + ? await interactionOrMessage.channel.send({ + content: jokeData.status === 200 ? jokeData.joke : '404 Joke Not Found' + }) + : await interactionOrMessage.reply({ + content: jokeData.status === 200 ? jokeData.joke : '404 Joke Not Found', + fetchReply: true + }); + } +}