mirror of
https://github.com/chrononeko/chronocat.git
synced 2024-11-22 07:07:53 +00:00
feat: adapt uix.getUix2()
This commit is contained in:
parent
3963ab61e7
commit
91b713a5aa
10
packages/docs/docs/code/2152/index.mdx
Normal file
10
packages/docs/docs/code/2152/index.mdx
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
title: 2152:内部错误
|
||||
sidebar_position: 2152
|
||||
---
|
||||
|
||||
import { ErrorScope } from '@site/src/components/ErrorScope'
|
||||
|
||||
<ErrorScope scope="chronocat" />
|
||||
|
||||
Chronocat 内部出现了错误。这是 Chronocat 的问题。
|
@ -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,
|
||||
},
|
||||
],
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -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: '',
|
||||
})
|
||||
|
@ -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),
|
||||
},
|
||||
],
|
||||
|
@ -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: {
|
||||
|
@ -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,
|
||||
|
@ -10,6 +10,15 @@ export const commonSend = async (
|
||||
peer: Partial<Peer>,
|
||||
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 = {
|
||||
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<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
|
||||
? 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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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<ChronocatLogCurrentConfig, ChronocatSatoriEventsConfig>,
|
||||
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],
|
||||
],
|
||||
),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user