mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-05 15:11:15 +00:00
Moved action example files into a new 'example' directory and updated all imports accordingly. Removed the monolithic 'examples.ts' and redefined ActionExamples in OneBotAction.ts to only include common error codes. This improves code organization and maintainability.
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
|
import { ActionName } from '@/napcat-onebot/action/router';
|
|
import { Static, Type } from '@sinclair/typebox';
|
|
|
|
import { ExtendsActionsExamples } from '../example/ExtendsActionsExamples';
|
|
|
|
const PayloadSchema = Type.Object({
|
|
words: Type.Array(Type.String(), { description: '待翻译单词列表' }),
|
|
});
|
|
|
|
type PayloadType = Static<typeof PayloadSchema>;
|
|
|
|
const ReturnSchema = Type.Object({
|
|
words: Type.Array(Type.String(), { description: '翻译结果列表' }),
|
|
}, { description: '翻译结果' });
|
|
|
|
type ReturnType = Static<typeof ReturnSchema>;
|
|
|
|
export class TranslateEnWordToZn extends OneBotAction<PayloadType, ReturnType> {
|
|
override actionName = ActionName.TranslateEnWordToZn;
|
|
override payloadSchema = PayloadSchema;
|
|
override returnSchema = ReturnSchema;
|
|
override actionSummary = '英文单词翻译';
|
|
override actionDescription = '将英文单词列表翻译为中文';
|
|
override actionTags = ['扩展接口'];
|
|
override payloadExample = ExtendsActionsExamples.TranslateEnWordToZn.payload;
|
|
override returnExample = ExtendsActionsExamples.TranslateEnWordToZn.response;
|
|
|
|
async _handle (payload: PayloadType): Promise<ReturnType> {
|
|
const ret = await this.core.apis.SystemApi.translateEnWordToZn(payload.words);
|
|
if (ret.result !== 0) {
|
|
throw new Error('翻译失败');
|
|
}
|
|
return {
|
|
words: ret.words
|
|
};
|
|
}
|
|
}
|