From e457363079dc54cd993a7cde741533edab0bbab9 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 28 Mar 2021 16:34:00 -0400 Subject: [PATCH] Check animalese string length --- commands/voice/animalese.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/commands/voice/animalese.js b/commands/voice/animalese.js index 0d287315..fee535f1 100644 --- a/commands/voice/animalese.js +++ b/commands/voice/animalese.js @@ -51,7 +51,11 @@ module.exports = class AnimaleseCommand extends Command { { key: 'text', prompt: 'What text should be said?', - type: 'string' + type: 'string', + validate: text => { + if (!this.processScript(text)) return 'This text has no audible characters.'; + return true; + } } ] }); @@ -76,7 +80,7 @@ module.exports = class AnimaleseCommand extends Command { } animalese(script, pitch) { - const processedScript = script.replace(/[^a-z]/gi, ' ').split(' ').map(this.shortenWord).join(''); + const processedScript = this.processScript(script); const data = []; const sampleFreq = 44100; const libraryLetterSecs = 0.15; @@ -108,4 +112,8 @@ module.exports = class AnimaleseCommand extends Command { } return str; } + + processScript(str) { + return str.replace(/[^a-z]/gi, ' ').split(' ').map(this.shortenWord).join(''); + } };