From 8ef34b0cdf64de1cf31cedae0f3359e1e3626928 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 21 Jul 2021 22:40:36 -0400 Subject: [PATCH] Migrating to Postgres --- functions.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/functions.js b/functions.js index 317345d..1133584 100644 --- a/functions.js +++ b/functions.js @@ -108,22 +108,24 @@ module.exports = { .setFooter(`@${author.username}#${author.discriminator}`); }, saveGif(message, name, embed_url) { - fs.writeFile(`./gifs/${name}.js`, `module.exports = {\n\tname: '${name}',\n\tembed_url: '${embed_url}'\n}`, function(err) { - if (err) throw err; - console.log('Saved file!'); - const gif = require(`./gifs/${name}.js`); - message.client.gifs.set(gif.name, gif); - }); + const gif = { + name: name, + embed_url: embed_url + }; + message.client.gifs.set(gif.name, gif); + this.uploadGIF(name, embed_url); }, savePasta(message, name, content) { - fs.writeFile(`./pastas/${name}.js`, `module.exports = {\n\tname: '${name}',\n\tcontent: '${content}'\n}`, function(err) { - if (err) { - return `There was a problem saving the copypasta.`; - } - const pasta = require(`./pastas/${name}.js`); - message.client.pastas.set(pasta.name, pasta); - }); - return `Copypasta saved successfully as ${name}.pasta`; + const pasta = { + name: name, + content: content + }; + message.client.pastas.set(pasta.name, pasta); + + const query = `INSERT INTO pastas (name, content) VALUES ('${name}','${content}')`; + db.query(query); + + return "Success"; }, createAirportEmbed(data, author, command) { const airport = data.airport[0]; @@ -234,7 +236,7 @@ module.exports = { .setFooter(`@${message.author.username}#${message.author.discriminator}`); }, uploadGIF(name, embed_url) { - const query = `INSERT INTO gifs (name, embed_url) VALUES ('${name}','${embed_url})'`; + const query = `INSERT INTO gifs (name, embed_url) VALUES ('${name}','${embed_url}')`; db.query(query) .then() .catch(e => console.error(e));