Compare commits
No commits in common. "53dda834f9c04aa19b2f3e2bf316ddf428793d69" and "8f16112b2ed885d6f346fadd59a419d84edbb34e" have entirely different histories.
53dda834f9
...
8f16112b2e
|
@ -1,35 +1,19 @@
|
|||
function expand(words, text) {
|
||||
|
||||
const letters = text.trim().toLowerCase().split("");
|
||||
// Build a dictionary with lowercase letters as keys
|
||||
const dict = {};
|
||||
words.forEach(word => {
|
||||
|
||||
if (word == "")
|
||||
return;
|
||||
const initial = word.split("")[0].toLowerCase();
|
||||
if (initial in dict)
|
||||
dict[initial].push(word);
|
||||
else
|
||||
dict[initial] = [word];
|
||||
|
||||
});
|
||||
return letters.map((letter) => {
|
||||
|
||||
if (!(letter.toLowerCase() in dict))
|
||||
return letter;
|
||||
const wordsWithLetter = dict[letter.toLowerCase()];
|
||||
const wordsWithLetter = words.filter(i => i.match(RegExp(`^${letter}`, "i")));
|
||||
const word = wordsWithLetter[Math.floor(Math.random() * wordsWithLetter.length)];
|
||||
return word;
|
||||
|
||||
}).reduce((acc, cur) => acc + " " + cur).replace(/\s{2,}/g, " ");
|
||||
}).reduce((acc, cur) => acc + " " + cur);
|
||||
|
||||
}
|
||||
|
||||
|
||||
module.exports = (words = []) => (ctx) => {
|
||||
|
||||
words = words.filter(i => ! i.match(/'s$/));
|
||||
const message = ctx.message.text.replace(/^[^ ]+/, "");
|
||||
if (message) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue