mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-05 23:19:37 +00:00
Standardized type usage and improved type safety across multiple OneBot action files. Updated payload schemas to use string types for IDs and flags, refined return types, and enhanced message content typing. Added error handling for missing parameters in SetGroupTodo.
26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
|
import { ActionName } from '@/napcat-onebot/action/router';
|
|
import { Static, Type } from '@sinclair/typebox';
|
|
|
|
export const SetFriendRemarkPayloadSchema = Type.Object({
|
|
user_id: Type.String({ description: '好友 QQ 号' }),
|
|
remark: Type.String({ description: '备注' }),
|
|
});
|
|
|
|
export type SetFriendRemarkPayload = Static<typeof SetFriendRemarkPayloadSchema>;
|
|
|
|
export default class SetFriendRemark extends OneBotAction<SetFriendRemarkPayload, void> {
|
|
override actionName = ActionName.SetFriendRemark;
|
|
override payloadSchema = SetFriendRemarkPayloadSchema;
|
|
override returnSchema = Type.Null();
|
|
|
|
async _handle (payload: SetFriendRemarkPayload): Promise<void> {
|
|
const friendUid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
|
const is_friend = await this.core.apis.FriendApi.isBuddy(friendUid);
|
|
if (!is_friend) {
|
|
throw new Error(`用户 ${payload.user_id} 不是好友`);
|
|
}
|
|
await this.core.apis.FriendApi.setBuddyRemark(friendUid, payload.remark);
|
|
}
|
|
}
|