From 92876125cacca84aaa7413446fcc0f60e9e1c1fb Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Wed, 10 Mar 2021 20:37:08 -0500 Subject: [PATCH] More intuitive story picker --- commands/other/kino.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/commands/other/kino.js b/commands/other/kino.js index 8aeafe43..081231bb 100644 --- a/commands/other/kino.js +++ b/commands/other/kino.js @@ -26,10 +26,25 @@ module.exports = class KinoCommand extends Command { args: [ { key: 'story', - prompt: `What story do you want to read? Either ${list(stories, 'or')}.`, + prompt: stripIndents` + What story do you want to read? You can type the number or the name. + \`\`\` + ${stories.map((story, i) => `${i.toString().padStart(2, '0')}. ${story}`).join('\n')} + \`\`\` + `, type: 'string', - oneOf: stories.map(story => story.toLowerCase()), - parse: story => story.toLowerCase() + validate: story => { + if (stories.some(story => story.toLowerCase() === story.toLowerCase())) return true; + const num = Number.parseInt(story, 10); + return Boolean(stories[num]); + }, + parse: story => { + if (stories.some(story => story.toLowerCase() === story.toLowerCase())) { + return story.toLowerCase(); + } + const num = Number.parseInt(story, 10); + return stories[num]; + } } ] });