diff --git a/packages/docs/docs/code/2152/index.mdx b/packages/docs/docs/code/2152/index.mdx new file mode 100644 index 0000000..621b0e7 --- /dev/null +++ b/packages/docs/docs/code/2152/index.mdx @@ -0,0 +1,10 @@ +--- +title: 2152:内部错误 +sidebar_position: 2152 +--- + +import { ErrorScope } from '@site/src/components/ErrorScope' + + + +Chronocat 内部出现了错误。这是 Chronocat 的问题。 diff --git a/packages/engine-chronocat-api/src/api/channel/member/mute.ts b/packages/engine-chronocat-api/src/api/channel/member/mute.ts index af0809d..6aadc79 100644 --- a/packages/engine-chronocat-api/src/api/channel/member/mute.ts +++ b/packages/engine-chronocat-api/src/api/channel/member/mute.ts @@ -7,12 +7,21 @@ import { setMemberShutUp } from '../../../definitions/groupService' export const buildChannelMemberMute = (ctx: ChronocatContext) => async ({ channel_id, user_id, duration }: ChannelMemberMutePayload) => { + const uid = await ctx.chronocat.uix.getUid2(user_id, channel_id) + if (!uid) { + ctx.chronocat.l.error('内部错误', { + code: 2152, + throw: true, + }) + return {} + } + await setMemberShutUp({ groupCode: channel_id, memList: [ { - uid: ctx.chronocat.uix.getUid(user_id), + uid, timeStamp: duration, }, ], diff --git a/packages/engine-chronocat-api/src/api/friend/approve.ts b/packages/engine-chronocat-api/src/api/friend/approve.ts index 20c8d4c..a3e42ef 100644 --- a/packages/engine-chronocat-api/src/api/friend/approve.ts +++ b/packages/engine-chronocat-api/src/api/friend/approve.ts @@ -14,9 +14,18 @@ export const buildFriendApprove = const [uin, reqTime] = message_id.split(':') as [string, string] + const friendUid = await ctx.chronocat.uix.getUid2(uin) + if (!friendUid) { + ctx.chronocat.l.error('内部错误', { + code: 2152, + throw: true, + }) + return {} + } + await approvalFriendRequest({ approvalInfo: { - friendUid: ctx.chronocat.uix.getUid(uin)!, + friendUid, reqTime, accept: approve, }, diff --git a/packages/engine-chronocat-api/src/api/friend/remove.ts b/packages/engine-chronocat-api/src/api/friend/remove.ts index 429c7fc..5b0ecaa 100644 --- a/packages/engine-chronocat-api/src/api/friend/remove.ts +++ b/packages/engine-chronocat-api/src/api/friend/remove.ts @@ -4,9 +4,18 @@ import { delBuddy } from '../../definitions/buddyService' export const buildFriendRemove = (ctx: ChronocatContext) => async ({ user_id }: UserPayload) => { + const friendUid = await ctx.chronocat.uix.getUid2(user_id) + if (!friendUid) { + ctx.chronocat.l.error('内部错误', { + code: 2152, + throw: true, + }) + return {} + } + await delBuddy({ delInfo: { - friendUid: ctx.chronocat.uix.getUid(user_id)!, + friendUid, tempBlock: false, tempBothDel: true, }, diff --git a/packages/engine-chronocat-api/src/api/guild/member/kick.ts b/packages/engine-chronocat-api/src/api/guild/member/kick.ts index 26c6294..50d5d8b 100644 --- a/packages/engine-chronocat-api/src/api/guild/member/kick.ts +++ b/packages/engine-chronocat-api/src/api/guild/member/kick.ts @@ -4,9 +4,18 @@ import { kickMember } from '../../../definitions/groupService' export const buildGuildMemberKick = (ctx: ChronocatContext) => async ({ guild_id, user_id, permanent }: GuildMemberKickPayload) => { + const uid = await ctx.chronocat.uix.getUid2(user_id, guild_id) + if (!uid) { + ctx.chronocat.l.error('内部错误', { + code: 2152, + throw: true, + }) + return {} + } + await kickMember({ groupCode: guild_id, - kickUids: [ctx.chronocat.uix.getUid(user_id)!], + kickUids: [uid], refuseForever: permanent as boolean, kickReason: '', }) diff --git a/packages/engine-chronocat-api/src/api/guild/member/mute.ts b/packages/engine-chronocat-api/src/api/guild/member/mute.ts index 0f7584d..8ca80b0 100644 --- a/packages/engine-chronocat-api/src/api/guild/member/mute.ts +++ b/packages/engine-chronocat-api/src/api/guild/member/mute.ts @@ -4,12 +4,21 @@ import { setMemberShutUp } from '../../../definitions/groupService' export const buildGuildMemberMute = (ctx: ChronocatContext) => async ({ guild_id, user_id, duration }: GuildMemberMutePayload) => { + const uid = await ctx.chronocat.uix.getUid2(user_id, guild_id) + if (!uid) { + ctx.chronocat.l.error('内部错误', { + code: 2152, + throw: true, + }) + return {} + } + await setMemberShutUp({ groupCode: guild_id, memList: [ { - uid: ctx.chronocat.uix.getUid(user_id), + uid, timeStamp: Math.floor(duration / 1000), }, ], diff --git a/packages/engine-chronocat-api/src/api/internal/assets/get.ts b/packages/engine-chronocat-api/src/api/internal/assets/get.ts index 75000df..0621e68 100644 --- a/packages/engine-chronocat-api/src/api/internal/assets/get.ts +++ b/packages/engine-chronocat-api/src/api/internal/assets/get.ts @@ -25,8 +25,18 @@ export const buildAssetsGet = if ( data.chatType === ChatType.Private && !data.peerUid.startsWith('u_') - ) - data.peerUid = ctx.chronocat.uix.getUid(data.peerUid)! + ) { + const peerUid = await ctx.chronocat.uix.getUid2(data.peerUid) + if (!peerUid) { + ctx.chronocat.l.error('内部错误', { + code: 2152, + throw: true, + }) + return Promise.resolve() + } + + data.peerUid = peerUid + } await downloadRichMedia({ getReq: { diff --git a/packages/engine-chronocat-api/src/api/message/delete.ts b/packages/engine-chronocat-api/src/api/message/delete.ts index 7690afd..4ddec27 100644 --- a/packages/engine-chronocat-api/src/api/message/delete.ts +++ b/packages/engine-chronocat-api/src/api/message/delete.ts @@ -5,11 +5,20 @@ import { recallMsg } from '../../definitions/msgService' export const buildMessageDelete = (ctx: ChronocatContext) => async ({ channel_id, message_id }: MessageDeletePayload) => { + const privatePeerUid = await ctx.chronocat.uix.getUid2(channel_id.slice(8)) // private: + if (!privatePeerUid) { + ctx.chronocat.l.error('内部错误', { + code: 2152, + throw: true, + }) + return {} + } + await recallMsg({ peer: channel_id.startsWith('private:') ? { chatType: ChatType.Private, - peerUid: ctx.chronocat.uix.getUid(channel_id.slice(8))!, // private: + peerUid: privatePeerUid, } : { chatType: ChatType.Group, diff --git a/packages/engine-chronocat-api/src/common/send.ts b/packages/engine-chronocat-api/src/common/send.ts index 7a4307f..f127b89 100644 --- a/packages/engine-chronocat-api/src/common/send.ts +++ b/packages/engine-chronocat-api/src/common/send.ts @@ -10,6 +10,15 @@ export const commonSend = async ( peer: Partial, elements: O.Partial[], ) => { + const privatePeerUid = await ctx.chronocat.uix.getUid2(peer.peerUid!) + if (!privatePeerUid) { + ctx.chronocat.l.error('内部错误', { + code: 2152, + throw: true, + }) + return Promise.resolve(undefined as unknown as RedMessage) + } + const param = { msgId: '0', msgAttributeInfos: new Map(), @@ -17,7 +26,7 @@ export const commonSend = async ( peer.chatType === ChatType.Private ? { chatType: ChatType.Private, - peerUid: ctx.chronocat.uix.getUid(peer.peerUid!)!, + peerUid: privatePeerUid, } : (peer as Peer), msgElements: elements, @@ -60,11 +69,22 @@ export const commonSendForward = async ( }[], source?: Partial | undefined, ) => { + const srcPeerUid = await ctx.chronocat.uix.getUid2(source!.peerUid!) + const dstPeerUid = await ctx.chronocat.uix.getUid2(peer.peerUid!) + + if (!srcPeerUid || !dstPeerUid) { + ctx.chronocat.l.error('内部错误', { + code: 2152, + throw: true, + }) + return task + } + const srcContact = source ? source.chatType === ChatType.Private ? { chatType: ChatType.Private, - peerUid: ctx.chronocat.uix.getUid(source.peerUid!)!, + peerUid: srcPeerUid, } : (source as Peer) : defaultSrcContact @@ -73,7 +93,7 @@ export const commonSendForward = async ( peer.chatType === ChatType.Private ? { chatType: ChatType.Private, - peerUid: ctx.chronocat.uix.getUid(peer.peerUid!)!, + peerUid: dstPeerUid, } : (peer as Peer) diff --git a/packages/engine-chronocat-event/src/handler.ts b/packages/engine-chronocat-event/src/handler.ts index f1840ef..b88a7f4 100644 --- a/packages/engine-chronocat-event/src/handler.ts +++ b/packages/engine-chronocat-event/src/handler.ts @@ -218,8 +218,11 @@ const dispatcher = async ( const { notifies } = payload as OnGroupSingleScreenNotifies for (const notify of notifies) { - const uin = ctx.chronocat.uix.getUin(notify.user1.uid) - if (!uin) return + const uin = await ctx.chronocat.uix.getUin2(notify.user1.uid) // 此时用户刚刚申请入群,不在群里,不能带 group 场景 + if (!uin) { + ctx.chronocat.l.error('内部错误', { code: 2152 }) + return + } const key = `${notify.group.groupCode}:${uin}:${notify.seq}` if (emittedGroupReqList.includes(key)) return @@ -251,11 +254,15 @@ const dispatcher = async ( case 'nodeIKernelBuddyListener/onBuddyReqChange': { const { buddyReqs } = payload as OnBuddyReqChange - buddyReqs.forEach((x) => { + // eslint-disable-next-line @typescript-eslint/no-misused-promises + buddyReqs.forEach(async (x) => { if (x.reqType !== 1 || x.reqSubType !== 1) return - const uin = ctx.chronocat.uix.getUin(x.friendUid) - if (!uin) return + const uin = await ctx.chronocat.uix.getUin2(x.friendUid) + if (!uin) { + ctx.chronocat.l.error('内部错误', { code: 2152 }) + return + } const key = `${uin}:${x.reqTime}` if (emittedBuddyReqList.includes(key)) return diff --git a/packages/engine-chronocat-event/src/parser/index.ts b/packages/engine-chronocat-event/src/parser/index.ts index 979f5d1..825910e 100644 --- a/packages/engine-chronocat-event/src/parser/index.ts +++ b/packages/engine-chronocat-event/src/parser/index.ts @@ -223,7 +223,12 @@ async function parseChatMessage( event: Event, message: RedMessage, ) { - const [elements, extraEvents] = await parseElements(ctx, config, message) + const [elements, extraEvents] = await parseElements( + ctx, + config, + event, + message, + ) event.type = 'message-created' event.message = { id: message.msgId, @@ -390,7 +395,7 @@ async function parsePokeMessage( event.type = 'message-created' event.message = { id: message.msgId, - content: `<${ctx.chronocat.platform}:poke user-id="${ctx.chronocat.uix.getUin(user.uid)}" operator-id="${ctx.chronocat.uix.getUin(operator.uid)}"/>`, + content: `<${ctx.chronocat.platform}:poke user-id="${await ctx.chronocat.uix.getUin2(user.uid, event.guild?.id)}" operator-id="${await ctx.chronocat.uix.getUin2(operator.uid, event.guild?.id)}"/>`, } return [event] @@ -402,6 +407,7 @@ async function parsePokeMessage( async function parseElements( ctx: ChronocatContext, config: O.Intersect, + event: Event, message: RedMessage, ) { const l = ctx.chronocat.l @@ -432,7 +438,10 @@ async function parseElements( let id: string | undefined = m.textElement!.atUid if (id === '0') id = undefined - id ||= ctx.chronocat.uix.getUin(m.textElement!.atNtUid) + id ||= await ctx.chronocat.uix.getUin2( + m.textElement!.atNtUid, + event.guild?.id, + ) const name = m.textElement!.content.slice(1) @@ -590,7 +599,7 @@ async function parseElements( }, [ await parseAuthor(ctx, source), - ...(await parseElements(ctx, config, source))[0], + ...(await parseElements(ctx, config, event, source))[0], ], ), )