From 153af5008d96b2230463752ce1f3c6fa2a5dac1a Mon Sep 17 00:00:00 2001 From: = Date: Sun, 27 Jun 2021 23:20:21 -0400 Subject: [PATCH] add ability to save gifs in chat --- commands/reload-gifs.js | 5 ++-- commands/save-gif.js | 6 ++++- functions.js | 35 +++++++++++++++++++++++++ gifs/bobsaget.js | 4 +++ gifs/cumb.js | 4 +++ gifs/{deeznuts.gif => deeznuts.js} | 0 gifs/shid.js | 4 +++ index.js | 41 +++++------------------------- 8 files changed, 61 insertions(+), 38 deletions(-) create mode 100644 functions.js create mode 100644 gifs/bobsaget.js create mode 100644 gifs/cumb.js rename gifs/{deeznuts.gif => deeznuts.js} (100%) create mode 100644 gifs/shid.js diff --git a/commands/reload-gifs.js b/commands/reload-gifs.js index 70be76a..2cf85c3 100644 --- a/commands/reload-gifs.js +++ b/commands/reload-gifs.js @@ -1,8 +1,9 @@ +/* eslint-disable quotes */ module.exports = { name: "reload-gifs", description: "Refresh the hardcoded gif library.", execute(message, args) { - const index = require('../index.js'); - index.getGifFiles(); + const functions = require('../functions.js'); + functions.getGifFiles(message.client); } } \ No newline at end of file diff --git a/commands/save-gif.js b/commands/save-gif.js index c036341..3da3aa9 100644 --- a/commands/save-gif.js +++ b/commands/save-gif.js @@ -8,9 +8,13 @@ module.exports = { } const fs = require('fs'); - fs.appendFile(`./gifs/${args[0]}.gif`, `module.exports = {\n\tname: '${args[0]}',\n\tembed_url: '${args[1]}'\n}`, function(err) { + fs.appendFile(`./gifs/${args[0]}.js`, `module.exports = {\n\tname: '${args[0]}',\n\tembed_url: '${args[1]}'\n}`, function(err) { if (err) throw err; console.log('Saved file!'); + const gif = require(`../gifs/${args[0]}.js`); + message.client.gifs.set(gif.name, gif); }); + + message.reply('GIF saved as: ' + args[0] + '.gif!'); } } \ No newline at end of file diff --git a/functions.js b/functions.js new file mode 100644 index 0000000..53576dc --- /dev/null +++ b/functions.js @@ -0,0 +1,35 @@ +const Discord = require('discord.js'); +const fs = require('fs'); +const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); +const gifFiles = fs.readdirSync('./gifs').filter(file => file.endsWith('.js')); +const debug = true; + +module.exports = { + getCommandFiles(client) { + client.commands = new Discord.Collection(); + for (const file of commandFiles) { + const command = require(`./commands/${file}`); + client.commands.set(command.name, command); + } + if (debug) console.log(client.commands); + }, + getGifFiles(client) { + client.gifs = new Discord.Collection(); + for (const file of gifFiles) { + const gif = require(`./gifs/${file}`); + client.gifs.set(gif.name, gif); + } + if (debug) console.log(client.gifs); + }, + extCheck(content) { + const lastFour = content.slice(-4); + switch (lastFour) { + case '.gif': + return 'gif'; + case '.jpg': + return 'jpg'; + default: + return false; + } + } +} \ No newline at end of file diff --git a/gifs/bobsaget.js b/gifs/bobsaget.js new file mode 100644 index 0000000..0866e6b --- /dev/null +++ b/gifs/bobsaget.js @@ -0,0 +1,4 @@ +module.exports = { + name: 'bobsaget', + embed_url: 'https://tenor.com/view/bob-saget-tourettes-mad-angry-gif-8840899' +} \ No newline at end of file diff --git a/gifs/cumb.js b/gifs/cumb.js new file mode 100644 index 0000000..d11fbe3 --- /dev/null +++ b/gifs/cumb.js @@ -0,0 +1,4 @@ +module.exports = { + name: 'cumb', + embed_url: 'https://tenor.com/view/sperm-gif-gif-13292476' +} \ No newline at end of file diff --git a/gifs/deeznuts.gif b/gifs/deeznuts.js similarity index 100% rename from gifs/deeznuts.gif rename to gifs/deeznuts.js diff --git a/gifs/shid.js b/gifs/shid.js new file mode 100644 index 0000000..f9ec0a2 --- /dev/null +++ b/gifs/shid.js @@ -0,0 +1,4 @@ +module.exports = { + name: 'shid', + embed_url: 'https://tenor.com/view/sheet-gif-19721309' +} \ No newline at end of file diff --git a/index.js b/index.js index 722b142..2301862 100644 --- a/index.js +++ b/index.js @@ -1,59 +1,30 @@ /* eslint-disable brace-style */ // Variable Assignment -const fs = require('fs'); const dotenv = require('dotenv'); 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 } = 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); +const functions = require('./functions.js'); -function getCommandFiles() { - for (const file of commandFiles) { - const command = require(`./commands/${file}`); - client.commands.set(command.name, command); - } - 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) { - case '.gif': - return 'gif'; - case '.jpg': - return 'jpg'; - default: - return false; - } -} client.once('ready', () => { console.log('Ready'); client.user.setActivity('Nod Simulator 2021', { type: 'PLAYING' }).then().catch(console.error); - getCommandFiles(); - getGifFiles(); + functions.getCommandFiles(client); + functions.getGifFiles(client); }); client.login(process.env.TOKEN); client.on('message', message => { - const ext = extCheck(message.content); + const ext = functions.extCheck(message.content); if (debug) console.log(ext); if ((!message.content.startsWith(prefix) && ext == false) || message.author.bot) return;