|
@@ -1,23 +1,42 @@
|
|
const db = require("../db.js");
|
|
const db = require("../db.js");
|
|
const util = require("../util.js");
|
|
const util = require("../util.js");
|
|
|
|
|
|
|
|
+const documentation = {
|
|
|
|
+ "add quote by \"<author>\" <NEWLINE> <quote>": {
|
|
|
|
+ auth: true,
|
|
|
|
+ description: "Adds a quote"
|
|
|
|
+ },
|
|
|
|
+ "remove quote <quote_index>": {
|
|
|
|
+ auth: true,
|
|
|
|
+ description: "Removes quote. Use \"list quotes\" to get the <quote_index>!"
|
|
|
|
+ },
|
|
|
|
+ "quotes": {
|
|
|
|
+ auth: true,
|
|
|
|
+ description: "Lists all known quotes."
|
|
|
|
+ },
|
|
|
|
+ "random quote": {
|
|
|
|
+ auth: false,
|
|
|
|
+ description: "Shows a random quote by someone special..."
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+
|
|
const quotePattern = /add quote by "([^"]+)"\s*(.*)/i;
|
|
const quotePattern = /add quote by "([^"]+)"\s*(.*)/i;
|
|
|
|
|
|
function minify(str, maxLength) {
|
|
function minify(str, maxLength) {
|
|
let result = str.replace("\n", "");
|
|
let result = str.replace("\n", "");
|
|
- if(result.length > maxLength)
|
|
|
|
|
|
+ if (result.length > maxLength)
|
|
result = `${result.substring(0, maxLength - 3)}...`;
|
|
result = `${result.substring(0, maxLength - 3)}...`;
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
const commands = {
|
|
const commands = {
|
|
"add quote": (msg, c) => {
|
|
"add quote": (msg, c) => {
|
|
- if(!util.isAuthorised(msg.author))
|
|
|
|
|
|
+ if (!util.isAuthorised(msg.author))
|
|
return;
|
|
return;
|
|
|
|
|
|
let result = quotePattern.exec(c);
|
|
let result = quotePattern.exec(c);
|
|
-
|
|
|
|
- if(result == null)
|
|
|
|
|
|
+
|
|
|
|
+ if (result == null)
|
|
return;
|
|
return;
|
|
|
|
|
|
let author = result[1].trim();
|
|
let author = result[1].trim();
|
|
@@ -31,7 +50,7 @@ const commands = {
|
|
msg.channel.send(`${msg.author.toString()} Added quote #${db.get("quotes").size().value()}!`);
|
|
msg.channel.send(`${msg.author.toString()} Added quote #${db.get("quotes").size().value()}!`);
|
|
},
|
|
},
|
|
"random quote": (msg) => {
|
|
"random quote": (msg) => {
|
|
- if(db.get("quotes").size().value() == 0){
|
|
|
|
|
|
+ if (db.get("quotes").size().value() == 0) {
|
|
msg.channel.send("I have no quotes!");
|
|
msg.channel.send("I have no quotes!");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -42,29 +61,30 @@ const commands = {
|
|
"remove quote": (msg, c) => {
|
|
"remove quote": (msg, c) => {
|
|
let quoteNum = c.substring("remove quote".length).trim();
|
|
let quoteNum = c.substring("remove quote".length).trim();
|
|
let val = parseInt(quoteNum);
|
|
let val = parseInt(quoteNum);
|
|
- if(isNaN(val) || db.get("quotes").size().value() < val - 1)
|
|
|
|
|
|
+ if (isNaN(val) || db.get("quotes").size().value() < val - 1)
|
|
return;
|
|
return;
|
|
|
|
|
|
db.get("quotes").pullAt(val - 1).write();
|
|
db.get("quotes").pullAt(val - 1).write();
|
|
msg.channel.send(`${msg.author.toString()} Removed quote #${val}!`);
|
|
msg.channel.send(`${msg.author.toString()} Removed quote #${val}!`);
|
|
},
|
|
},
|
|
- "list quotes": msg => {
|
|
|
|
- if(!util.isAuthorised(msg.author)) {
|
|
|
|
|
|
+ "quotes": msg => {
|
|
|
|
+ if (!util.isAuthorised(msg.author)) {
|
|
msg.channel.send(`${msg.author.toString()} To prevent spamming, only bot moderators can view all quotes!`);
|
|
msg.channel.send(`${msg.author.toString()} To prevent spamming, only bot moderators can view all quotes!`);
|
|
- return;
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
- if(db.get("quotes").size().value() == 0){
|
|
|
|
|
|
+ if (db.get("quotes").size().value() == 0) {
|
|
msg.channel.send("I have no quotes!");
|
|
msg.channel.send("I have no quotes!");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- let quotes = db.get("quotes").reduce((prev, curr, i) => `${prev}[${i+1}] "${minify(curr.message, 10)}" by ${curr.author}\n`, "").value();
|
|
|
|
|
|
+ let quotes = db.get("quotes").reduce((prev, curr, i) => `${prev}[${i+1}] "${minify(curr.message, 10)}" by ${curr.author}\n`, "\n").value();
|
|
msg.channel.send(`${msg.author.toString()}I know the following quotes:\n\`\`\`${quotes}\`\`\``);
|
|
msg.channel.send(`${msg.author.toString()}I know the following quotes:\n\`\`\`${quotes}\`\`\``);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
module.exports = {
|
|
- commands: commands
|
|
|
|
|
|
+ commands: commands,
|
|
|
|
+ documentation: documentation
|
|
};
|
|
};
|