Commit d074367b authored by nanahira's avatar nanahira

bump

parent a149c82c
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
"typescript": "^4.5.5" "typescript": "^4.5.5"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.4.1" "koishi": "^4.4.2"
} }
}, },
"node_modules/@babel/code-frame": { "node_modules/@babel/code-frame": {
...@@ -998,14 +998,13 @@ ...@@ -998,14 +998,13 @@
} }
}, },
"node_modules/@koishijs/core": { "node_modules/@koishijs/core": {
"version": "4.4.1", "version": "4.4.2",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.4.1.tgz", "resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.4.2.tgz",
"integrity": "sha512-nd/QAm9ejk4KQP8BjnyuDCxg4rpyq4fyYtTvFOuafj9G/vN6gHL11YLF5R7g2WimnN1S2sN1txB7WNx8dnGI1A==", "integrity": "sha512-fLJIFQ52qjxJeKz8rpIL7ZIB46sOGu7DbXY++umVEQdn4PVdb6uVg87jdySW/VCx3VNv0gI2oFndE47fCattHg==",
"peer": true, "peer": true,
"dependencies": { "dependencies": {
"@koishijs/utils": "^5.2.0", "@koishijs/utils": "^5.2.1",
"fastest-levenshtein": "^1.0.12", "fastest-levenshtein": "^1.0.12"
"schemastery": "^3.1.0"
}, },
"engines": { "engines": {
"node": ">=12.0.0" "node": ">=12.0.0"
...@@ -1061,13 +1060,14 @@ ...@@ -1061,13 +1060,14 @@
"peer": true "peer": true
}, },
"node_modules/@koishijs/utils": { "node_modules/@koishijs/utils": {
"version": "5.2.0", "version": "5.2.1",
"resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.2.0.tgz", "resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.2.1.tgz",
"integrity": "sha512-KqZS/zK415XkFZn1EQ9BpT4ydaNS0ZFCAS64RT4pR8pzCUWz5eyN81Z8A7AmLKdJWgNDiT6mQ08EyUvMq0l/7Q==", "integrity": "sha512-Yu+QzmpStHAx5ZknSZhp9Zv3rfy6M4b1tuU3Wh8D3gTgZPeo+gqh07X7GyN7SA76Nr472rN8+hDqq5rafuA9iQ==",
"peer": true, "peer": true,
"dependencies": { "dependencies": {
"@koishijs/segment": "^1.1.1", "@koishijs/segment": "^1.1.1",
"supports-color": "^8.1.0" "schemastery": "^3.1.1",
"supports-color": "^8.1.1"
} }
}, },
"node_modules/@koishijs/utils/node_modules/supports-color": { "node_modules/@koishijs/utils/node_modules/supports-color": {
...@@ -1423,9 +1423,9 @@ ...@@ -1423,9 +1423,9 @@
} }
}, },
"node_modules/@types/ws": { "node_modules/@types/ws": {
"version": "8.5.2", "version": "8.5.3",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.2.tgz", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.3.tgz",
"integrity": "sha512-VXI82ykONr5tacHEojnErTQk+KQSoYbW1NB6iz6wUwrNd+BqfkfggQNoNdCqhJSzbNumShPERbM+Pc5zpfhlbw==", "integrity": "sha512-6YOoWjruKj1uLf3INHH7D3qTXwFfEsg1kf3c0uDdSBJwfa/llkwIjrAGV7j7mVgGNbzTQ3HiHKKDXl6bJPD97w==",
"peer": true, "peer": true,
"dependencies": { "dependencies": {
"@types/node": "*" "@types/node": "*"
...@@ -4737,17 +4737,17 @@ ...@@ -4737,17 +4737,17 @@
} }
}, },
"node_modules/koishi": { "node_modules/koishi": {
"version": "4.4.1", "version": "4.4.2",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.4.1.tgz", "resolved": "https://registry.npmjs.org/koishi/-/koishi-4.4.2.tgz",
"integrity": "sha512-yTJlAwsbF7ecjqRGUX5l2LT8HROusAZj1UjzxEevXGWklRrzABWTifIXDEKd9H+oC5xq4hJQeXRCQCogiPe+SQ==", "integrity": "sha512-zFLRGCeLT5Jy7KSw8iSlf7S/vz2mLJ/DIlqZv4TeoE5TjSkdTkTRqBMM+2XwrHXGdKHMbQ124rMr5CGFiNSXPA==",
"peer": true, "peer": true,
"dependencies": { "dependencies": {
"@koa/router": "^10.1.1", "@koa/router": "^10.1.1",
"@koishijs/core": "^4.4.1", "@koishijs/core": "^4.4.2",
"@koishijs/utils": "^5.2.0", "@koishijs/utils": "^5.2.1",
"@types/koa": "*", "@types/koa": "*",
"@types/koa__router": "*", "@types/koa__router": "*",
"@types/ws": "^8.5.2", "@types/ws": "^8.5.3",
"axios": "^0.24.0", "axios": "^0.24.0",
"file-type": "^16.5.3", "file-type": "^16.5.3",
"koa": "^2.13.4", "koa": "^2.13.4",
...@@ -5756,9 +5756,9 @@ ...@@ -5756,9 +5756,9 @@
} }
}, },
"node_modules/schemastery": { "node_modules/schemastery": {
"version": "3.1.0", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.1.0.tgz", "resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.1.1.tgz",
"integrity": "sha512-I1KaYmKfB+buINqBXydV8bC7N+BaC8y/V+609oSJNDO3mP3DY0zoNcDCIaY95KR0a5Cr9+CxgKl5BLEgFoikzw==", "integrity": "sha512-TdbphUvailcX1FqxSq3sqlxdFx/HhBD7TXliq1r4Su7BTChRQimHvrauK/Q75jLVCYaJPACDU92s0JTovmVrtA==",
"peer": true "peer": true
}, },
"node_modules/semver": { "node_modules/semver": {
...@@ -7534,14 +7534,13 @@ ...@@ -7534,14 +7534,13 @@
} }
}, },
"@koishijs/core": { "@koishijs/core": {
"version": "4.4.1", "version": "4.4.2",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.4.1.tgz", "resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.4.2.tgz",
"integrity": "sha512-nd/QAm9ejk4KQP8BjnyuDCxg4rpyq4fyYtTvFOuafj9G/vN6gHL11YLF5R7g2WimnN1S2sN1txB7WNx8dnGI1A==", "integrity": "sha512-fLJIFQ52qjxJeKz8rpIL7ZIB46sOGu7DbXY++umVEQdn4PVdb6uVg87jdySW/VCx3VNv0gI2oFndE47fCattHg==",
"peer": true, "peer": true,
"requires": { "requires": {
"@koishijs/utils": "^5.2.0", "@koishijs/utils": "^5.2.1",
"fastest-levenshtein": "^1.0.12", "fastest-levenshtein": "^1.0.12"
"schemastery": "^3.1.0"
} }
}, },
"@koishijs/plugin-adapter-onebot": { "@koishijs/plugin-adapter-onebot": {
...@@ -7577,13 +7576,14 @@ ...@@ -7577,13 +7576,14 @@
"peer": true "peer": true
}, },
"@koishijs/utils": { "@koishijs/utils": {
"version": "5.2.0", "version": "5.2.1",
"resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.2.0.tgz", "resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.2.1.tgz",
"integrity": "sha512-KqZS/zK415XkFZn1EQ9BpT4ydaNS0ZFCAS64RT4pR8pzCUWz5eyN81Z8A7AmLKdJWgNDiT6mQ08EyUvMq0l/7Q==", "integrity": "sha512-Yu+QzmpStHAx5ZknSZhp9Zv3rfy6M4b1tuU3Wh8D3gTgZPeo+gqh07X7GyN7SA76Nr472rN8+hDqq5rafuA9iQ==",
"peer": true, "peer": true,
"requires": { "requires": {
"@koishijs/segment": "^1.1.1", "@koishijs/segment": "^1.1.1",
"supports-color": "^8.1.0" "schemastery": "^3.1.1",
"supports-color": "^8.1.1"
}, },
"dependencies": { "dependencies": {
"supports-color": { "supports-color": {
...@@ -7923,9 +7923,9 @@ ...@@ -7923,9 +7923,9 @@
} }
}, },
"@types/ws": { "@types/ws": {
"version": "8.5.2", "version": "8.5.3",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.2.tgz", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.3.tgz",
"integrity": "sha512-VXI82ykONr5tacHEojnErTQk+KQSoYbW1NB6iz6wUwrNd+BqfkfggQNoNdCqhJSzbNumShPERbM+Pc5zpfhlbw==", "integrity": "sha512-6YOoWjruKj1uLf3INHH7D3qTXwFfEsg1kf3c0uDdSBJwfa/llkwIjrAGV7j7mVgGNbzTQ3HiHKKDXl6bJPD97w==",
"peer": true, "peer": true,
"requires": { "requires": {
"@types/node": "*" "@types/node": "*"
...@@ -10406,17 +10406,17 @@ ...@@ -10406,17 +10406,17 @@
} }
}, },
"koishi": { "koishi": {
"version": "4.4.1", "version": "4.4.2",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.4.1.tgz", "resolved": "https://registry.npmjs.org/koishi/-/koishi-4.4.2.tgz",
"integrity": "sha512-yTJlAwsbF7ecjqRGUX5l2LT8HROusAZj1UjzxEevXGWklRrzABWTifIXDEKd9H+oC5xq4hJQeXRCQCogiPe+SQ==", "integrity": "sha512-zFLRGCeLT5Jy7KSw8iSlf7S/vz2mLJ/DIlqZv4TeoE5TjSkdTkTRqBMM+2XwrHXGdKHMbQ124rMr5CGFiNSXPA==",
"peer": true, "peer": true,
"requires": { "requires": {
"@koa/router": "^10.1.1", "@koa/router": "^10.1.1",
"@koishijs/core": "^4.4.1", "@koishijs/core": "^4.4.2",
"@koishijs/utils": "^5.2.0", "@koishijs/utils": "^5.2.1",
"@types/koa": "*", "@types/koa": "*",
"@types/koa__router": "*", "@types/koa__router": "*",
"@types/ws": "^8.5.2", "@types/ws": "^8.5.3",
"axios": "^0.24.0", "axios": "^0.24.0",
"file-type": "^16.5.3", "file-type": "^16.5.3",
"koa": "^2.13.4", "koa": "^2.13.4",
...@@ -11150,9 +11150,9 @@ ...@@ -11150,9 +11150,9 @@
} }
}, },
"schemastery": { "schemastery": {
"version": "3.1.0", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.1.0.tgz", "resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.1.1.tgz",
"integrity": "sha512-I1KaYmKfB+buINqBXydV8bC7N+BaC8y/V+609oSJNDO3mP3DY0zoNcDCIaY95KR0a5Cr9+CxgKl5BLEgFoikzw==", "integrity": "sha512-TdbphUvailcX1FqxSq3sqlxdFx/HhBD7TXliq1r4Su7BTChRQimHvrauK/Q75jLVCYaJPACDU92s0JTovmVrtA==",
"peer": true "peer": true
}, },
"semver": { "semver": {
......
...@@ -65,6 +65,6 @@ ...@@ -65,6 +65,6 @@
"typed-reflector": "^1.0.9" "typed-reflector": "^1.0.9"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.4.1" "koishi": "^4.4.2"
} }
} }
...@@ -19,7 +19,7 @@ import { ...@@ -19,7 +19,7 @@ import {
FieldCollector, FieldCollector,
Selection, Selection,
Session, Session,
Store, I18n,
} from 'koishi'; } from 'koishi';
import { Metadata } from '../meta/metadata.decorators'; import { Metadata } from '../meta/metadata.decorators';
import { CommandPut, DoRegister } from '../registry'; import { CommandPut, DoRegister } from '../registry';
...@@ -77,6 +77,9 @@ export function UseCommand( ...@@ -77,6 +77,9 @@ export function UseCommand(
}; };
} }
export const UseFormatter = (name: string) => DoRegister.formatter(name);
export const UserRenderer = (name: string) => DoRegister.renderer(name);
// Context scopes // Context scopes
export const OnContext = ( export const OnContext = (
...@@ -231,17 +234,15 @@ export const DefineTemplate = (name: string, text: string | Dict<string>) => ...@@ -231,17 +234,15 @@ export const DefineTemplate = (name: string, text: string | Dict<string>) =>
registerTemplate({ name, text: adaptLocaleDict(text) }, ctx), registerTemplate({ name, text: adaptLocaleDict(text) }, ctx),
); );
type Node = string | Store; export function DefineLocale(locale: string, dict: I18n.Store): ClassDecorator;
export function DefineLocale(locale: string, dict: Store): ClassDecorator;
export function DefineLocale( export function DefineLocale(
locale: string, locale: string,
key: string, key: string,
value: Node, value: I18n.Node,
): ClassDecorator; ): ClassDecorator;
export function DefineLocale( export function DefineLocale(
locale: string, locale: string,
...args: [Store] | [string, Node] ...args: [I18n.Store] | [string, I18n.Node]
): ClassDecorator { ): ClassDecorator {
return TopLevelAction((ctx) => return TopLevelAction((ctx) =>
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
......
...@@ -6,7 +6,7 @@ import { ...@@ -6,7 +6,7 @@ import {
EventMap, EventMap,
Plugin, Plugin,
Selection, Selection,
Store, I18n,
} from 'koishi'; } from 'koishi';
import type { DefaultContext, DefaultState, ParameterizedContext } from 'koa'; import type { DefaultContext, DefaultState, ParameterizedContext } from 'koa';
import type { RouterParamContext } from '@koa/router'; import type { RouterParamContext } from '@koa/router';
...@@ -154,10 +154,10 @@ export interface CommandOptionConfigWithDescription extends Argv.OptionConfig { ...@@ -154,10 +154,10 @@ export interface CommandOptionConfigWithDescription extends Argv.OptionConfig {
description?: string | Dict<string>; description?: string | Dict<string>;
} }
export interface CommandLocaleDef extends Store { export interface CommandLocaleDef extends I18n.Store {
description?: string; description?: string;
options?: Dict<string>; options?: Dict<string>;
messages?: Store; messages?: I18n.Store;
} }
export interface CommandArgDef { export interface CommandArgDef {
......
...@@ -46,6 +46,8 @@ export namespace DoRegister { ...@@ -46,6 +46,8 @@ export namespace DoRegister {
command: CommandRegisterConfig; command: CommandRegisterConfig;
route: KoishiRouteDef; route: KoishiRouteDef;
ws: MaybeArray<string | RegExp>; ws: MaybeArray<string | RegExp>;
formatter: string;
renderer: string;
} }
export type Config<K extends keyof ConfigMap = keyof ConfigMap> = export type Config<K extends keyof ConfigMap = keyof ConfigMap> =
...@@ -152,4 +154,23 @@ export namespace DoRegister { ...@@ -152,4 +154,23 @@ export namespace DoRegister {
return command; return command;
}, },
); );
export const formatter = registry.define(
'formatter',
(data, ctx, obj, key) => {
ctx.i18n.formatter(data, (...args) => obj[key](...args));
ctx.on('dispose', () => {
delete ctx.i18n._formatters[data];
});
return;
},
);
export const renderer = registry.define('renderer', (data, ctx, obj, key) => {
ctx.i18n.renderer(data, (...args) => obj[key](...args));
ctx.on('dispose', () => {
delete ctx.i18n._renderers[data];
});
return;
});
} }
...@@ -41,7 +41,7 @@ class MyClass { ...@@ -41,7 +41,7 @@ class MyClass {
return `bot: ${content}`; return `bot: ${content}`;
} }
@UseCommand('count') @UseCommand('count <count>')
async onCount(@PutArg(0) count: number) { async onCount(@PutArg(0) count: number) {
return `I have ${count} dresses.`; return `I have ${count} dresses.`;
} }
...@@ -91,6 +91,7 @@ describe('Register', () => { ...@@ -91,6 +91,7 @@ describe('Register', () => {
expect(result.type).toBe('command'); expect(result.type).toBe('command');
const command: Command = result.result; const command: Command = result.result;
expect(command._arguments[0].type).toBe('number'); expect(command._arguments[0].type).toBe('number');
expect(command._arguments[0].required).toBe(true);
expect(command.execute({ args: ['4'] })).resolves.toBe('I have 4 dresses.'); expect(command.execute({ args: ['4'] })).resolves.toBe('I have 4 dresses.');
}); });
......
...@@ -38,9 +38,9 @@ describe('Register', () => { ...@@ -38,9 +38,9 @@ describe('Register', () => {
options: { content: 'hello' }, options: { content: 'hello' },
session: { session: {
text(path, params) { text(path, params) {
return app.i18n.render( return app.i18n.text(
[locale.locale], [locale.locale],
`commands.echo.messages${path}`, [`commands.echo.messages${path}`],
params, params,
); );
}, },
......
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