From 89592c5719224e9ca30da8a2124852440e399c0c Mon Sep 17 00:00:00 2001 From: = Date: Sat, 26 Jun 2021 21:24:14 -0400 Subject: [PATCH] Hardcoding Links --- gifs.json | 3 --- index.js | 50 ++++++++++++++++++++++++++++++-------------------- links.json | 24 ++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 23 deletions(-) delete mode 100644 gifs.json create mode 100644 links.json diff --git a/gifs.json b/gifs.json deleted file mode 100644 index d14686b..0000000 --- a/gifs.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "nod": "" -} \ No newline at end of file diff --git a/index.js b/index.js index 23e1f94..07c87fe 100644 --- a/index.js +++ b/index.js @@ -5,17 +5,13 @@ const Discord = require('discord.js'); const client = new Discord.Client(); const giphy = require('giphy-api')(process.env.giphyAPIKey); const debug = true; -// const gifs = require('gifs.json'); +const links = require('./links.json'); dotenv.config(); const owner = process.env.ownerID; -async function getUser(id) { - const user = await client.users.fetch(id); - if (debug) { - console.log(user); - } - return user; +if (debug) { + console.log(links); } client.once('ready', () => { @@ -27,22 +23,36 @@ client.login(process.env.TOKEN); client.on('message', message => { const pre = message.content.slice(0, -4); const ext = message.content.slice(-4); + let gifFound = false; switch (ext) { case '.gif': - try { - giphy.search(pre, function(err, res) { - if (res.data[0] != undefined) { - message.channel.send(res.data[0].embed_url); - } else { - message.channel.send('Sorry, I was unable to find a gif of ' + pre + '.'); - } - if (err) { - console.log(err); - } - }); - } catch (error) { - console.log(error); + if (debug) { + console.log('pre: ' + pre); + console.log('ext: ' + ext); + } + for (let index = 0; index < links.gifs.length; index++) { + const gif = links.gifs[index]; + if (gif.name == pre) { + message.channel.send(gif.embed_url); + gifFound = true; + } + } + if (gifFound == false) { + try { + giphy.search(pre, function(err, res) { + if (res.data[0] != undefined) { + message.channel.send(res.data[0].embed_url); + } else { + message.channel.send('Sorry, I was unable to find a gif of ' + pre + '.'); + } + if (err) { + console.log(err); + } + }); + } catch (error) { + console.log(error); + } } break; // Admin Commands diff --git a/links.json b/links.json new file mode 100644 index 0000000..4cacb21 --- /dev/null +++ b/links.json @@ -0,0 +1,24 @@ +{ + "gifs": [ + { + "name": "nod", + "embed_url": "https://tenor.com/view/smile-nod-yes-robert-redford-beard-gif-10489927" + }, + { + "name": "psh", + "embed_url": "https://tenor.com/view/ed-bassmaster-youtuber-youtube-influencer-psh-gif-10556767" + }, + { + "name": "unreal", + "embed_url": "https://tenor.com/view/unreall-gif-15193874" + }, + { + "name": "lookatit", + "embed_url": "https://tenor.com/view/just-look-at-it-gif-11036230" + }, + { + "name": "foolme", + "embed_url": "https://tenor.com/view/george-bush-fool-me-once-brave-gif-12227074" + } + ] +} \ No newline at end of file