Ignore 's words in /expand. Return letter if nothing starting with it is found.

This commit is contained in:
Ceda EI 2020-04-23 20:10:37 +05:30
parent 8f16112b2e
commit 382579ba3f
1 changed files with 3 additions and 0 deletions

View File

@ -4,6 +4,8 @@ function expand(words, text) {
return letters.map((letter) => {
const wordsWithLetter = words.filter(i => i.match(RegExp(`^${letter}`, "i")));
if (! wordsWithLetter.length)
return letter;
const word = wordsWithLetter[Math.floor(Math.random() * wordsWithLetter.length)];
return word;
@ -14,6 +16,7 @@ function expand(words, text) {
module.exports = (words = []) => (ctx) => {
words = words.filter(i => ! i.match(/'s$/));
const message = ctx.message.text.replace(/^[^ ]+/, "");
if (message) {