From a9cf34717b7e78027c2e3353fb5b53ffbc0d7c7b Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 18 Jun 2020 12:09:29 -0500 Subject: [PATCH] fumck --- .vscode/launch.json | 17 +++++++++++++++++ src/index.js | 45 ++++++++++++++++++++------------------------- 2 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6203425 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}/src/index.js" + } + ] +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 02f93fc..42c715d 100755 --- a/src/index.js +++ b/src/index.js @@ -238,33 +238,28 @@ client.on("message", async message => { /////////Funny DHS is funny/////////// ////////////////////////////////////// if (command == "xkcd") { - let comic = "" - if (!isNaN(args[0])) { - fetch(`https://xkcd.com/${args[0]}/info.0.json`) - .then(res => res.json()) - .then(json => comic = json) - // eslint-disable-next-line no-unused-vars - .catch(err => message.reply("Something went wrong... Check your number and try again later.")); - - let embed = new Discord.MessageEmbed() - .setTitle(`xkcd #${args[0]}`) - .setAuthor("Randel Munroe") - .setColor(0xffffff) - .image(`${comic.img}`); - return message.channel.send(embed); + async function getcomic(args) { + var comic + try { + var response = await fetch(`https://xkcd.com/${args[0]}/info.0.json`); + comic = await response.text(); + } catch (e) { + console.error(e); + return message.reply("Something went wrong... Check your number and try again later.") } - fetch(`https://xkcd.com/info.0.json`) - .then(res => res.json()) - .then(json => comic = json) - // eslint-disable-next-line no-unused-vars - .catch(err => message.reply("Something went wrong... Check your number and try again later.")); - let embed = new Discord.MessageEmbed() - .setTitle(`xkcd #${args[0]}`) - .setAuthor("Randel Munroe") - .setColor(0xffffff) - .image(`${comic.img}`); - return message.channel.send(embed); + } + + + getcomic(); + + let embed = new Discord.MessageEmbed() + .setTitle(`xkcd #${comic.num}`) + .setAuthor("Randel Munroe") + .setColor(0xffffff) + .image(`${comic.img}`); + return message.channel.send(embed); + } });