mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
opt
This commit is contained in:
parent
3b3795c946
commit
c37858e2f9
@ -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
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -80,34 +80,25 @@ 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) { }
|
||||
/*try {
|
||||
const isLogger = args[0]?.eventName?.startsWith('ns-LoggerApi')
|
||||
if (!isLogger) {
|
||||
try {
|
||||
HOOK_LOG && log(`received ntqq api message: ${channel}`, args)
|
||||
} catch (e) {
|
||||
log('hook log error', e, args)
|
||||
log(`received ntqq api message: ${channel}`, args)
|
||||
}
|
||||
}*/
|
||||
try {
|
||||
} catch { }*/
|
||||
if (args?.[1] instanceof Array) {
|
||||
for (let receiveData of args?.[1]) {
|
||||
for (const receiveData of args?.[1]) {
|
||||
const ntQQApiMethodName = receiveData.cmdName
|
||||
// log(`received ntqq api message: ${channel} ${ntQQApiMethodName}`, JSON.stringify(receiveData))
|
||||
for (let hook of receiveHooks) {
|
||||
for (const 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()
|
||||
}
|
||||
hook.hookFunc(receiveData.payload)
|
||||
} catch (e: any) {
|
||||
log('hook error', ntQQApiMethodName, e.stack.toString())
|
||||
}
|
||||
resolve(undefined)
|
||||
}).then()
|
||||
}
|
||||
}
|
||||
@ -120,13 +111,11 @@ export function hookNTQQApiReceive(window: BrowserWindow) {
|
||||
// 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)
|
||||
}
|
||||
window.webContents.send = patchSend
|
||||
@ -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)
|
||||
}
|
||||
|
@ -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',
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user