NapCatQQ/packages/napcat-onebot/action/extends/TranslateEnWordToZn.ts
手瓜一十雪 5b80a8576f Refactor extends actions to use new examples module
Replaced imports of ActionExamples with ExtendsActionsExamples in all extends actions. Updated action summary, description, tags, and example references for consistency and clarity across actions. This improves maintainability and aligns with the new examples structure.
2026-01-25 18:23:19 +08:00

35 lines
1.3 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 './examples';
const PayloadSchema = Type.Object({
words: Type.Array(Type.String(), { description: '待翻译单词列表' }),
});
type PayloadType = Static<typeof PayloadSchema>;
const ReturnSchema = Type.Union([Type.Array(Type.Any()), Type.Undefined()], { 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 ret.words;
}
}