From 382579ba3fef2059b549f89f393a6fe8838c775c Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Thu, 23 Apr 2020 20:10:37 +0530 Subject: [PATCH] Ignore 's words in /expand. Return letter if nothing starting with it is found. --- commands/expand.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/commands/expand.js b/commands/expand.js index 80135a7..a9592c6 100644 --- a/commands/expand.js +++ b/commands/expand.js @@ -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) {