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.
38 lines
1.4 KiB
TypeScript
38 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';
|
|
|
|
|
|
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();
|
|
override actionSummary = '设置好友备注';
|
|
override actionDescription = '设置好友备注';
|
|
override actionTags = ['用户接口'];
|
|
override payloadExample = {
|
|
user_id: '123456',
|
|
remark: '测试备注'
|
|
};
|
|
override returnExample = null;
|
|
override errorExamples = [
|
|
{ code: 1400, description: '备注设置失败(好友不存在或非法输入)' }
|
|
];
|
|
|
|
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);
|
|
}
|
|
}
|