Merge pull request #489 from LLOneBot/dev

release: 4.1.1
This commit is contained in:
idranme 2024-10-26 00:19:15 +08:00 committed by GitHub
commit 6d036704c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 54 additions and 1661 deletions

View File

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

View File

@ -12,7 +12,7 @@
"deploy-win": "cmd /c \"xcopy /C /S /Y dist\\* %LITELOADERQQNT_PROFILE%\\plugins\\LLOneBot\\\"",
"format": "prettier -cw .",
"check": "tsc",
"compile:proto": "pbjs --no-create --no-convert --no-verify -t static-module -w es6 -p src/ntqqapi/proto -o src/ntqqapi/proto/compiled.js profileLikeTip.proto groupNotify.proto message.proto richMedia.proto && pbts -o src/ntqqapi/proto/compiled.d.ts src/ntqqapi/proto/compiled.js"
"compile:proto": "pbjs --no-create --no-convert --no-delimited --no-verify -t static-module -w es6 -p src/ntqqapi/proto -o src/ntqqapi/proto/compiled.js profileLikeTip.proto groupNotify.proto message.proto richMedia.proto && pbts -o src/ntqqapi/proto/compiled.d.ts src/ntqqapi/proto/compiled.js"
},
"author": "",
"license": "MIT",

View File

@ -185,7 +185,7 @@ function onLoad() {
if (config.enableLLOB && (config.satori.enable || config.ob11.enable)) {
startHook()
await ctx.sleep(350)
await ctx.sleep(550)
} else {
llonebotError.otherError = 'LLOneBot 未启动'
log('LLOneBot 开关设置为关闭,不启动 LLOneBot')

View File

@ -110,8 +110,9 @@ export class NTQQGroupApi extends Service {
const groupCode = flagitem[0]
const seq = flagitem[1]
const type = parseInt(flagitem[2])
const doubt = flagitem[3] === '1'
return await invoke(NTMethod.HANDLE_GROUP_REQUEST, [{
doubt: false,
doubt,
operateMsg: {
operateType,
targetMsg: {

View File

@ -153,7 +153,17 @@ export class NTQQMsgApi extends Service {
afterFirstCmd: false,
cmdCB: payload => {
for (const msgRecord of payload.msgList) {
if (msgRecord.peerUid === destPeer.peerUid && msgRecord.senderUid === selfUid) {
if (
msgRecord.msgType === 11 &&
msgRecord.subMsgType === 7 &&
msgRecord.peerUid === destPeer.peerUid &&
msgRecord.senderUid === selfUid
) {
const element = msgRecord.elements[0]
const data = JSON.parse(element.arkElement!.bytesData)
if (data.app !== 'com.tencent.multimsg' || !data.meta.detail.resid) {
continue
}
return true
}
}
@ -161,20 +171,12 @@ export class NTQQMsgApi extends Service {
}
}
)
for (const msg of data.msgList) {
const arkElement = msg.elements.find(ele => ele.arkElement)
if (!arkElement) {
continue
return data.msgList.find(msgRecord => {
const { arkElement } = msgRecord.elements[0]
if (arkElement?.bytesData.includes('com.tencent.multimsg')) {
return true
}
const forwardData = JSON.parse(arkElement.arkElement!.bytesData)
if (forwardData.app !== 'com.tencent.multimsg') {
continue
}
if (msg.peerUid === destPeer.peerUid && msg.senderUid === selfUid) {
return msg
}
}
throw new Error('转发消息超时')
})!
}
async getSingleMsg(peer: Peer, msgSeq: string) {

View File

@ -16,7 +16,7 @@ import {
BuddyReqType,
GrayTipElementSubType
} from './types'
import { selfInfo, llonebotError } from '../common/globalVars'
import { selfInfo } from '../common/globalVars'
import { version } from '../version'
import { invoke } from './ntcall'
import { Native } from './native/index'
@ -29,7 +29,7 @@ declare module 'cordis' {
'nt/message-created': (input: RawMessage) => void
'nt/message-deleted': (input: RawMessage) => void
'nt/message-sent': (input: RawMessage) => void
'nt/group-notify': (input: GroupNotify) => void
'nt/group-notify': (input: { notify: GroupNotify, doubt: boolean }) => void
'nt/friend-request': (input: FriendRequest) => void
'nt/group-member-info-updated': (input: { groupCode: string, members: GroupMember[] }) => void
'nt/system-message-created': (input: Uint8Array) => void
@ -228,7 +228,7 @@ class Core extends Service {
continue
}
groupNotifyIgnore.push(notify.seq)
this.ctx.parallel('nt/group-notify', notify)
this.ctx.parallel('nt/group-notify', { notify, doubt: payload.doubt })
}
}
})

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,7 @@ interface Payload {
interface Response {
message_id: number
forward_id?: string
forward_id: string
}
export class SendForwardMsg extends BaseAction<Payload, Response> {
@ -60,14 +60,11 @@ export class SendForwardMsg extends BaseAction<Payload, Response> {
}
}
let msg: RawMessage
if (fake && this.ctx.app.native.activated) {
msg = await this.handleFakeForwardNode(peer, nodes)
return await this.handleFakeForwardNode(peer, nodes)
} else {
msg = await this.handleForwardNode(peer, nodes)
return await this.handleForwardNode(peer, nodes)
}
const msgShortId = this.ctx.store.createMsgShortId({ chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId)
return { message_id: msgShortId }
}
private parseNodeContent(nodes: OB11MessageNode[]) {
@ -82,7 +79,7 @@ export class SendForwardMsg extends BaseAction<Payload, Response> {
})
}
private async handleFakeForwardNode(peer: Peer, nodes: OB11MessageNode[]) {
private async handleFakeForwardNode(peer: Peer, nodes: OB11MessageNode[]): Promise<Response> {
const encoder = new MessageEncoder(this.ctx, peer)
const raw = await encoder.generate(nodes)
const transmit = Msg.PbMultiMsgTransmit.encode({ pbItemList: raw.multiMsgItems }).finish()
@ -122,7 +119,11 @@ export class SendForwardMsg extends BaseAction<Payload, Response> {
})
}
}], 1800)
return msg!
const msgShortId = this.ctx.store.createMsgShortId({
chatType: msg!.chatType,
peerUid: msg!.peerUid
}, msg!.msgId)
return { message_id: msgShortId, forward_id: resid }
} catch (e) {
this.ctx.logger.error('合并转发失败', e)
throw new Error(`发送伪造合并转发消息失败 (res_id: ${resid} `)
@ -153,7 +154,7 @@ export class SendForwardMsg extends BaseAction<Payload, Response> {
}
// 返回一个合并转发的消息id
private async handleForwardNode(destPeer: Peer, messageNodes: OB11MessageNode[]) {
private async handleForwardNode(destPeer: Peer, messageNodes: OB11MessageNode[]): Promise<Response> {
const selfPeer = {
chatType: ChatType.C2C,
peerUid: selfInfo.uid,
@ -245,8 +246,13 @@ export class SendForwardMsg extends BaseAction<Payload, Response> {
if (retMsgIds.length === 0) {
throw Error('转发消息失败,节点为空')
}
const returnMsg = await this.ctx.ntMsgApi.multiForwardMsg(srcPeer!, destPeer, retMsgIds)
return returnMsg
const msg = await this.ctx.ntMsgApi.multiForwardMsg(srcPeer!, destPeer, retMsgIds)
const resid = JSON.parse(msg.elements[0].arkElement!.bytesData).meta.detail.resid
const msgShortId = this.ctx.store.createMsgShortId({
chatType: msg.chatType,
peerUid: msg.peerUid
}, msg.msgId)
return { message_id: msgShortId, forward_id: resid }
}
}

View File

@ -15,7 +15,6 @@ import { OB11Config, Config as LLOBConfig } from '../common/types'
import { OB11WebSocket, OB11WebSocketReverseManager } from './connect/ws'
import { OB11Http, OB11HttpPost } from './connect/http'
import { OB11BaseEvent } from './event/OB11BaseEvent'
import { OB11Message } from './types'
import { OB11BaseMetaEvent } from './event/meta/OB11BaseMetaEvent'
import { postHttpEvent } from './helper/eventForHttp'
import { initActionMap } from './action'
@ -88,9 +87,9 @@ class OneBot11Adapter extends Service {
}
}
private async handleGroupNotify(notify: GroupNotify) {
private async handleGroupNotify(notify: GroupNotify, doubt: boolean) {
try {
const flag = notify.group.groupCode + '|' + notify.seq + '|' + notify.type
const flag = `${notify.group.groupCode}|${notify.seq}|${notify.type}|${doubt === true ? '1' : '0'}`
if ([GroupNotifyType.MemberLeaveNotifyAdmin, GroupNotifyType.KickMemberNotifyAdmin].includes(notify.type)) {
if (notify.user2.uid) {
this.ctx.logger.info('有群成员被踢', notify.group.groupCode, notify.user1.uid, notify.user2.uid)
@ -338,7 +337,8 @@ class OneBot11Adapter extends Service {
this.handleMsg(input)
})
this.ctx.on('nt/group-notify', input => {
this.handleGroupNotify(input)
const { doubt, notify } = input
this.handleGroupNotify(notify, doubt)
})
this.ctx.on('nt/friend-request', input => {
this.handleFriendRequest(input)
@ -370,12 +370,6 @@ class OneBot11Adapter extends Service {
const userId = Number(memberUin)
const event = new OB11GroupDecreaseEvent(tip.groupCode, userId, userId)
this.dispatch(event)
} else if (msgType === 87) {
const tip = SysMsg.GroupInvite.decode(sysMsg.body!.msgContent!)
this.ctx.logger.info('群成员增加', tip)
const operatorUin = await this.ctx.ntUserApi.getUinByUid(tip.operatorUid)
const event = new OB11GroupIncreaseEvent(tip.groupCode, +selfInfo.uin, +operatorUin, 'invite')
this.dispatch(event)
}
})
}

View File

@ -520,7 +520,6 @@ export namespace OB11Entities {
ctx.logger.info('收到新人被邀请进群消息', xmlElement)
const invitor = xmlElement.templParam.get('invitor')
const invitee = xmlElement.templParam.get('invitee')
if (invitee === selfInfo.uin) return
if (invitor && invitee) {
return new OB11GroupIncreaseEvent(+msg.peerUid, +invitee, +invitor, 'invite')
}

View File

@ -174,7 +174,7 @@ export class MessageEncoder {
const { type, data } = segment
if (type === OB11MessageDataType.Node) {
await this.render(data.content as OB11MessageData[])
const id = data.id ?? data.user_id
const id = data.uin ?? data.user_id
this.uin = id ? +id : undefined
this.name = data.name ?? data.nickname
await this.flush()

View File

@ -99,7 +99,7 @@ class SatoriAdapter extends Service {
}
}
async handleGroupNotify(input: NT.GroupNotify) {
async handleGroupNotify(input: NT.GroupNotify, doubt: boolean) {
if (
input.type === NT.GroupNotifyType.InvitedByMember &&
input.status === NT.GroupNotifyStatus.Unhandle
@ -119,14 +119,14 @@ class SatoriAdapter extends Service {
input.status === NT.GroupNotifyStatus.Unhandle
) {
// 他人主动申请,需管理员同意
return await parseGuildMemberRequest(this, input)
return await parseGuildMemberRequest(this, input, doubt)
}
else if (
input.type === NT.GroupNotifyType.InvitedNeedAdminiStratorPass &&
input.status === NT.GroupNotifyStatus.Unhandle
) {
// 他人被邀请,需管理员同意
return await parseGuildMemberRequest(this, input)
return await parseGuildMemberRequest(this, input, doubt)
}
}
@ -140,7 +140,8 @@ class SatoriAdapter extends Service {
})
this.ctx.on('nt/group-notify', async input => {
const event = await this.handleGroupNotify(input)
const { doubt, notify } = input
const event = await this.handleGroupNotify(notify, doubt)
.catch(e => this.ctx.logger.error(e))
event && this.server.dispatch(event)
})

View File

@ -46,9 +46,9 @@ export async function parseGuildMemberRemoved(bot: SatoriAdapter, input: GroupNo
})
}
export async function parseGuildMemberRequest(bot: SatoriAdapter, input: GroupNotify) {
export async function parseGuildMemberRequest(bot: SatoriAdapter, input: GroupNotify, doubt: boolean) {
const groupCode = input.group.groupCode
const flag = groupCode + '|' + input.seq + '|' + input.type
const flag = `${groupCode}|${input.seq}|${input.type}|${doubt === true ? '1' : '0'}`
return bot.event('guild-member-request', {
guild: decodeGuild(input.group),

View File

@ -1 +1 @@
export const version = '4.1.0'
export const version = '4.1.1'