From 8aa5cc90a19724d2d0c72e617ac5f52d83bc9ec7 Mon Sep 17 00:00:00 2001 From: Maiko Sinkyaet Tan Date: Fri, 1 Nov 2024 10:27:25 +0800 Subject: [PATCH] feat: add count option to tarot command for multiple card draws (#5) --- src/index.ts | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index c3332b0..c33378e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,18 +8,26 @@ export function apply(ctx: Context) { .command('tarot') .alias('塔罗') .alias('塔罗牌') + .option('count', '-n ') .option('minimal', '-m') .action(async ({ options }) => { - let result = await getTarot(ctx) - let img = result.match(/(?<=(±img=)).+(?=±)/g)[0] + let ret: h = [] - if (options.minimal) { - return h('img', { src: img }) - } + for (let i = 0; i < options.count || 1; i++) { + let result = await getTarot(ctx) + let img = result.match(/(?<=(±img=)).+(?=±)/g)[0] + + if (options.minimal) { + ret.push(h('img', { src: img })) + continue + } - let text1 = result.match(/.+(?=(±i))/g)[0].replace(/(\\r)/, '\n') - let text2 = result.match(/(?<=(g±)).+/g)[0].replace(/(\\r)/, ' ') - return h('message', h('img', { src: img }), text1, text2) + let text1 = result.match(/.+(?=(±i))/g)[0].replace(/(\\r)/, '\n') + let text2 = result.match(/(?<=(g±)).+/g)[0].replace(/(\\r)/, ' ') + ret.push(h('img', { src: img }), text1, text2) + } + + return h('message', ret) }) ctx.i18n.define('zh-CN', { @@ -27,6 +35,7 @@ export function apply(ctx: Context) { description: '抽取一张塔罗牌', options: { minimal: '仅输出图片', + count: '抽取张数', }, }, }) @@ -35,6 +44,7 @@ export function apply(ctx: Context) { description: 'Draw a tarot card (Chinese only)', options: { minimal: 'show image only', + count: 'number of cards', }, }, })