|
@@ -0,0 +1,70 @@
|
|
|
+const db = require("../db.js");
|
|
|
+const util = require("../util.js");
|
|
|
+
|
|
|
+const quotePattern = /add quote by "([^"]+)"\s*(.*)/i;
|
|
|
+
|
|
|
+function minify(str, maxLength) {
|
|
|
+ let result = str.replace("\n", "");
|
|
|
+ if(result.length > maxLength)
|
|
|
+ result = `${result.substring(0, maxLength - 3)}...`;
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+const commands = {
|
|
|
+ "add quote": (msg, c) => {
|
|
|
+ if(!util.isAuthorised(msg.author))
|
|
|
+ return;
|
|
|
+
|
|
|
+ let result = quotePattern.exec(c);
|
|
|
+
|
|
|
+ if(result == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ let author = result[1].trim();
|
|
|
+ let message = result[2].trim();
|
|
|
+
|
|
|
+ db.get("quotes").push({
|
|
|
+ author: author,
|
|
|
+ message: message
|
|
|
+ }).write();
|
|
|
+
|
|
|
+ msg.channel.send(`${msg.author.toString()} Added quote #${db.get("quotes").size().value()}!`);
|
|
|
+ },
|
|
|
+ "random quote": (msg) => {
|
|
|
+ if(db.get("quotes").size().value() == 0){
|
|
|
+ msg.channel.send("I have no quotes!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let quote = db.get("quotes").randomElement().value();
|
|
|
+ let index = db.get("quotes").indexOf(quote).value();
|
|
|
+ msg.channel.send(`Quote #${index + 1}:\n*"${quote.message}"*\n- ${quote.author}`);
|
|
|
+ },
|
|
|
+ "remove quote": (msg, c) => {
|
|
|
+ let quoteNum = c.substring("remove quote".length).trim();
|
|
|
+ let val = parseInt(quoteNum);
|
|
|
+ if(isNaN(val) || db.get("quotes").size().value() < val - 1)
|
|
|
+ return;
|
|
|
+
|
|
|
+ db.get("quotes").pullAt(val - 1).write();
|
|
|
+ msg.channel.send(`${msg.author.toString()} Removed quote #${val}!`);
|
|
|
+ },
|
|
|
+ "list quotes": msg => {
|
|
|
+ if(!util.isAuthorised(msg.author)) {
|
|
|
+ msg.channel.send(`${msg.author.toString()} To prevent spamming, only bot moderators can view all quotes!`);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(db.get("quotes").size().value() == 0){
|
|
|
+ msg.channel.send("I have no quotes!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ let quotes = db.get("quotes").reduce((prev, curr, i) => `${prev}[${i+1}] "${minify(curr.message, 10)}" by ${curr.author}\n`, "").value();
|
|
|
+ msg.channel.send(`${msg.author.toString()}I know the following quotes:\n\`\`\`${quotes}\`\`\``);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+module.exports = {
|
|
|
+ commands: commands
|
|
|
+};
|