Skip to content

Commit

Permalink
feat: add count option to tarot command for multiple card draws (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaikoTan authored Nov 1, 2024
1 parent b41da05 commit 8aa5cc9
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,34 @@ export function apply(ctx: Context) {
.command('tarot')
.alias('塔罗')
.alias('塔罗牌')
.option('count', '-n <count:posint>')
.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', {
'commands.tarot': {
description: '抽取一张塔罗牌',
options: {
minimal: '仅输出图片',
count: '抽取张数',
},
},
})
Expand All @@ -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',
},
},
})
Expand Down

0 comments on commit 8aa5cc9

Please sign in to comment.