Merge pull request #390 from LLOneBot/dev

3.31.5
This commit is contained in:
idranme 2024-09-02 16:42:35 +08:00 committed by GitHub
commit ba413b9581
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 49 additions and 27 deletions

View File

@ -4,7 +4,7 @@
"name": "LLOneBot",
"slug": "LLOneBot",
"description": "实现 OneBot 11 协议,用于 QQ 机器人开发",
"version": "3.31.4",
"version": "3.31.5",
"icon": "./icon.webp",
"authors": [
{

View File

@ -19,7 +19,7 @@ declare module 'cordis' {
export class NTQQGroupApi extends Service {
static inject = ['ntWindowApi']
private groupMembers: Map<string, Map<string, GroupMember>> = new Map<string, Map<string, GroupMember>>()
public groupMembers: Map<string, Map<string, GroupMember>> = new Map<string, Map<string, GroupMember>>()
constructor(protected ctx: Context) {
super(ctx, 'ntGroupApi', true)

View File

@ -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[]) {

View File

@ -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
}

View File

@ -11,13 +11,17 @@ class DeleteMsg extends BaseAction<Payload, void> {
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])
}
}

View File

@ -48,16 +48,16 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
}
}
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<BaseCheckResult> {
@ -160,6 +160,9 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
}
}
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<OB11PostSendMsg, ReturnDataType> {
// 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, () => {
}))

View File

@ -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)
if (returnMsg) {
returnMsg.msgShortId = MessageUnique.createMsg(peer, returnMsg.msgId)
ctx.logger.info('消息发送', returnMsg.msgShortId)
deleteAfterSentFiles.map(path => fsPromise.unlink(path))
return returnMsg
}
}

View File

@ -1 +1 @@
export const version = '3.31.4'
export const version = '3.31.5'