mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-05 23:19:37 +00:00
Introduced explicit payloadSchema and returnSchema definitions for all OneBotAction classes using @sinclair/typebox. This improves type safety, API documentation, and validation for action payloads and return values. Also refactored method signatures and types for consistency across the codebase.
26 lines
1.0 KiB
TypeScript
26 lines
1.0 KiB
TypeScript
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
|
import { ActionName } from '@/napcat-onebot/action/router';
|
|
import { Static, Type } from '@sinclair/typebox';
|
|
|
|
export const SendLikePayloadSchema = Type.Object({
|
|
user_id: Type.String({ description: '对方 QQ 号' }),
|
|
times: Type.Union([Type.Number(), Type.String()], { default: 1, description: '点赞次数' }),
|
|
});
|
|
|
|
export type SendLikePayload = Static<typeof SendLikePayloadSchema>;
|
|
|
|
export default class SendLike extends OneBotAction<SendLikePayload, void> {
|
|
override actionName = ActionName.SendLike;
|
|
override payloadSchema = SendLikePayloadSchema;
|
|
override returnSchema = Type.Null();
|
|
|
|
async _handle (payload: SendLikePayload): Promise<void> {
|
|
const qq = payload.user_id.toString();
|
|
const uid: string = await this.core.apis.UserApi.getUidByUinV2(qq) ?? '';
|
|
const result = await this.core.apis.UserApi.like(uid, +payload.times);
|
|
if (result.result !== 0) {
|
|
throw new Error(`点赞失败 ${result.errMsg}`);
|
|
}
|
|
}
|
|
}
|