diff --git a/manifest.json b/manifest.json index ccf4812..33896bd 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "name": "LLOneBot", "slug": "LLOneBot", "description": "实现 OneBot 11 协议,用于 QQ 机器人开发", - "version": "3.31.4", + "version": "3.31.5", "icon": "./icon.webp", "authors": [ { diff --git a/src/ntqqapi/api/group.ts b/src/ntqqapi/api/group.ts index 04e029e..e9a8b2a 100644 --- a/src/ntqqapi/api/group.ts +++ b/src/ntqqapi/api/group.ts @@ -19,7 +19,7 @@ declare module 'cordis' { export class NTQQGroupApi extends Service { static inject = ['ntWindowApi'] - private groupMembers: Map> = new Map>() + public groupMembers: Map> = new Map>() constructor(protected ctx: Context) { super(ctx, 'ntGroupApi', true) diff --git a/src/ntqqapi/api/msg.ts b/src/ntqqapi/api/msg.ts index b6d66ed..33bcbba 100644 --- a/src/ntqqapi/api/msg.ts +++ b/src/ntqqapi/api/msg.ts @@ -153,12 +153,7 @@ export class NTQQMsgApi extends Service { ) msgList = data.msgList } - const retMsg = msgList.find(msgRecord => { - if (msgRecord.guildId === msgId) { - return true - } - }) - return retMsg! + return msgList.find(msgRecord => msgRecord.guildId === msgId) } async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) { diff --git a/src/ntqqapi/api/user.ts b/src/ntqqapi/api/user.ts index fdafa66..5023b8f 100644 --- a/src/ntqqapi/api/user.ts +++ b/src/ntqqapi/api/user.ts @@ -3,7 +3,7 @@ import { User, UserDetailInfoByUin, UserDetailInfoByUinV2, UserDetailInfoListene import { getBuildVersion } from '@/common/utils' import { getSession } from '@/ntqqapi/wrapper' import { RequestUtil } from '@/common/utils/request' -import { NodeIKernelProfileService, UserDetailSource, ProfileBizType, forceFetchClientKeyRetType } from '../services' +import { NodeIKernelProfileService, UserDetailSource, ProfileBizType } from '../services' import { NodeIKernelProfileListener } from '../listeners' import { NTEventDispatch } from '@/common/utils/eventTask' import { Time } from 'cosmokit' @@ -17,7 +17,7 @@ declare module 'cordis' { } export class NTQQUserApi extends Service { - static inject = ['ntFriendApi'] + static inject = ['ntFriendApi', 'ntGroupApi'] constructor(protected ctx: Context) { super(ctx, 'ntUserApi', true) @@ -192,11 +192,26 @@ export class NTQQUserApi extends Service { // 通用转换开始尝试 let uid = (await session?.getUixConvertService().getUid([uin]))?.uidInfo.get(uin) if (!uid) { - let unveifyUid = (await this.getUserDetailInfoByUin(uin)).info.uid //从QQ Native 特殊转换 方法三 - if (unveifyUid.indexOf('*') == -1) { + for (const membersList of this.ctx.ntGroupApi.groupMembers.values()) { //从群友列表转 + for (const member of membersList.values()) { + if (member.uin === uin) { + uid = member.uid + break + } + } + if (uid) break + } + } + if (!uid) { + const unveifyUid = (await this.getUserDetailInfoByUin(uin)).info.uid //特殊转换 + if (unveifyUid.indexOf('*') === -1) { uid = unveifyUid } } + if (!uid) { + const friends = await this.ctx.ntFriendApi.getFriends() //从好友列表转 + uid = friends.find(item => item.uin === uin)?.uid + } return uid } diff --git a/src/onebot11/action/msg/DeleteMsg.ts b/src/onebot11/action/msg/DeleteMsg.ts index 6354e07..df01185 100644 --- a/src/onebot11/action/msg/DeleteMsg.ts +++ b/src/onebot11/action/msg/DeleteMsg.ts @@ -11,13 +11,17 @@ class DeleteMsg extends BaseAction { protected async _handle(payload: Payload) { if (!payload.message_id) { - throw Error('message_id不能为空') + throw new Error('参数message_id不能为空') } const msg = await MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id) if (!msg) { - throw `消息${payload.message_id}不存在` + throw new Error(`消息${payload.message_id}不存在`) + } + const data = await this.ctx.ntMsgApi.recallMsg(msg.Peer, [msg.MsgId]) + if (data.result !== 0) { + this.ctx.logger.error('delete_msg', payload.message_id, data) + throw new Error(`消息撤回失败`) } - await this.ctx.ntMsgApi.recallMsg(msg.Peer, [msg.MsgId]) } } diff --git a/src/onebot11/action/msg/SendMsg.ts b/src/onebot11/action/msg/SendMsg.ts index adc0722..87509e7 100644 --- a/src/onebot11/action/msg/SendMsg.ts +++ b/src/onebot11/action/msg/SendMsg.ts @@ -48,16 +48,16 @@ export class SendMsg extends BaseAction { } } if ((contextMode === ContextMode.Private || contextMode === ContextMode.Normal) && payload.user_id) { - const Uid = await this.ctx.ntUserApi.getUidByUin(payload.user_id.toString()) - const isBuddy = await this.ctx.ntFriendApi.isBuddy(Uid!) - //console.log("[调试代码] UIN:", payload.user_id, " UID:", Uid, " IsBuddy:", isBuddy) + const uid = await this.ctx.ntUserApi.getUidByUin(payload.user_id.toString()) + if (!uid) throw new Error('无法获取用户信息') + const isBuddy = await this.ctx.ntFriendApi.isBuddy(uid) return { chatType: isBuddy ? ChatType.friend : ChatType.temp, - peerUid: Uid!, - guildId: payload.group_id?.toString() || '' //临时主动发起时需要传入群号 + peerUid: uid, + guildId: isBuddy ? '' : payload.group_id?.toString() || '' } } - throw '请指定 group_id 或 user_id' + throw new Error('请指定 group_id 或 user_id') } protected async check(payload: OB11PostSendMsg): Promise { @@ -160,6 +160,9 @@ export class SendMsg extends BaseAction { } } const returnMsg = await sendMsg(this.ctx, peer, sendElements, deleteAfterSentFiles) + if (!returnMsg) { + throw new Error('消息发送失败') + } return { message_id: returnMsg.msgShortId! } } @@ -251,9 +254,12 @@ export class SendMsg extends BaseAction { // log("分割后的转发节点", sendElementsSplit) for (const eles of sendElementsSplit) { const nodeMsg = await sendMsg(this.ctx, selfPeer, eles, [], true) + if (!nodeMsg) { + this.ctx.logger.warn('转发节点生成失败', eles) + continue + } nodeMsgIds.push(nodeMsg.msgId) await this.ctx.sleep(400) - this.ctx.logger.info('转发节点生成成功', nodeMsg.msgId) } deleteAfterSentFiles.map((f) => fs.unlink(f, () => { })) diff --git a/src/onebot11/helper/createMessage.ts b/src/onebot11/helper/createMessage.ts index 3ea20c1..a96cf8a 100644 --- a/src/onebot11/helper/createMessage.ts +++ b/src/onebot11/helper/createMessage.ts @@ -270,8 +270,10 @@ export async function sendMsg( const timeout = 10000 + (totalSize / 1024 / 256 * 1000) // 10s Basic Timeout + PredictTime( For File 512kb/s ) //log('设置消息超时时间', timeout) const returnMsg = await ctx.ntMsgApi.sendMsg(peer, sendElements, waitComplete, timeout) - returnMsg.msgShortId = MessageUnique.createMsg(peer, returnMsg.msgId) - ctx.logger.info('消息发送', returnMsg.msgShortId) - deleteAfterSentFiles.map(path => fsPromise.unlink(path)) - return returnMsg + if (returnMsg) { + returnMsg.msgShortId = MessageUnique.createMsg(peer, returnMsg.msgId) + ctx.logger.info('消息发送', returnMsg.msgShortId) + deleteAfterSentFiles.map(path => fsPromise.unlink(path)) + return returnMsg + } } \ No newline at end of file diff --git a/src/version.ts b/src/version.ts index 4216824..53bdf68 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const version = '3.31.4' +export const version = '3.31.5'