mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-05 15:11:15 +00:00
Replaced Type.Union([Type.Number(), Type.String()]) with Type.String for group_id, user_id, and similar fields across all action payload schemas to standardize input types. Also made minor improvements to error handling, return types, and removed unused imports for better code clarity and consistency.
66 lines
2.9 KiB
TypeScript
66 lines
2.9 KiB
TypeScript
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
|
import { ActionName } from '@/napcat-onebot/action/router';
|
|
import { NetworkAdapterConfig } from '@/napcat-onebot/config/config';
|
|
import { Static, Type } from '@sinclair/typebox';
|
|
|
|
export const GetRecentContactPayloadSchema = Type.Object({
|
|
count: Type.Union([Type.Number(), Type.String()], { default: 10, description: '获取的数量' }),
|
|
});
|
|
|
|
export type GetRecentContactPayload = Static<typeof GetRecentContactPayloadSchema>;
|
|
|
|
export const GetRecentContactReturnSchema = Type.Array(Type.Object({
|
|
lastestMsg: Type.Any({ description: '最后一条消息' }),
|
|
peerUin: Type.String({ description: '对象QQ' }),
|
|
remark: Type.String({ description: '备注' }),
|
|
msgTime: Type.String({ description: '消息时间' }),
|
|
chatType: Type.Number({ description: '聊天类型' }),
|
|
msgId: Type.String({ description: '消息ID' }),
|
|
sendNickName: Type.String({ description: '发送者昵称' }),
|
|
sendMemberName: Type.String({ description: '发送者群名片' }),
|
|
peerName: Type.String({ description: '对象名称' }),
|
|
}), { description: '最近会话列表' });
|
|
|
|
export type GetRecentContactReturn = Static<typeof GetRecentContactReturnSchema>;
|
|
|
|
export default class GetRecentContact extends OneBotAction<GetRecentContactPayload, GetRecentContactReturn> {
|
|
override actionName = ActionName.GetRecentContact;
|
|
override payloadSchema = GetRecentContactPayloadSchema;
|
|
override returnSchema = GetRecentContactReturnSchema;
|
|
|
|
async _handle (payload: GetRecentContactPayload, _adapter: string, config: NetworkAdapterConfig): Promise<GetRecentContactReturn> {
|
|
const ret = await this.core.apis.UserApi.getRecentContactListSnapShot(+payload.count);
|
|
// 烘焙消息
|
|
const results = await Promise.all(ret.info.changedList.map(async (t) => {
|
|
const FastMsg = await this.core.apis.MsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]);
|
|
if (FastMsg.msgList.length > 0 && FastMsg.msgList[0]) {
|
|
// 扩展ret.info.changedList
|
|
const lastestMsg = await this.obContext.apis.MsgApi.parseMessage(FastMsg.msgList[0], config.messagePostFormat);
|
|
return {
|
|
lastestMsg,
|
|
peerUin: t.peerUin,
|
|
remark: String(t.remark ?? ''),
|
|
msgTime: t.msgTime,
|
|
chatType: t.chatType,
|
|
msgId: t.msgId,
|
|
sendNickName: String(t.sendNickName ?? ''),
|
|
sendMemberName: String(t.sendMemberName ?? ''),
|
|
peerName: String(t.peerName ?? ''),
|
|
};
|
|
}
|
|
return {
|
|
lastestMsg: undefined,
|
|
peerUin: t.peerUin,
|
|
remark: String(t.remark ?? ''),
|
|
msgTime: t.msgTime,
|
|
chatType: t.chatType,
|
|
msgId: t.msgId,
|
|
sendNickName: String(t.sendNickName ?? ''),
|
|
sendMemberName: String(t.sendMemberName ?? ''),
|
|
peerName: String(t.peerName ?? ''),
|
|
};
|
|
}));
|
|
return results;
|
|
}
|
|
}
|