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
src
common
main
ntqqapi
onebot11
@ -108,11 +108,10 @@ export function getSelfUin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const messages: Map<string, RawMessage> = new Map()
|
const messages: Map<string, RawMessage> = new Map()
|
||||||
let expire: number
|
|
||||||
|
|
||||||
/** 缓存近期消息内容 */
|
/** 缓存近期消息内容 */
|
||||||
export async function addMsgCache(msg: RawMessage) {
|
export async function addMsgCache(msg: RawMessage) {
|
||||||
expire ??= getConfigUtil().getConfig().msgCacheExpire! * 1000
|
const expire = getConfigUtil().getConfig().msgCacheExpire! * 1000
|
||||||
if (expire === 0) {
|
if (expire === 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ export abstract class HttpServerBase {
|
|||||||
} else if (req.query) {
|
} else if (req.query) {
|
||||||
payload = { ...req.query, ...req.body }
|
payload = { ...req.query, ...req.body }
|
||||||
}
|
}
|
||||||
log('收到http请求', url, payload)
|
log('收到 HTTP 请求', url, payload)
|
||||||
try {
|
try {
|
||||||
res.send(await handler(res, payload))
|
res.send(await handler(res, payload))
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -149,7 +149,6 @@ function onLoad() {
|
|||||||
const { debug, reportSelfMessage } = getConfigUtil().getConfig()
|
const { debug, reportSelfMessage } = getConfigUtil().getConfig()
|
||||||
for (let message of msgList) {
|
for (let message of msgList) {
|
||||||
// 过滤启动之前的消息
|
// 过滤启动之前的消息
|
||||||
// log('收到新消息', message);
|
|
||||||
if (parseInt(message.msgTime) < startTime / 1000) {
|
if (parseInt(message.msgTime) < startTime / 1000) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -190,13 +189,6 @@ function onLoad() {
|
|||||||
postOb11Event(privateEvent)
|
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 // 毫秒
|
let startTime = 0 // 毫秒
|
||||||
|
|
||||||
async function start(uid: string, uin: string) {
|
async function start(uid: string, uin: string) {
|
||||||
log('llonebot pid', process.pid)
|
log('process pid', process.pid)
|
||||||
const config = getConfigUtil().getConfig()
|
const config = getConfigUtil().getConfig()
|
||||||
if (!config.enableLLOB) {
|
if (!config.enableLLOB) {
|
||||||
llonebotError.otherError = 'LLOneBot 未启动'
|
llonebotError.otherError = 'LLOneBot 未启动'
|
||||||
@ -391,7 +383,7 @@ function onLoad() {
|
|||||||
NTEventDispatch.init({ ListenerMap: wrapperConstructor, WrapperSession: getSession()! })
|
NTEventDispatch.init({ ListenerMap: wrapperConstructor, WrapperSession: getSession()! })
|
||||||
MessageUnique.init(uin)
|
MessageUnique.init(uin)
|
||||||
|
|
||||||
log('start activate group member info')
|
//log('start activate group member info')
|
||||||
// 下面两个会导致CPU占用过高,QQ卡死
|
// 下面两个会导致CPU占用过高,QQ卡死
|
||||||
// NTQQGroupApi.activateMemberInfoChange().then().catch(log)
|
// NTQQGroupApi.activateMemberInfoChange().then().catch(log)
|
||||||
// NTQQGroupApi.activateMemberListChange().then().catch(log)
|
// NTQQGroupApi.activateMemberListChange().then().catch(log)
|
||||||
|
@ -80,52 +80,41 @@ let callHooks: Array<{
|
|||||||
export function hookNTQQApiReceive(window: BrowserWindow) {
|
export function hookNTQQApiReceive(window: BrowserWindow) {
|
||||||
const originalSend = window.webContents.send
|
const originalSend = window.webContents.send
|
||||||
const patchSend = (channel: string, ...args: NTQQApiReturnData) => {
|
const patchSend = (channel: string, ...args: NTQQApiReturnData) => {
|
||||||
// console.log("hookNTQQApiReceive", channel, args)
|
/*try {
|
||||||
/*let isLogger = false
|
const isLogger = args[0]?.eventName?.startsWith('ns-LoggerApi')
|
||||||
try {
|
if (!isLogger) {
|
||||||
isLogger = args[0]?.eventName?.startsWith('ns-LoggerApi')
|
log(`received ntqq api message: ${channel}`, args)
|
||||||
} catch (e) { }
|
|
||||||
if (!isLogger) {
|
|
||||||
try {
|
|
||||||
HOOK_LOG && log(`received ntqq api message: ${channel}`, args)
|
|
||||||
} catch (e) {
|
|
||||||
log('hook log error', e, args)
|
|
||||||
}
|
}
|
||||||
}*/
|
} catch { }*/
|
||||||
try {
|
if (args?.[1] instanceof Array) {
|
||||||
if (args?.[1] instanceof Array) {
|
for (const receiveData of args?.[1]) {
|
||||||
for (let receiveData of args?.[1]) {
|
const ntQQApiMethodName = receiveData.cmdName
|
||||||
const ntQQApiMethodName = receiveData.cmdName
|
// log(`received ntqq api message: ${channel} ${ntQQApiMethodName}`, JSON.stringify(receiveData))
|
||||||
// log(`received ntqq api message: ${channel} ${ntQQApiMethodName}`, JSON.stringify(receiveData))
|
for (const hook of receiveHooks) {
|
||||||
for (let hook of receiveHooks) {
|
if (hook.method.includes(ntQQApiMethodName)) {
|
||||||
if (hook.method.includes(ntQQApiMethodName)) {
|
new Promise((resolve, reject) => {
|
||||||
new Promise((resolve, reject) => {
|
try {
|
||||||
try {
|
hook.hookFunc(receiveData.payload)
|
||||||
let _ = hook.hookFunc(receiveData.payload)
|
} catch (e: any) {
|
||||||
if (hook.hookFunc.constructor.name === 'AsyncFunction') {
|
log('hook error', ntQQApiMethodName, e.stack.toString())
|
||||||
; (_ as Promise<void>).then()
|
}
|
||||||
}
|
resolve(undefined)
|
||||||
} catch (e: any) {
|
}).then()
|
||||||
log('hook error', ntQQApiMethodName, e.stack.toString())
|
|
||||||
}
|
|
||||||
}).then()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (args[0]?.callbackId) {
|
}
|
||||||
// log("hookApiCallback", hookApiCallbacks, args)
|
if (args[0]?.callbackId) {
|
||||||
const callbackId = args[0].callbackId
|
// log("hookApiCallback", hookApiCallbacks, args)
|
||||||
if (hookApiCallbacks[callbackId]) {
|
const callbackId = args[0].callbackId
|
||||||
// log("callback found")
|
if (hookApiCallbacks[callbackId]) {
|
||||||
new Promise((resolve, reject) => {
|
// log("callback found")
|
||||||
hookApiCallbacks[callbackId](args[1])
|
new Promise((resolve, reject) => {
|
||||||
}).then()
|
hookApiCallbacks[callbackId](args[1])
|
||||||
delete hookApiCallbacks[callbackId]
|
resolve(undefined)
|
||||||
}
|
}).then()
|
||||||
|
delete hookApiCallbacks[callbackId]
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
|
||||||
log('hookNTQQApiReceive error', e.stack.toString(), args)
|
|
||||||
}
|
}
|
||||||
originalSend.call(window.webContents, channel, ...args)
|
originalSend.call(window.webContents, channel, ...args)
|
||||||
}
|
}
|
||||||
@ -395,7 +384,7 @@ export async function startHook() {
|
|||||||
}>(ReceiveCmdS.FRIENDS, (payload) => {
|
}>(ReceiveCmdS.FRIENDS, (payload) => {
|
||||||
// log("onBuddyListChange", payload)
|
// log("onBuddyListChange", payload)
|
||||||
// let friendListV2: {userSimpleInfos: Map<string, SimpleInfo>} = []
|
// let friendListV2: {userSimpleInfos: Map<string, SimpleInfo>} = []
|
||||||
type V2data = {userSimpleInfos: Map<string, SimpleInfo>}
|
type V2data = { userSimpleInfos: Map<string, SimpleInfo> }
|
||||||
let friendList: User[] = [];
|
let friendList: User[] = [];
|
||||||
if ((payload as any).userSimpleInfos) {
|
if ((payload as any).userSimpleInfos) {
|
||||||
// friendListV2 = payload as any
|
// friendListV2 = payload as any
|
||||||
@ -405,7 +394,7 @@ export async function startHook() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
for (const fData of payload.data) {
|
for (const fData of payload.data) {
|
||||||
friendList.push(...fData.buddyList)
|
friendList.push(...fData.buddyList)
|
||||||
}
|
}
|
||||||
|
@ -356,7 +356,13 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async _handle(payload: OB11PostSendMsg) {
|
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(
|
const messages = convertMessage2List(
|
||||||
payload.message,
|
payload.message,
|
||||||
payload.auto_escape === true || payload.auto_escape === 'true',
|
payload.auto_escape === true || payload.auto_escape === 'true',
|
||||||
|
@ -27,9 +27,10 @@ export function unregisterWsEventSender(ws: WebSocketClass) {
|
|||||||
|
|
||||||
export function postWsEvent(event: PostEventType) {
|
export function postWsEvent(event: PostEventType) {
|
||||||
for (const ws of eventWSList) {
|
for (const ws of eventWSList) {
|
||||||
new Promise(() => {
|
new Promise((resolve) => {
|
||||||
wsReply(ws, event)
|
wsReply(ws, event)
|
||||||
}).then().catch(log)
|
resolve(undefined)
|
||||||
|
}).then()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user