Commit b1bf76f8 authored by nanahira's avatar nanahira

rework command use

parent 2e0cb0b4
Pipeline #11162 passed with stage
in 43 seconds
...@@ -181,7 +181,7 @@ export default class PicsContainer ...@@ -181,7 +181,7 @@ export default class PicsContainer
description: '获取随机图片', description: '获取随机图片',
options: { options: {
source: `指定图源,逗号分隔。图源可以用 ${this.config.commandName}.sources 查询。`, source: `指定图源,逗号分隔。图源可以用 ${this.config.commandName}.sources 查询。`,
tag: '需要查询的图片标签,逗号分隔。', // tag: '需要查询的图片标签,逗号分隔。',
}, },
messages: { messages: {
'not-found': '未找到任何图片。', 'not-found': '未找到任何图片。',
...@@ -191,7 +191,7 @@ export default class PicsContainer ...@@ -191,7 +191,7 @@ export default class PicsContainer
description: 'Get random picture', description: 'Get random picture',
options: { options: {
source: `Specify picture source. Sources can be queried by command ${this.config.commandName}.sources`, source: `Specify picture source. Sources can be queried by command ${this.config.commandName}.sources`,
tag: 'Tags to search for, separated by comma.', // tag: 'Tags to search for, separated by comma.',
}, },
messages: { messages: {
'not-found': 'No pictures found.', 'not-found': 'No pictures found.',
...@@ -200,7 +200,7 @@ export default class PicsContainer ...@@ -200,7 +200,7 @@ export default class PicsContainer
ctx.i18n.define('zh', `commands.${this.config.commandName}.sources`, { ctx.i18n.define('zh', `commands.${this.config.commandName}.sources`, {
description: '查询图源列表', description: '查询图源列表',
options: { options: {
source: '要查询的图源标签,逗号分隔。', // source: '要查询的图源标签,逗号分隔。',
}, },
messages: { messages: {
list: '图源的列表如下:', list: '图源的列表如下:',
...@@ -209,14 +209,14 @@ export default class PicsContainer ...@@ -209,14 +209,14 @@ export default class PicsContainer
ctx.i18n.define('en', `commands.${this.config.commandName}.sources`, { ctx.i18n.define('en', `commands.${this.config.commandName}.sources`, {
description: 'Query picture sources', description: 'Query picture sources',
options: { options: {
source: 'Tags to search for, separated by comma.', // source: 'Tags to search for, separated by comma.',
}, },
messages: { messages: {
list: 'List of sources:', list: 'List of sources:',
}, },
}); });
ctx ctx
.command(`${this.config.commandName}`, '获取随机图片') .command(`${this.config.commandName} [...tags:string]`, '获取随机图片')
.usage( .usage(
`从各个图源中随机获取一张随机图片。图源可以用 ${this.config.commandName}.sources 查询。参数均为可选。`, `从各个图源中随机获取一张随机图片。图源可以用 ${this.config.commandName}.sources 查询。参数均为可选。`,
) )
...@@ -224,15 +224,16 @@ export default class PicsContainer ...@@ -224,15 +224,16 @@ export default class PicsContainer
'source', 'source',
`-s <source:string> 指定图源,逗号分隔。图源可以用 ${this.config.commandName}.sources 查询。`, `-s <source:string> 指定图源,逗号分隔。图源可以用 ${this.config.commandName}.sources 查询。`,
) )
.option('tag', '-t <tag:string> 需要查询的图片标签,逗号分隔。') // .option('tag', '-t <tag:string> 需要查询的图片标签,逗号分隔。')
.example( .example(
`${this.config.commandName} -s yande -t yuyuko 从 yande 图源中获取一张具有 yuyuko 标签的图。`, `${this.config.commandName} yuyuko -s yande 从 yande 图源中获取一张具有 yuyuko 标签的图。`,
) )
.action(async (argv) => { .action(async (argv, ...picTags) => {
const sourceTags = argv.options.source const sourceTags = argv.options.source
? argv.options.source.split(',') ? argv.options.source.split(/[,+\uFF0C\uFF0B\u3001]/)
: []; : [];
const picTags = argv.options.tag ? argv.options.tag.split(',') : []; // const picTags = argv.options.tag ? argv.options.tag.split(',') : [];
picTags ||= [];
const result = await this.randomPic(picTags, sourceTags); const result = await this.randomPic(picTags, sourceTags);
if (!result) { if (!result) {
return argv.session.text('.not-found'); return argv.session.text('.not-found');
...@@ -253,17 +254,18 @@ export default class PicsContainer ...@@ -253,17 +254,18 @@ export default class PicsContainer
} }
return msg; return msg;
}) })
.subcommand('.sources', '查询图源列表') .subcommand('.sources [...tags:string]', '查询图源列表')
.option('source', '-s <source:string> 要查询的图源标签,逗号分隔。') // .option('source', '-s <source:string> 要查询的图源标签,逗号分隔。')
.usage('图源标签可用于图片获取的图源筛选。') .usage('图源标签可用于图片获取的图源筛选。')
.example(`${this.config.commandName}.sources 查询全部的图源`) .example(`${this.config.commandName}.sources 查询全部的图源`)
.example( .example(
`${this.config.commandName} -s pixiv 查询含有 pixiv 标签的图源。`, `${this.config.commandName} -s pixiv 查询含有 pixiv 标签的图源。`,
) )
.action(async (argv) => { .action(async (argv, ...sourceTags) => {
const sourceTags = argv.options.source //const sourceTags = argv.options.source
? argv.options.source.split(',') // ? argv.options.source.split(',')
: []; // : [];
sourceTags ||= [];
const sources = this.pickAvailableSources(sourceTags, true); const sources = this.pickAvailableSources(sourceTags, true);
return `${argv.session.text('.list')}\n${sources return `${argv.session.text('.list')}\n${sources
.map((s) => s.getDisplayString()) .map((s) => s.getDisplayString())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment