From 275493b0f577ea41f13a17bb1972455ab7b13398 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 26 May 2020 01:09:55 +0000 Subject: [PATCH] it works --- package.json | 2 +- quotes.json | 6 ++++++ src/index.js | 37 ++++++++++++++++++++++--------------- 3 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 quotes.json diff --git a/package.json b/package.json index eb89aac..59c5c51 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "devDependencies": {}, "scripts": { "test": "node ./src/index --TEST", - "start": "npm install; node ./src/index.js" + "start": "node ./src/index.js" }, "repository": { "type": "git", diff --git a/quotes.json b/quotes.json new file mode 100644 index 0000000..1478093 --- /dev/null +++ b/quotes.json @@ -0,0 +1,6 @@ +{ + "quotes": [ + "you can add quotes by running ?quote add Quote goes here", + "tech,is,bad,at,sneezing" + ] +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index ae23acf..e539648 100755 --- a/src/index.js +++ b/src/index.js @@ -142,24 +142,31 @@ client.on("message", async message => { }; //////////////////////////////////////////////////////////////////////////////// if(command === "quote") { - let quotes = require(`${homedir}/quotes.json`); + let quotes = require(`../quotes.json`); var quoteadd = ""; + var selector; try{ - let selector = args[0].toLowerCase(); - if(selector === "add") { - args.shift(); - quoteadd = args; - quotes.quotes.push(quoteadd.tostring()); - fs.writeFile(`${homedir}/quotes.json`, JSON.stringify(quotes), (err) => { - if (err) return message.reply("Something went wrong"); - client.channels.cache.get('712084662033580064').send(`${message.member} has submitted ${quoteadd} to the quote repository`); - return message.reply("Quote added to repository"); + selector = args[0].toLowerCase(); + } catch (err) { + var number = quotes.quotes.length + 1; + let quotesend = Math.floor(Math.random() * (number - 0) + 0); + return message.channel.send(`${quotes.quotes[quotesend]}`); + }; + if(selector === "add") { + args.shift(); + quoteadd = args; + quoteadd = quoteadd.toString(); + quoteadd = quoteadd.replace(/,/g, " "); + quoteadd = quoteadd.replace(/ /g, ", "); quotes.quotes.push(quoteadd.toString()); + fs.writeFile(`../quotes.json`, JSON.stringify(quotes), (err) => { + if (err) return message.reply("Something went wrong");`` + client.channels.cache.get('712084662033580064').send(`${message.member} has submitted \`${quoteadd}\` to the quote repository`); + return message.reply("Quote added to repository"); }); - }; - } catch (err) {}; - var number = quotes.quotes.length + 1; - let quotesend = Math.floor(Math.random() * (number - 0) + 0); - return message.channel.send(`${quotes.quotes[quotesend]}`); + } + else { + return message.reply("you can add quotes by running `?quote add Quote goes here`"); + }; }; //////////////////////////////////////////////////////////////////////////////// if (command === "version") {