feat: adapt uix.getUix2()

This commit is contained in:
Il Harper 2024-08-23 15:29:37 +08:00
parent 3963ab61e7
commit 91b713a5aa
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
11 changed files with 130 additions and 20 deletions

View File

@ -0,0 +1,10 @@
---
title: 2152内部错误
sidebar_position: 2152
---
import { ErrorScope } from '@site/src/components/ErrorScope'
<ErrorScope scope="chronocat" />
Chronocat 内部出现了错误。这是 Chronocat 的问题。

View File

@ -7,12 +7,21 @@ import { setMemberShutUp } from '../../../definitions/groupService'
export const buildChannelMemberMute = export const buildChannelMemberMute =
(ctx: ChronocatContext) => (ctx: ChronocatContext) =>
async ({ channel_id, user_id, duration }: ChannelMemberMutePayload) => { 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({ await setMemberShutUp({
groupCode: channel_id, groupCode: channel_id,
memList: [ memList: [
{ {
uid: ctx.chronocat.uix.getUid(user_id), uid,
timeStamp: duration, timeStamp: duration,
}, },
], ],

View File

@ -14,9 +14,18 @@ export const buildFriendApprove =
const [uin, reqTime] = message_id.split(':') as [string, string] 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({ await approvalFriendRequest({
approvalInfo: { approvalInfo: {
friendUid: ctx.chronocat.uix.getUid(uin)!, friendUid,
reqTime, reqTime,
accept: approve, accept: approve,
}, },

View File

@ -4,9 +4,18 @@ import { delBuddy } from '../../definitions/buddyService'
export const buildFriendRemove = export const buildFriendRemove =
(ctx: ChronocatContext) => (ctx: ChronocatContext) =>
async ({ user_id }: UserPayload) => { 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({ await delBuddy({
delInfo: { delInfo: {
friendUid: ctx.chronocat.uix.getUid(user_id)!, friendUid,
tempBlock: false, tempBlock: false,
tempBothDel: true, tempBothDel: true,
}, },

View File

@ -4,9 +4,18 @@ import { kickMember } from '../../../definitions/groupService'
export const buildGuildMemberKick = export const buildGuildMemberKick =
(ctx: ChronocatContext) => (ctx: ChronocatContext) =>
async ({ guild_id, user_id, permanent }: GuildMemberKickPayload) => { 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({ await kickMember({
groupCode: guild_id, groupCode: guild_id,
kickUids: [ctx.chronocat.uix.getUid(user_id)!], kickUids: [uid],
refuseForever: permanent as boolean, refuseForever: permanent as boolean,
kickReason: '', kickReason: '',
}) })

View File

@ -4,12 +4,21 @@ import { setMemberShutUp } from '../../../definitions/groupService'
export const buildGuildMemberMute = export const buildGuildMemberMute =
(ctx: ChronocatContext) => (ctx: ChronocatContext) =>
async ({ guild_id, user_id, duration }: GuildMemberMutePayload) => { 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({ await setMemberShutUp({
groupCode: guild_id, groupCode: guild_id,
memList: [ memList: [
{ {
uid: ctx.chronocat.uix.getUid(user_id), uid,
timeStamp: Math.floor(duration / 1000), timeStamp: Math.floor(duration / 1000),
}, },
], ],

View File

@ -25,8 +25,18 @@ export const buildAssetsGet =
if ( if (
data.chatType === ChatType.Private && data.chatType === ChatType.Private &&
!data.peerUid.startsWith('u_') !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({ await downloadRichMedia({
getReq: { getReq: {

View File

@ -5,11 +5,20 @@ import { recallMsg } from '../../definitions/msgService'
export const buildMessageDelete = export const buildMessageDelete =
(ctx: ChronocatContext) => (ctx: ChronocatContext) =>
async ({ channel_id, message_id }: MessageDeletePayload) => { 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({ await recallMsg({
peer: channel_id.startsWith('private:') peer: channel_id.startsWith('private:')
? { ? {
chatType: ChatType.Private, chatType: ChatType.Private,
peerUid: ctx.chronocat.uix.getUid(channel_id.slice(8))!, // private: peerUid: privatePeerUid,
} }
: { : {
chatType: ChatType.Group, chatType: ChatType.Group,

View File

@ -10,6 +10,15 @@ export const commonSend = async (
peer: Partial<Peer>, peer: Partial<Peer>,
elements: O.Partial<Element, 'deep'>[], elements: O.Partial<Element, 'deep'>[],
) => { ) => {
const privatePeerUid = await ctx.chronocat.uix.getUid2(peer.peerUid!)
if (!privatePeerUid) {
ctx.chronocat.l.error('内部错误', {
code: 2152,
throw: true,
})
return Promise.resolve<RedMessage>(undefined as unknown as RedMessage)
}
const param = { const param = {
msgId: '0', msgId: '0',
msgAttributeInfos: new Map(), msgAttributeInfos: new Map(),
@ -17,7 +26,7 @@ export const commonSend = async (
peer.chatType === ChatType.Private peer.chatType === ChatType.Private
? { ? {
chatType: ChatType.Private, chatType: ChatType.Private,
peerUid: ctx.chronocat.uix.getUid(peer.peerUid!)!, peerUid: privatePeerUid,
} }
: (peer as Peer), : (peer as Peer),
msgElements: elements, msgElements: elements,
@ -60,11 +69,22 @@ export const commonSendForward = async (
}[], }[],
source?: Partial<Peer> | undefined, source?: Partial<Peer> | 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 const srcContact = source
? source.chatType === ChatType.Private ? source.chatType === ChatType.Private
? { ? {
chatType: ChatType.Private, chatType: ChatType.Private,
peerUid: ctx.chronocat.uix.getUid(source.peerUid!)!, peerUid: srcPeerUid,
} }
: (source as Peer) : (source as Peer)
: defaultSrcContact : defaultSrcContact
@ -73,7 +93,7 @@ export const commonSendForward = async (
peer.chatType === ChatType.Private peer.chatType === ChatType.Private
? { ? {
chatType: ChatType.Private, chatType: ChatType.Private,
peerUid: ctx.chronocat.uix.getUid(peer.peerUid!)!, peerUid: dstPeerUid,
} }
: (peer as Peer) : (peer as Peer)

View File

@ -218,8 +218,11 @@ const dispatcher = async (
const { notifies } = payload as OnGroupSingleScreenNotifies const { notifies } = payload as OnGroupSingleScreenNotifies
for (const notify of notifies) { for (const notify of notifies) {
const uin = ctx.chronocat.uix.getUin(notify.user1.uid) const uin = await ctx.chronocat.uix.getUin2(notify.user1.uid) // 此时用户刚刚申请入群,不在群里,不能带 group 场景
if (!uin) return if (!uin) {
ctx.chronocat.l.error('内部错误', { code: 2152 })
return
}
const key = `${notify.group.groupCode}:${uin}:${notify.seq}` const key = `${notify.group.groupCode}:${uin}:${notify.seq}`
if (emittedGroupReqList.includes(key)) return if (emittedGroupReqList.includes(key)) return
@ -251,11 +254,15 @@ const dispatcher = async (
case 'nodeIKernelBuddyListener/onBuddyReqChange': { case 'nodeIKernelBuddyListener/onBuddyReqChange': {
const { buddyReqs } = payload as 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 if (x.reqType !== 1 || x.reqSubType !== 1) return
const uin = ctx.chronocat.uix.getUin(x.friendUid) const uin = await ctx.chronocat.uix.getUin2(x.friendUid)
if (!uin) return if (!uin) {
ctx.chronocat.l.error('内部错误', { code: 2152 })
return
}
const key = `${uin}:${x.reqTime}` const key = `${uin}:${x.reqTime}`
if (emittedBuddyReqList.includes(key)) return if (emittedBuddyReqList.includes(key)) return

View File

@ -223,7 +223,12 @@ async function parseChatMessage(
event: Event, event: Event,
message: RedMessage, message: RedMessage,
) { ) {
const [elements, extraEvents] = await parseElements(ctx, config, message) const [elements, extraEvents] = await parseElements(
ctx,
config,
event,
message,
)
event.type = 'message-created' event.type = 'message-created'
event.message = { event.message = {
id: message.msgId, id: message.msgId,
@ -390,7 +395,7 @@ async function parsePokeMessage(
event.type = 'message-created' event.type = 'message-created'
event.message = { event.message = {
id: message.msgId, 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] return [event]
@ -402,6 +407,7 @@ async function parsePokeMessage(
async function parseElements( async function parseElements(
ctx: ChronocatContext, ctx: ChronocatContext,
config: O.Intersect<ChronocatLogCurrentConfig, ChronocatSatoriEventsConfig>, config: O.Intersect<ChronocatLogCurrentConfig, ChronocatSatoriEventsConfig>,
event: Event,
message: RedMessage, message: RedMessage,
) { ) {
const l = ctx.chronocat.l const l = ctx.chronocat.l
@ -432,7 +438,10 @@ async function parseElements(
let id: string | undefined = m.textElement!.atUid let id: string | undefined = m.textElement!.atUid
if (id === '0') id = undefined 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) const name = m.textElement!.content.slice(1)
@ -590,7 +599,7 @@ async function parseElements(
}, },
[ [
await parseAuthor(ctx, source), await parseAuthor(ctx, source),
...(await parseElements(ctx, config, source))[0], ...(await parseElements(ctx, config, event, source))[0],
], ],
), ),
) )