From ae6627488acd30c61ed6a3029a105b820a43731b Mon Sep 17 00:00:00 2001 From: = Date: Sun, 27 Jun 2021 22:19:16 -0400 Subject: [PATCH] Adding ability to save new gifs to the hardcode list --- commands/reload-gifs.js | 3 ++- commands/save-gif.js | 16 ++++++++++++++++ gifs/deeznuts.gif | 4 ++++ gifs/template | 4 +--- index.js | 1 + 5 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 commands/save-gif.js create mode 100644 gifs/deeznuts.gif diff --git a/commands/reload-gifs.js b/commands/reload-gifs.js index ce63611..70be76a 100644 --- a/commands/reload-gifs.js +++ b/commands/reload-gifs.js @@ -2,6 +2,7 @@ module.exports = { name: "reload-gifs", description: "Refresh the hardcoded gif library.", execute(message, args) { - getGifFiles(); + const index = require('../index.js'); + index.getGifFiles(); } } \ No newline at end of file diff --git a/commands/save-gif.js b/commands/save-gif.js new file mode 100644 index 0000000..c036341 --- /dev/null +++ b/commands/save-gif.js @@ -0,0 +1,16 @@ +module.exports = { + name: 'save-gif', + description: 'Adds a given gif to the hardcoded list.', + execute(message, args) { + if (args.length != 2) { + message.reply('This command requires exactly two arguments, gif name and url. Please try again.'); + return; + } + + const fs = require('fs'); + fs.appendFile(`./gifs/${args[0]}.gif`, `module.exports = {\n\tname: '${args[0]}',\n\tembed_url: '${args[1]}'\n}`, function(err) { + if (err) throw err; + console.log('Saved file!'); + }); + } +} \ No newline at end of file diff --git a/gifs/deeznuts.gif b/gifs/deeznuts.gif new file mode 100644 index 0000000..c894853 --- /dev/null +++ b/gifs/deeznuts.gif @@ -0,0 +1,4 @@ +module.exports = { + name: 'deeznuts', + embed_url: 'https://giphy.com/embed/z0XEX0BeuPGmY' +} \ No newline at end of file diff --git a/gifs/template b/gifs/template index 1df103a..e767e5d 100644 --- a/gifs/template +++ b/gifs/template @@ -1,3 +1 @@ -module.exports = { - -} \ No newline at end of file +module.exports = {\n\tname: '${args[0]}',\n\tembed_url: '${args[1]}'\n} \ No newline at end of file diff --git a/index.js b/index.js index c977f2e..722b142 100644 --- a/index.js +++ b/index.js @@ -61,6 +61,7 @@ client.on('message', message => { const args = message.content.slice(prefix.length).trim().split(/ +/); const command = args.shift().toLowerCase(); + if (debug) console.log(args); if (!client.commands.has(command)) return; try {