diff --git a/commands/reload-gifs.js b/commands/reload-gifs.js new file mode 100644 index 0000000..ce63611 --- /dev/null +++ b/commands/reload-gifs.js @@ -0,0 +1,7 @@ +module.exports = { + name: "reload-gifs", + description: "Refresh the hardcoded gif library.", + execute(message, args) { + getGifFiles(); + } +} \ No newline at end of file diff --git a/gifs/dab.js b/gifs/dab.js new file mode 100644 index 0000000..12e46a4 --- /dev/null +++ b/gifs/dab.js @@ -0,0 +1,4 @@ +module.exports = { + name: "dab", + embed_url: "https://giphy.com/embed/lae7QSMFxEkkE" +} \ No newline at end of file diff --git a/gifs/nod.js b/gifs/nod.js new file mode 100644 index 0000000..23eb602 --- /dev/null +++ b/gifs/nod.js @@ -0,0 +1,4 @@ +module.exports = { + name: "nod", + embed_url: "https://tenor.com/view/smile-nod-yes-robert-redford-beard-gif-10489927" +} \ No newline at end of file diff --git a/gifs/psh.js b/gifs/psh.js new file mode 100644 index 0000000..dfd3885 --- /dev/null +++ b/gifs/psh.js @@ -0,0 +1,4 @@ +module.exports = { + name: "psh", + embed_url: "https://tenor.com/view/ed-bassmaster-youtuber-youtube-influencer-psh-gif-10556767" +} \ No newline at end of file diff --git a/gifs/shedsalive.js b/gifs/shedsalive.js new file mode 100644 index 0000000..49e998f --- /dev/null +++ b/gifs/shedsalive.js @@ -0,0 +1,4 @@ +module.exports = { + name: "shedsalive", + embed_url: "https://giphy.com/embed/glL1yvxJ4KvYc" +} \ No newline at end of file diff --git a/gifs/shedsdead.js b/gifs/shedsdead.js new file mode 100644 index 0000000..ca3c725 --- /dev/null +++ b/gifs/shedsdead.js @@ -0,0 +1,4 @@ +module.exports = { + name: "shedsdead", + embed_url: "http://voidf1sh.me/shedsdead.gif" +} \ No newline at end of file diff --git a/gifs/template b/gifs/template new file mode 100644 index 0000000..1df103a --- /dev/null +++ b/gifs/template @@ -0,0 +1,3 @@ +module.exports = { + +} \ No newline at end of file diff --git a/index.js b/index.js index 503eefb..c977f2e 100644 --- a/index.js +++ b/index.js @@ -6,11 +6,14 @@ dotenv.config(); const Discord = require('discord.js'); const client = new Discord.Client(); client.commands = new Discord.Collection(); +client.gifs = new Discord.Collection(); const debug = true; -const config = require('./config.json'); -const { prefix, serverID } = require('./config.json'); +// const config = require('./config.json'); +const { prefix } = require('./config.json'); const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); +const gifFiles = fs.readdirSync('./gifs').filter(file => file.endsWith('.js')); // const owner = process.env.ownerID; +const giphy = require('giphy-api')(process.env.giphyAPIKey); function getCommandFiles() { for (const file of commandFiles) { @@ -20,6 +23,14 @@ function getCommandFiles() { if (debug) console.log(client.commands); } +function getGifFiles() { + for (const file of gifFiles) { + const gif = require(`./gifs/${file}`); + client.gifs.set(gif.name, gif); + } + if (debug) console.log(client.gifs); +} + function extCheck(content) { const lastFour = content.slice(-4); switch (lastFour) { @@ -34,27 +45,47 @@ function extCheck(content) { client.once('ready', () => { console.log('Ready'); - client.guilds.fetch(serverID) - .then(guild => client.user.setActivity('Nod Simulator 2021', {type: "PLAYING"})) - .catch(console.error); + client.user.setActivity('Nod Simulator 2021', { type: 'PLAYING' }).then().catch(console.error); getCommandFiles(); + getGifFiles(); }); client.login(process.env.TOKEN); client.on('message', message => { - if (debug) console.log(extCheck(message.content)); - if (!message.content.startsWith(prefix) || message.author.bot || !extCheck(message.content)) return; + const ext = extCheck(message.content); + if (debug) console.log(ext); + if ((!message.content.startsWith(prefix) && ext == false) || message.author.bot) return; - const args = message.content.slice(prefix.length).trim().split(/ +/); - const command = args.shift().toLowerCase(); + if (message.content.startsWith(prefix)) { + const args = message.content.slice(prefix.length).trim().split(/ +/); + const command = args.shift().toLowerCase(); - if (!client.commands.has(command)) return; + if (!client.commands.has(command)) return; - try { - client.commands.get(command).execute(message, args); - } catch (error) { - console.error(error); - message.reply('There was an error trying to execute that command.'); + try { + client.commands.get(command).execute(message, args); + } catch (error) { + console.error(error); + message.channel.send('There was an error trying to execute that command.'); + } + } + + if (ext == 'gif') { + const query = message.content.slice(0, -4); + if (debug) console.log(query); + + if (!client.gifs.has(query)) { + giphy.search(query, (err, res) => { + if (res.data[0] != undefined) { + message.channel.send(res.data[0].embed_url).then().catch(console.error); + } else { + message.channel.send('I was unable to find a gif of ' + query); + } + if (err) console.error(err); + }); + } else { + message.channel.send(client.gifs.get(query).embed_url); + } } }); \ No newline at end of file