From f4ad45f8dcea20a8b673f739c78d49b0c0956792 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Fri, 22 May 2020 00:54:27 -0400 Subject: [PATCH] Lorem Ipsum Command --- .gitignore | 2 - README.md | 3 +- assets/json/lorem-ipsum.json | 64 ++++++++++++++++++++++++ commands/random-res/lorem-ipsum.js | 78 ++++++++++++++++++++++++++++++ package.json | 2 +- 5 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 assets/json/lorem-ipsum.json create mode 100644 commands/random-res/lorem-ipsum.js diff --git a/.gitignore b/.gitignore index 8b14c2d9..2047fa2f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,3 @@ report*.json config.json # In-Development Commands -assets/json/lorem-ipsum.json -commands/random-res/lorem-ipsum.js diff --git a/README.md b/README.md index 6cca8ede..bda7fa5e 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 429 +Total: 430 ### Utility: @@ -278,6 +278,7 @@ Total: 429 * **joke:** Responds with a random joke. * **kiss-marry-kill:** Determines who to kiss, who to marry, and who to kill. * **light-novel-title:** Responds with a randomly generated Light Novel title. +* **lorem-ipsum:** Generates a randomized Lorem Ipsum placeholder text. * **magic-conch:** Asks your question to the Magic Conch. * **name:** Responds with a random name, with the gender of your choice. * **number-fact:** Responds with a random fact about a specific number. diff --git a/assets/json/lorem-ipsum.json b/assets/json/lorem-ipsum.json new file mode 100644 index 00000000..e14657bb --- /dev/null +++ b/assets/json/lorem-ipsum.json @@ -0,0 +1,64 @@ +[ + "ad", + "adipisicing", + "aliqua", + "aliquip", + "amet", + "anim", + "aute", + "cillum", + "commodo", + "consectetur", + "consequat", + "culpa", + "cupidatat", + "deserunt", + "do", + "dolor", + "dolore", + "duis", + "ea", + "eiusmod", + "elit", + "enim", + "esse", + "est", + "et", + "eu", + "ex", + "excepteur", + "exercitation", + "fugiat", + "id", + "in", + "incididunt", + "ipsum", + "irure", + "labore", + "laboris", + "laborum", + "lorem", + "magna", + "minim", + "mollit", + "nisi", + "non", + "nostrud", + "nulla", + "occaecat", + "officia", + "pariatur", + "proident", + "qui", + "quis", + "reprehenderit", + "sint", + "sit", + "sunt", + "tempor", + "ullamco", + "ut", + "velit", + "veniam", + "voluptate" +] diff --git a/commands/random-res/lorem-ipsum.js b/commands/random-res/lorem-ipsum.js new file mode 100644 index 00000000..bbb1e06d --- /dev/null +++ b/commands/random-res/lorem-ipsum.js @@ -0,0 +1,78 @@ +const Command = require('../../structures/Command'); +const { firstUpperCase } = require('../../util/Util'); +const words = require('../../assets/json/lorem-ipsum'); +const firstSentence = ['Lorem', 'ipsum', 'dolor', 'sit', 'amet,', 'consectetur', 'adipiscing', 'elit']; + +module.exports = class LoremIpsumCommand extends Command { + constructor(client) { + super(client, { + name: 'lorem-ipsum', + aliases: ['lorem', 'ipsum'], + group: 'random-res', + memberName: 'lorem-ipsum', + description: 'Generates a randomized Lorem Ipsum placeholder text.', + args: [ + { + key: 'characters', + prompt: 'How many characters do you want the text to be?', + type: 'integer', + min: 6, + max: 2000 + } + ] + }); + } + + run(msg, { characters }) { + const result = []; + let resultLength = 0; + let firstSentenceIndex = 0; + let currentSentenceWords = 0; + let sentenceStart = true; + while (resultLength < characters) { + if (firstSentenceIndex === firstSentence.length) { + const filterWords = words.filter(word => characters > resultLength + word.length + 1); + if (!filterWords.length) { + result[result.length - 1] = '.'; + for (let i = 0; i < characters - resultLength; i++) { + const allowedI = []; + result.forEach((item, i) => { + if (result[i + 1] === '. ') return; + if (result[i] === ' ') return; + if (result[i] === '. ') return; + if (i === result.length - 1) return; + if (result[i].endsWith(',')) return; + allowedI.push(i); + }); + const chosenI = allowedI[Math.floor(Math.random() * allowedI.length)]; + const insertPoint = result[chosenI]; + result[chosenI] = `${insertPoint},`; + } + break; + } + const word = filterWords[Math.floor(Math.random() * filterWords.length)]; + result.push(sentenceStart ? firstUpperCase(word) : word); + resultLength += word.length; + currentSentenceWords++; + if (currentSentenceWords > 0) sentenceStart = false; + } else { + const word = firstSentence[firstSentenceIndex]; + result.push(word); + firstSentenceIndex++; + currentSentenceWords++; + resultLength += word.length; + if (firstSentenceIndex > 0) sentenceStart = false; + } + if (currentSentenceWords === 8 || characters - resultLength === 1) { + currentSentenceWords = 0; + sentenceStart = true; + result.push('. '); + resultLength += 2; + } else { + result.push(' '); + resultLength += 1; + } + } + return msg.say(result.join('')); + } +}; diff --git a/package.json b/package.json index f8cb2d01..26e158f2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "114.18.0", + "version": "114.19.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {