From 04344c3fdd45bf997503ac6be6dae145f1e575c2 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 19 Jul 2021 14:54:08 -0400 Subject: [PATCH] New handling of valid extensions and new gif and pasta lists --- ReleaseNotes.md | 2 ++ commands/gifs.js | 12 ++++++++++++ commands/mapcommands.js | 9 --------- commands/pastas.js | 12 ++++++++++++ config.json | 20 +------------------- functions.js | 34 ++++++++++++++++++++++++++++++++++ index.js | 1 + 7 files changed, 62 insertions(+), 28 deletions(-) create mode 100644 commands/gifs.js delete mode 100644 commands/mapcommands.js create mode 100644 commands/pastas.js diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 5559400..15f4470 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,6 +1,8 @@ # Release Notes ## v2.1.0 +Wondering what GIFs and Copypastas have been saved? Try `.gifs` and `.pastas`, also check out the new help message with `.help`! + NodBot now uses Tenor instead of Giphy for GIF searches! Changing the method to search for and save GIFs for later reuse. Previously the bot simply sent a message containing the link to a GIF which Discord would display in the chat. However the new code uses Embeds to make the messages look prettier. These Embeds require a *direct* link to the GIF, which isn't very user friendly. Now you can search for a GIF and NodBot will DM you with results for you to browse before choosing the GIF you'd like to save, then name it. diff --git a/commands/gifs.js b/commands/gifs.js new file mode 100644 index 0000000..3bef0ac --- /dev/null +++ b/commands/gifs.js @@ -0,0 +1,12 @@ +const functions = require('../functions.js'); + +module.exports = { + name: 'gifs', + description: 'Get a list of saved GIFs', + execute(message, file) { + message.author.createDM().then(channel => { + channel.send(functions.createGIFList(message)); + message.reply('I\'ve sent you a DM with a list of saved GIFs.') + }).catch(err => message.channel.send('Sorry I was unable to send you a DM.')); + } +} \ No newline at end of file diff --git a/commands/mapcommands.js b/commands/mapcommands.js deleted file mode 100644 index f9a0278..0000000 --- a/commands/mapcommands.js +++ /dev/null @@ -1,9 +0,0 @@ -const functions = require('../functions.js'); - -module.exports = { - name: 'mapcommands', - description: '', - execute(message, file) { - console.log(functions.mapCommands(message)); - } -} \ No newline at end of file diff --git a/commands/pastas.js b/commands/pastas.js new file mode 100644 index 0000000..c7fbe05 --- /dev/null +++ b/commands/pastas.js @@ -0,0 +1,12 @@ +const functions = require('../functions.js'); + +module.exports = { + name: 'pastas', + description: 'Get a list of saved copypastas', + execute(message, file) { + message.author.createDM().then(channel => { + channel.send(functions.createPastaList(message)); + message.channel.send('I\'ve sent you a DM with a list of saved copypastas.') + }).catch(err => message.channel.send('Sorry I was unable to send you a DM.')); + } +} \ No newline at end of file diff --git a/config.json b/config.json index dc049cf..5715eb5 100644 --- a/config.json +++ b/config.json @@ -4,25 +4,7 @@ "logChannel": "859249300894908447", "bootMessage": "NodBot v2 Starting Up", "shutdownMessage": "NodBot v2 Shutting Down", - "validExtensions": [ - "gif", - "pasta", - "help", - "spongebob", - "savepasta", - "request", - "savegif", - "truth", - "joint", - "ping", - "strain", - "airport", - "weather", - "oldgif", - "newgif", - "newpng", - "mapcommands" - ], + "validExtensions": [], "emoji": { "joint": "<:joint:862082955902976000>", "next": "⏭️", diff --git a/functions.js b/functions.js index 7e380e8..75c4bc6 100644 --- a/functions.js +++ b/functions.js @@ -3,8 +3,14 @@ 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 pastaFiles = fs.readdirSync('./pastas').filter(file => file.endsWith('.js')); +const config = require('./config.json'); module.exports = { + setValidExtensions(client) { + for (const entry of client.commands.map(command => command.name)) { + config.validExtensions.push(entry); + } + }, getCommandFiles(client) { client.commands = new Discord.Collection(); for (const file of commandFiles) { @@ -149,5 +155,33 @@ module.exports = { .setDescription('All commands are provided as "file extensions" instead of prefixes to the message.') .addFields(fields) .setTimestamp(); + }, + createGIFList(message) { + let list = []; + const { gifs } = message.client; + for (const entry of gifs.map(gif => [gif.name])) { + list.push(entry[0] + '.gif'); + } + + return new Discord.MessageEmbed() + .setAuthor('NodBot GIF List') + .setTitle('List of Currently Saved GIFs') + .setDescription(list.join('\n')) + .setTimestamp() + .setFooter(`@${message.author.username}#${message.author.discriminator}`); + }, + createPastaList(message) { + let list = []; + const { pastas } = message.client; + for (const entry of pastas.map(pasta => [pasta.name])) { + list.push(entry[0] + '.pasta'); + } + + return new Discord.MessageEmbed() + .setAuthor('NodBot Pasta List') + .setTitle('List of Currently Saved Copypastas') + .setDescription(list.join('\n')) + .setTimestamp() + .setFooter(`@${message.author.username}#${message.author.discriminator}`); } } \ No newline at end of file diff --git a/index.js b/index.js index b50c88c..0c2a2d1 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,7 @@ client.once('ready', () => { functions.getCommandFiles(client); functions.getGifFiles(client); functions.getPastaFiles(client); + functions.setValidExtensions(client); // Get the owner and DM them a message that the bot is ready, useful for remote deployment client.users.fetch(process.env.ownerID).then(user => { user.createDM().then(channel => {