From 98255e73aa89bd9cc3a42d0daaa741ee32a7e3ee Mon Sep 17 00:00:00 2001 From: Emily J Date: Fri, 23 Oct 2020 12:34:20 +1100 Subject: [PATCH] new garfield command --- package.json | 1 - src/commands/garfield.js | 23 +++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 2dea72e..23c9cbf 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "dblapi.js": "^2.4.1", "discord.js": "^12.4.0", "enmap": "^5.8.0", - "garfield": "^1.1.2", "hastebin-gen": "^2.0.5", "moment": "^2.29.1", "moment-duration-format": "^2.3.2", diff --git a/src/commands/garfield.js b/src/commands/garfield.js index 5376ded..597fe16 100644 --- a/src/commands/garfield.js +++ b/src/commands/garfield.js @@ -1,8 +1,23 @@ -const garfield = require("garfield"); +const fetch = require("node-fetch") +const { MessageEmbed } = require('discord.js') exports.run = async (client, message) => { - message.channel.send({ files: [garfield.random()] }).catch(() => message.channel.send( - "<:error:466995152976871434> API didn't respond, try again in a few seconds." - )); + message.channel.startTyping(); + try { + fetch('https://garfield-comics.glitch.me/~SRoMG/?date=xxxx') + .then(res => res.json()) + .then(json => { + const embed = new MessageEmbed() + .setTitle(`${json.data.name} (No. ${json.data.number})`) + .setColor(client.embedColour(message)) + .setURL('https://www.mezzacotta.net/garfield/?comic=' + json.data.number) + .setImage(json.data.image.src); + message.channel.send(embed) + }); + message.channel.stopTyping(); + } catch (err) { + message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`) + message.channel.stopTyping(); + }; }; exports.conf = {