Commit 7947540e authored by nanahira's avatar nanahira

bump and for templating meta

parent 0b7a7ad9
......@@ -9,7 +9,7 @@
"version": "9.2.0",
"license": "MIT",
"dependencies": {
"koishi-thirdeye": "^10.1.0",
"koishi-thirdeye": "^10.1.4",
"lodash": "^4.17.21"
},
"devDependencies": {
......@@ -5234,28 +5234,29 @@
}
},
"node_modules/koishi-decorators": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.0.1.tgz",
"integrity": "sha512-dDrBS4Su1NtmrkIeCdcCKsC6uaBYTRTspDdeeoPLOMuSJf6fqqXwxa2qEosvG5475MXs9SaNQDaKjh0gq/NY6A==",
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.0.3.tgz",
"integrity": "sha512-rAC3bJVdeIQmydUbOWy+SWqtczUJfUHSIQggR5+bVI9oKMxNuTfbik3xD/FnCMF84Z9aCklOz5MJOLPbaUs1pw==",
"dependencies": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
"lodash": "^4.17.21",
"mustache": "^4.2.0",
"reflect-metadata": "^0.1.13",
"typed-reflector": "^1.0.10"
},
"peerDependencies": {
"koishi": "^4.6.0"
"koishi": "^4.7.0"
}
},
"node_modules/koishi-thirdeye": {
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-10.1.0.tgz",
"integrity": "sha512-ElobuJABbWmWdFkzaU6pUmHUCqvpAwIe43BwxwV2AOHWrFM7IJtS9W+rODfx4WaUrnP7KMy2+jPt5C4UyD8tYQ==",
"version": "10.1.4",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-10.1.4.tgz",
"integrity": "sha512-uOCBw/SsAqW3HtKU/iozJTogJXnvDbP98n/20+CaLoAe+xK05z6QToRR6hEk0CLsAYgSivkXbUsEKTBHKT4i/g==",
"dependencies": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
"koishi-decorators": "^2.0.1",
"koishi-decorators": "^2.0.3",
"lodash": "^4.17.21",
"minato-decorators": "^2.0.6",
"reflect-metadata": "^0.1.13",
......@@ -5529,6 +5530,14 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/mustache": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz",
"integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==",
"bin": {
"mustache": "bin/mustache"
}
},
"node_modules/natural-compare": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
......@@ -11808,25 +11817,26 @@
}
},
"koishi-decorators": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.0.1.tgz",
"integrity": "sha512-dDrBS4Su1NtmrkIeCdcCKsC6uaBYTRTspDdeeoPLOMuSJf6fqqXwxa2qEosvG5475MXs9SaNQDaKjh0gq/NY6A==",
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.0.3.tgz",
"integrity": "sha512-rAC3bJVdeIQmydUbOWy+SWqtczUJfUHSIQggR5+bVI9oKMxNuTfbik3xD/FnCMF84Z9aCklOz5MJOLPbaUs1pw==",
"requires": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
"lodash": "^4.17.21",
"mustache": "^4.2.0",
"reflect-metadata": "^0.1.13",
"typed-reflector": "^1.0.10"
}
},
"koishi-thirdeye": {
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-10.1.0.tgz",
"integrity": "sha512-ElobuJABbWmWdFkzaU6pUmHUCqvpAwIe43BwxwV2AOHWrFM7IJtS9W+rODfx4WaUrnP7KMy2+jPt5C4UyD8tYQ==",
"version": "10.1.4",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-10.1.4.tgz",
"integrity": "sha512-uOCBw/SsAqW3HtKU/iozJTogJXnvDbP98n/20+CaLoAe+xK05z6QToRR6hEk0CLsAYgSivkXbUsEKTBHKT4i/g==",
"requires": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
"koishi-decorators": "^2.0.1",
"koishi-decorators": "^2.0.3",
"lodash": "^4.17.21",
"minato-decorators": "^2.0.6",
"reflect-metadata": "^0.1.13",
......@@ -12044,6 +12054,11 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"mustache": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz",
"integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ=="
},
"natural-compare": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
......
......@@ -29,7 +29,7 @@
},
"homepage": "https://github.com/koishijs/koishi-plugin-pics",
"dependencies": {
"koishi-thirdeye": "^10.1.0",
"koishi-thirdeye": "^10.1.4",
"lodash": "^4.17.21"
},
"devDependencies": {
......
......@@ -6,11 +6,19 @@ import { segment, Quester } from 'koishi';
import {
BasePlugin,
Caller,
CommandExample,
CommandLocale,
DefinePlugin,
Inject,
InjectLogger,
LifecycleEvents,
Provide,
PutArgs,
PutBot,
PutOption,
PutRenderer,
Renderer,
UseCommand,
} from 'koishi-thirdeye';
import { AxiosRequestConfig } from 'axios';
import { PicAssetsTransformMiddleware } from './middlewares/assets';
......@@ -242,76 +250,81 @@ export default class PicsContainer
}
}
@UseCommand('{{commandName}} [...tags:string]')
@CommandLocale('zh', {
description: '获取随机图片',
options: {
source: `指定图源,逗号分隔。图源可以用 {{commandName}}.sources 查询。`,
},
usage: `从各个图源中随机获取一张随机图片。图源可以用 {{commandName}}.sources 查询。参数均为可选。`,
messages: {
'not-found': '未找到任何图片。',
},
})
@CommandLocale('en', {
description: 'Get random picture',
options: {
source: `Specify the source, separated by comma. You can query the sources with {{commandName}}.sources.`,
},
usage: `Get a random picture from a random source. Sources can be queried with command {{commandName}}.sources`,
messages: {
'not-found': 'No pictures found.',
},
})
@CommandExample(`{{commandName}}`)
@CommandExample(`{{commandName}} yuyuko`)
@CommandExample(`{{commandName}} -s yande`)
@CommandExample(`{{commandName}} -s yande yuyuko saigyouji`)
async onPic(
@PutOption('source', `-s <source>`) source: string,
@PutArgs() picTags: string[],
@PutRenderer('.not-found') notFound: Renderer,
@PutBot() bot: Bot,
) {
const sourceTags = source?.split(/[ ,+\uFF0C\uFF0B\u3001]/) || [];
picTags ||= [];
const result = await this.randomPic(picTags, sourceTags);
if (!result) {
return notFound();
}
let msg = await this.getSegment(result.url, bot);
if (result.description) {
msg += `\n${result.description}`;
}
return msg;
}
@UseCommand('{{commandName}}.sources')
@CommandLocale('zh', {
description: '查询图源列表',
options: {},
usage: '图源标签可用于图片获取的图源筛选。',
messages: {
list: '图源的列表如下:',
},
})
@CommandLocale('en', {
description: 'Query picture sources',
options: {},
usage: 'Source tags can be used to filter picture sources.',
messages: {
list: 'List of sources:',
},
})
@CommandExample(`{{commandName}}.sources`)
@CommandExample(`{{commandName}}.sources pixiv`)
async onQuerySource(
@PutArgs() sourceTags: string[],
@PutRenderer('.list') list: Renderer,
) {
sourceTags ||= [];
const sources = this.pickAvailableSources(sourceTags, true);
return `${list()}\n${sources.map((s) => s.getDisplayString()).join('\n')}`;
}
onApply() {
this._http = this.http.extend(this.config.httpConfig);
this.installDefaultMiddlewares();
const ctx = this.ctx;
ctx.i18n.define('zh', `commands.${this.config.commandName}`, {
description: '获取随机图片',
options: {
source: `指定图源,逗号分隔。图源可以用 ${this.config.commandName}.sources 查询。`,
},
usage: `从各个图源中随机获取一张随机图片。图源可以用 ${this.config.commandName}.sources 查询。参数均为可选。`,
messages: {
'not-found': '未找到任何图片。',
},
});
ctx.i18n.define('en', `commands.${this.config.commandName}`, {
description: 'Get random picture',
options: {},
usage: `Get a random picture from a random sourse. Sources can be queried with command ${this.config.commandName}.sources`,
messages: {
'not-found': 'No pictures found.',
},
});
ctx.i18n.define('zh', `commands.${this.config.commandName}.sources`, {
description: '查询图源列表',
options: {},
usage: '图源标签可用于图片获取的图源筛选。',
messages: {
list: '图源的列表如下:',
},
});
ctx.i18n.define('en', `commands.${this.config.commandName}.sources`, {
description: 'Query picture sources',
options: {},
usage: 'Source tags can be used to filter picture sources.',
messages: {
list: 'List of sources:',
},
});
ctx
.command(`${this.config.commandName} [...tags:string]`)
.option('source', `-s <source:string>`)
.example(`${this.config.commandName}`)
.example(`${this.config.commandName} yuyuko`)
.example(`${this.config.commandName} -s yande`)
.example(`${this.config.commandName} -s yande yuyuko saigyouji`)
.action(async (argv, ...picTags) => {
const sourceTags = argv.options.source
? argv.options.source.split(/[ ,+\uFF0C\uFF0B\u3001]/)
: [];
picTags ||= [];
const result = await this.randomPic(picTags, sourceTags);
if (!result) {
return argv.session.text('.not-found');
}
let msg = await this.getSegment(result.url, argv.session.bot);
if (result.description) {
msg += `\n${result.description}`;
}
return msg;
})
.subcommand('.sources [...tags:string]')
.example(`${this.config.commandName}.sources`)
.example(`${this.config.commandName}.sources pixiv`)
.action(async (argv, ...sourceTags) => {
sourceTags ||= [];
const sources = this.pickAvailableSources(sourceTags, true);
return `${argv.session.text('.list')}\n${sources
.map((s) => s.getDisplayString())
.join('\n')}`;
});
}
}
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