Add reload function and upload potphrases

This commit is contained in:
= 2021-07-24 15:44:58 -04:00
parent 8ef34b0cdf
commit 24537c2d12
3 changed files with 32 additions and 15 deletions

10
commands/reload.js Normal file
View File

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

View File

@ -1,5 +1,3 @@
const fs = require('fs');
const strings = require('../src/strings.json');
const functions = require('../functions.js'); const functions = require('../functions.js');
module.exports = { module.exports = {
@ -7,11 +5,7 @@ module.exports = {
description: 'Add a phrase to the .joint command', description: 'Add a phrase to the .joint command',
usage: '<phrase to save>', usage: '<phrase to save>',
execute(message, file) { execute(message, file) {
strings.weed.push(functions.cleanInput(file.name)); functions.uploadPotPhrase(file.name);
fs.writeFile('./src/strings.json', JSON.stringify(strings), err => { message.channel.send('"' + file.name + '" has been added to the list');
if (err) throw err;
message.channel.send('"' + file.name + '" has been added to the list');
})
} }
} }

View File

@ -20,15 +20,16 @@ module.exports = {
} }
}, },
getCommandFiles(client) { getCommandFiles(client) {
client.commands = new Discord.Collection(); if (!client.commands) client.commands = new Discord.Collection();
client.commands.clear();
for (const file of commandFiles) { for (const file of commandFiles) {
const command = require(`./commands/${file}`); const command = require(`./commands/${file}`);
client.commands.set(command.name, command); client.commands.set(command.name, command);
} }
}, },
getGifFiles(client) { 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"; const query = "SELECT name, embed_url FROM gifs";
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.query(query) db.query(query)
@ -46,8 +47,8 @@ module.exports = {
}); });
}, },
getPotPhrases(client) { 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"; const query = "SELECT id, content FROM potphrases";
db.query(query) db.query(query)
.then(res => { .then(res => {
@ -62,8 +63,8 @@ module.exports = {
.catch(err => console.error(err)); .catch(err => console.error(err));
}, },
getPastaFiles(client) { 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"; const query = "SELECT name, content FROM pastas";
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.query(query) 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) { getFileInfo(content) {
// Split the message content at the final instance of a period // Split the message content at the final instance of a period
const finalPeriod = content.lastIndexOf('.'); const finalPeriod = content.lastIndexOf('.');
@ -240,5 +247,11 @@ module.exports = {
db.query(query) db.query(query)
.then() .then()
.catch(e => console.error(e)); .catch(e => console.error(e));
},
uploadPotPhrase(content) {
const query = `INSERT INTO potphrases (content) VALUES ('${content}')`;
db.query(query)
.then()
.catch(e => console.error(e));
} }
} }