This commit is contained in:
idranme 2024-08-20 21:13:27 +08:00
parent 3b3795c946
commit c37858e2f9
No known key found for this signature in database
GPG Key ID: 926F7B5B668E495F
6 changed files with 46 additions and 59 deletions

View File

@ -108,11 +108,10 @@ export function getSelfUin() {
}
const messages: Map<string, RawMessage> = new Map()
let expire: number
/** 缓存近期消息内容 */
export async function addMsgCache(msg: RawMessage) {
expire ??= getConfigUtil().getConfig().msgCacheExpire! * 1000
const expire = getConfigUtil().getConfig().msgCacheExpire! * 1000
if (expire === 0) {
return
}

View File

@ -100,7 +100,7 @@ export abstract class HttpServerBase {
} else if (req.query) {
payload = { ...req.query, ...req.body }
}
log('收到http请求', url, payload)
log('收到 HTTP 请求', url, payload)
try {
res.send(await handler(res, payload))
} catch (e: any) {

View File

@ -149,7 +149,6 @@ function onLoad() {
const { debug, reportSelfMessage } = getConfigUtil().getConfig()
for (let message of msgList) {
// 过滤启动之前的消息
// log('收到新消息', message);
if (parseInt(message.msgTime) < startTime / 1000) {
continue
}
@ -190,13 +189,6 @@ function onLoad() {
postOb11Event(privateEvent)
}
})
// OB11Constructor.FriendAddEvent(message).then((friendAddEvent) => {
// log(message)
// if (friendAddEvent) {
// // log("post friend add event", friendAddEvent);
// postOb11Event(friendAddEvent)
// }
// })
}
}
@ -376,7 +368,7 @@ function onLoad() {
let startTime = 0 // 毫秒
async function start(uid: string, uin: string) {
log('llonebot pid', process.pid)
log('process pid', process.pid)
const config = getConfigUtil().getConfig()
if (!config.enableLLOB) {
llonebotError.otherError = 'LLOneBot 未启动'
@ -391,7 +383,7 @@ function onLoad() {
NTEventDispatch.init({ ListenerMap: wrapperConstructor, WrapperSession: getSession()! })
MessageUnique.init(uin)
log('start activate group member info')
//log('start activate group member info')
// 下面两个会导致CPU占用过高QQ卡死
// NTQQGroupApi.activateMemberInfoChange().then().catch(log)
// NTQQGroupApi.activateMemberListChange().then().catch(log)

View File

@ -80,52 +80,41 @@ let callHooks: Array<{
export function hookNTQQApiReceive(window: BrowserWindow) {
const originalSend = window.webContents.send
const patchSend = (channel: string, ...args: NTQQApiReturnData) => {
// console.log("hookNTQQApiReceive", channel, args)
/*let isLogger = false
try {
isLogger = args[0]?.eventName?.startsWith('ns-LoggerApi')
} catch (e) { }
if (!isLogger) {
try {
HOOK_LOG && log(`received ntqq api message: ${channel}`, args)
} catch (e) {
log('hook log error', e, args)
/*try {
const isLogger = args[0]?.eventName?.startsWith('ns-LoggerApi')
if (!isLogger) {
log(`received ntqq api message: ${channel}`, args)
}
}*/
try {
if (args?.[1] instanceof Array) {
for (let receiveData of args?.[1]) {
const ntQQApiMethodName = receiveData.cmdName
// log(`received ntqq api message: ${channel} ${ntQQApiMethodName}`, JSON.stringify(receiveData))
for (let hook of receiveHooks) {
if (hook.method.includes(ntQQApiMethodName)) {
new Promise((resolve, reject) => {
try {
let _ = hook.hookFunc(receiveData.payload)
if (hook.hookFunc.constructor.name === 'AsyncFunction') {
; (_ as Promise<void>).then()
}
} catch (e: any) {
log('hook error', ntQQApiMethodName, e.stack.toString())
}
}).then()
}
} catch { }*/
if (args?.[1] instanceof Array) {
for (const receiveData of args?.[1]) {
const ntQQApiMethodName = receiveData.cmdName
// log(`received ntqq api message: ${channel} ${ntQQApiMethodName}`, JSON.stringify(receiveData))
for (const hook of receiveHooks) {
if (hook.method.includes(ntQQApiMethodName)) {
new Promise((resolve, reject) => {
try {
hook.hookFunc(receiveData.payload)
} catch (e: any) {
log('hook error', ntQQApiMethodName, e.stack.toString())
}
resolve(undefined)
}).then()
}
}
}
if (args[0]?.callbackId) {
// log("hookApiCallback", hookApiCallbacks, args)
const callbackId = args[0].callbackId
if (hookApiCallbacks[callbackId]) {
// log("callback found")
new Promise((resolve, reject) => {
hookApiCallbacks[callbackId](args[1])
}).then()
delete hookApiCallbacks[callbackId]
}
}
if (args[0]?.callbackId) {
// log("hookApiCallback", hookApiCallbacks, args)
const callbackId = args[0].callbackId
if (hookApiCallbacks[callbackId]) {
// log("callback found")
new Promise((resolve, reject) => {
hookApiCallbacks[callbackId](args[1])
resolve(undefined)
}).then()
delete hookApiCallbacks[callbackId]
}
} catch (e: any) {
log('hookNTQQApiReceive error', e.stack.toString(), args)
}
originalSend.call(window.webContents, channel, ...args)
}
@ -395,7 +384,7 @@ export async function startHook() {
}>(ReceiveCmdS.FRIENDS, (payload) => {
// log("onBuddyListChange", payload)
// let friendListV2: {userSimpleInfos: Map<string, SimpleInfo>} = []
type V2data = {userSimpleInfos: Map<string, SimpleInfo>}
type V2data = { userSimpleInfos: Map<string, SimpleInfo> }
let friendList: User[] = [];
if ((payload as any).userSimpleInfos) {
// friendListV2 = payload as any
@ -405,7 +394,7 @@ export async function startHook() {
}
})
}
else{
else {
for (const fData of payload.data) {
friendList.push(...fData.buddyList)
}

View File

@ -356,7 +356,13 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
}
protected async _handle(payload: OB11PostSendMsg) {
const peer = await createContext(payload, ContextMode.Normal)
let contextMode = ContextMode.Normal
if (payload.message_type === 'group') {
contextMode = ContextMode.Group
} else if (payload.message_type === 'private') {
contextMode = ContextMode.Private
}
const peer = await createContext(payload, contextMode)
const messages = convertMessage2List(
payload.message,
payload.auto_escape === true || payload.auto_escape === 'true',

View File

@ -27,9 +27,10 @@ export function unregisterWsEventSender(ws: WebSocketClass) {
export function postWsEvent(event: PostEventType) {
for (const ws of eventWSList) {
new Promise(() => {
new Promise((resolve) => {
wsReply(ws, event)
}).then().catch(log)
resolve(undefined)
}).then()
}
}