New handling of valid extensions and new gif and pasta lists

This commit is contained in:
= 2021-07-19 14:54:08 -04:00
parent 5236462efe
commit 04344c3fdd
7 changed files with 62 additions and 28 deletions

View File

@ -1,6 +1,8 @@
# Release Notes # Release Notes
## v2.1.0 ## 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! 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. 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.

12
commands/gifs.js Normal file
View File

@ -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.'));
}
}

View File

@ -1,9 +0,0 @@
const functions = require('../functions.js');
module.exports = {
name: 'mapcommands',
description: '',
execute(message, file) {
console.log(functions.mapCommands(message));
}
}

12
commands/pastas.js Normal file
View File

@ -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.'));
}
}

View File

@ -4,25 +4,7 @@
"logChannel": "859249300894908447", "logChannel": "859249300894908447",
"bootMessage": "NodBot v2 Starting Up", "bootMessage": "NodBot v2 Starting Up",
"shutdownMessage": "NodBot v2 Shutting Down", "shutdownMessage": "NodBot v2 Shutting Down",
"validExtensions": [ "validExtensions": [],
"gif",
"pasta",
"help",
"spongebob",
"savepasta",
"request",
"savegif",
"truth",
"joint",
"ping",
"strain",
"airport",
"weather",
"oldgif",
"newgif",
"newpng",
"mapcommands"
],
"emoji": { "emoji": {
"joint": "<:joint:862082955902976000>", "joint": "<:joint:862082955902976000>",
"next": "⏭️", "next": "⏭️",

View File

@ -3,8 +3,14 @@ const fs = require('fs');
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
const gifFiles = fs.readdirSync('./gifs').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 pastaFiles = fs.readdirSync('./pastas').filter(file => file.endsWith('.js'));
const config = require('./config.json');
module.exports = { module.exports = {
setValidExtensions(client) {
for (const entry of client.commands.map(command => command.name)) {
config.validExtensions.push(entry);
}
},
getCommandFiles(client) { getCommandFiles(client) {
client.commands = new Discord.Collection(); client.commands = new Discord.Collection();
for (const file of commandFiles) { 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.') .setDescription('All commands are provided as "file extensions" instead of prefixes to the message.')
.addFields(fields) .addFields(fields)
.setTimestamp(); .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}`);
} }
} }

View File

@ -18,6 +18,7 @@ client.once('ready', () => {
functions.getCommandFiles(client); functions.getCommandFiles(client);
functions.getGifFiles(client); functions.getGifFiles(client);
functions.getPastaFiles(client); functions.getPastaFiles(client);
functions.setValidExtensions(client);
// Get the owner and DM them a message that the bot is ready, useful for remote deployment // 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 => { client.users.fetch(process.env.ownerID).then(user => {
user.createDM().then(channel => { user.createDM().then(channel => {