From 24537c2d120b3e388631240b5616e59fb6bf2c0e Mon Sep 17 00:00:00 2001 From: = Date: Sat, 24 Jul 2021 15:44:58 -0400 Subject: [PATCH] Add reload function and upload potphrases --- commands/reload.js | 10 ++++++++++ commands/roll.js | 10 ++-------- functions.js | 27 ++++++++++++++++++++------- 3 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 commands/reload.js diff --git a/commands/reload.js b/commands/reload.js new file mode 100644 index 0000000..97f4320 --- /dev/null +++ b/commands/reload.js @@ -0,0 +1,10 @@ +const fn = require('../functions'); + +module.exports = { + name: 'reload', + description: 'Reload saved GIFs, Pastas, Joint Phrases, etc', + execute(message, file) { + fn.reload(message.client); + message.reply('Reload Successful'); + } +} \ No newline at end of file diff --git a/commands/roll.js b/commands/roll.js index e48a32d..cd6a333 100644 --- a/commands/roll.js +++ b/commands/roll.js @@ -1,5 +1,3 @@ -const fs = require('fs'); -const strings = require('../src/strings.json'); const functions = require('../functions.js'); module.exports = { @@ -7,11 +5,7 @@ module.exports = { description: 'Add a phrase to the .joint command', usage: '', execute(message, file) { - strings.weed.push(functions.cleanInput(file.name)); - fs.writeFile('./src/strings.json', JSON.stringify(strings), err => { - if (err) throw err; - - message.channel.send('"' + file.name + '" has been added to the list'); - }) + functions.uploadPotPhrase(file.name); + message.channel.send('"' + file.name + '" has been added to the list'); } } \ No newline at end of file diff --git a/functions.js b/functions.js index 1133584..d6dd1c5 100644 --- a/functions.js +++ b/functions.js @@ -20,15 +20,16 @@ module.exports = { } }, getCommandFiles(client) { - client.commands = new Discord.Collection(); + if (!client.commands) client.commands = new Discord.Collection(); + client.commands.clear(); for (const file of commandFiles) { const command = require(`./commands/${file}`); client.commands.set(command.name, command); } }, getGifFiles(client) { - client.gifs = new Discord.Collection(); - + if (!client.gifs) client.gifs = new Discord.Collection(); + client.gifs.clear(); const query = "SELECT name, embed_url FROM gifs"; return new Promise((resolve, reject) => { db.query(query) @@ -46,8 +47,8 @@ module.exports = { }); }, getPotPhrases(client) { - client.potphrases = new Discord.Collection(); - + if (!client.potphrases) client.potphrases = new Discord.Collection(); + client.potphrases.clear(); const query = "SELECT id, content FROM potphrases"; db.query(query) .then(res => { @@ -62,8 +63,8 @@ module.exports = { .catch(err => console.error(err)); }, getPastaFiles(client) { - client.pastas = new Discord.Collection(); - + if (!client.pastas) client.pastas = new Discord.Collection(); + client.pastas.clear(); const query = "SELECT name, content FROM pastas"; return new Promise((resolve, reject) => { db.query(query) @@ -81,6 +82,12 @@ module.exports = { }); }, + reload(client) { + this.getCommandFiles(client); + this.getGifFiles(client); + this.getPastaFiles(client); + this.getPotPhrases(client); + }, getFileInfo(content) { // Split the message content at the final instance of a period const finalPeriod = content.lastIndexOf('.'); @@ -240,5 +247,11 @@ module.exports = { db.query(query) .then() .catch(e => console.error(e)); + }, + uploadPotPhrase(content) { + const query = `INSERT INTO potphrases (content) VALUES ('${content}')`; + db.query(query) + .then() + .catch(e => console.error(e)); } } \ No newline at end of file