Hardcoding Links

This commit is contained in:
= 2021-06-26 21:24:14 -04:00
parent c39e009df8
commit 89592c5719
3 changed files with 54 additions and 23 deletions

View File

@ -1,3 +0,0 @@
{
"nod": ""
}

View File

@ -5,17 +5,13 @@ const Discord = require('discord.js');
const client = new Discord.Client(); const client = new Discord.Client();
const giphy = require('giphy-api')(process.env.giphyAPIKey); const giphy = require('giphy-api')(process.env.giphyAPIKey);
const debug = true; const debug = true;
// const gifs = require('gifs.json'); const links = require('./links.json');
dotenv.config(); dotenv.config();
const owner = process.env.ownerID; const owner = process.env.ownerID;
async function getUser(id) { if (debug) {
const user = await client.users.fetch(id); console.log(links);
if (debug) {
console.log(user);
}
return user;
} }
client.once('ready', () => { client.once('ready', () => {
@ -27,22 +23,36 @@ client.login(process.env.TOKEN);
client.on('message', message => { client.on('message', message => {
const pre = message.content.slice(0, -4); const pre = message.content.slice(0, -4);
const ext = message.content.slice(-4); const ext = message.content.slice(-4);
let gifFound = false;
switch (ext) { switch (ext) {
case '.gif': case '.gif':
try { if (debug) {
giphy.search(pre, function(err, res) { console.log('pre: ' + pre);
if (res.data[0] != undefined) { console.log('ext: ' + ext);
message.channel.send(res.data[0].embed_url); }
} else { for (let index = 0; index < links.gifs.length; index++) {
message.channel.send('Sorry, I was unable to find a gif of ' + pre + '.'); const gif = links.gifs[index];
} if (gif.name == pre) {
if (err) { message.channel.send(gif.embed_url);
console.log(err); gifFound = true;
} }
}); }
} catch (error) { if (gifFound == false) {
console.log(error); 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; break;
// Admin Commands // Admin Commands

24
links.json Normal file
View File

@ -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"
}
]
}