mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-06 21:10:23 +00:00
update: normalize log
This commit is contained in:
@@ -148,7 +148,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
//对Mgsid和OB11ID混用情况兜底
|
||||
const nodeMsg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(nodeId)) || MessageUnique.getPeerByMsgId(nodeId);
|
||||
if (!nodeMsg) {
|
||||
logger.logError('转发消息失败,未找到消息', nodeId);
|
||||
logger.logError(`转发消息失败, 未找到消息 ${nodeId}`);
|
||||
continue;
|
||||
}
|
||||
nodeMsgIds.push(nodeMsg.MsgId);
|
||||
@@ -160,7 +160,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
const isNodeMsg = OB11Data.filter(e => e.type === OB11MessageDataType.node).length;//找到子转发消息
|
||||
if (isNodeMsg !== 0) {
|
||||
if (isNodeMsg !== OB11Data.length) {
|
||||
logger.logError('子消息中包含非node消息 跳过不合法部分');
|
||||
logger.logWarn('子消息中包含非 node 消息, 跳过不合法部分');
|
||||
continue;
|
||||
}
|
||||
const nodeMsg = await this.handleForwardedNodes(selfPeer, OB11Data.filter(e => e.type === OB11MessageDataType.node));
|
||||
@@ -256,12 +256,12 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
}
|
||||
|
||||
if (sendElements.length === 0) {
|
||||
logger.logDebug('需要clone的消息无法解析,将会忽略掉', msg);
|
||||
logger.logWarn('需要 clone 的消息无法解析, 忽略: ', msg);
|
||||
}
|
||||
try {
|
||||
return await this.core.apis.MsgApi.sendMsg(selfPeer, sendElements, true);
|
||||
} catch (e) {
|
||||
logger.logError(e, '克隆转发消息失败,将忽略本条消息', msg);
|
||||
logger.logError('克隆转发消息失败, 将忽略本条消息', e, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ export class OneBotMsgApi {
|
||||
if (records.peerUin === '284840486') {
|
||||
return createReplyData(records.msgId);
|
||||
}
|
||||
let replyMsg = (await this.core.apis.MsgApi.queryMsgsWithFilterExWithSeqV2(peer, element.replayMsgSeq, element.replyMsgTime, [element.senderUidStr]))
|
||||
const replyMsg = (await this.core.apis.MsgApi.queryMsgsWithFilterExWithSeqV2(peer, element.replayMsgSeq, element.replyMsgTime, [element.senderUidStr]))
|
||||
.msgList.find(msg => msg.msgRandom === records.msgRandom);
|
||||
|
||||
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
|
||||
@@ -591,25 +591,20 @@ export class OneBotMsgApi {
|
||||
// 保留, 直到...找到更好的解决方案
|
||||
if (data.type === 'custom') {
|
||||
if (!data.url) {
|
||||
this.core.context.logger.logError('自定义音卡缺少参数url');
|
||||
return undefined;
|
||||
throw '自定义音乐卡片缺少参数 url';
|
||||
}
|
||||
if (!data.audio) {
|
||||
this.core.context.logger.logError('自定义音卡缺少参数audio');
|
||||
return undefined;
|
||||
throw '自定义音乐卡片缺少参数 audio';
|
||||
}
|
||||
if (!data.title) {
|
||||
this.core.context.logger.logError('自定义音卡缺少参数title');
|
||||
return undefined;
|
||||
throw '自定义音乐卡片缺少参数 title';
|
||||
}
|
||||
} else {
|
||||
if (!['qq', '163'].includes(data.type)) {
|
||||
this.core.context.logger.logError('音乐卡片type错误, 只支持qq、163、custom,当前type:', data.type);
|
||||
return undefined;
|
||||
throw `不支持的 type: ${data.type}`;
|
||||
}
|
||||
if (!data.id) {
|
||||
this.core.context.logger.logError('音乐卡片缺少参数id');
|
||||
return undefined;
|
||||
throw '音乐卡片缺少参数 id';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ export class NapCatOneBot11Adapter {
|
||||
selfInfo.nick = user.nick;
|
||||
this.context.logger.setLogSelfInfo(selfInfo);
|
||||
}).catch(this.context.logger.logError);
|
||||
this.context.logger.log(`[Notice] [OneBot11] ${serviceInfo}`);
|
||||
this.context.logger.log(`OneBot 服务状态: ${serviceInfo}`);
|
||||
|
||||
//创建NetWork服务
|
||||
if (ob11Config.http.enable) {
|
||||
@@ -128,7 +128,7 @@ export class NapCatOneBot11Adapter {
|
||||
await WebUiDataRuntime.setOnOB11ConfigChanged(async (newConfig: OB11Config) => {
|
||||
const prev = this.configLoader.configData;
|
||||
this.configLoader.save(newConfig);
|
||||
this.context.logger.log(`OneBot11 配置更改:${JSON.stringify(prev)} -> ${JSON.stringify(newConfig)}`);
|
||||
this.context.logger.logDebug(`OneBot11 配置更改: ${JSON.stringify(prev)} -> ${JSON.stringify(newConfig)}`);
|
||||
await this.reloadNetwork(prev, newConfig);
|
||||
});
|
||||
}
|
||||
@@ -150,7 +150,7 @@ export class NapCatOneBot11Adapter {
|
||||
HTTP上报服务 ${now.http.enablePost ? '已启动' : '未启动'}, 上报地址: ${now.http.postUrls}
|
||||
WebSocket服务 ${now.ws.enable ? '已启动' : '未启动'}, ${now.ws.host}:${now.ws.port}
|
||||
WebSocket反向服务 ${now.reverseWs.enable ? '已启动' : '未启动'}, 反向地址: ${now.reverseWs.urls}`;
|
||||
this.context.logger.log(`[Notice] [OneBot11] 热重载 ${serviceInfo}`);
|
||||
this.context.logger.log(`热重载 - OneBot 服务状态: ${serviceInfo}`);
|
||||
|
||||
// check difference in passive http (Http)
|
||||
if (prev.http.enable !== now.http.enable) {
|
||||
@@ -270,7 +270,7 @@ export class NapCatOneBot11Adapter {
|
||||
|
||||
msgListener.onInputStatusPush = async data => {
|
||||
const uin = await this.core.apis.UserApi.getUinByUidV2(data.fromUin);
|
||||
this.context.logger.log(`[Notice] [输入状态] ${uin} ${data.statusText}`);
|
||||
this.context.logger.log(`${uin} 输入状态更新: ${data.statusText}`);
|
||||
await this.networkManager.emitEvent(new OB11InputStatusEvent(
|
||||
this.core,
|
||||
parseInt(uin),
|
||||
|
||||
@@ -43,7 +43,7 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
resJson = await res.json();
|
||||
//logDebug('新消息事件HTTP上报返回快速操作: ', JSON.stringify(resJson));
|
||||
} catch (e) {
|
||||
this.logger.logDebug('[OneBot] [Http Client] 新消息事件HTTP上报没有返回快速操作,不需要处理');
|
||||
this.logger.logDebug('新消息事件 HTTP 上报没有返回快速操作,不需要处理');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -51,10 +51,10 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
.handleQuickOperation(event as QuickActionEvent, resJson)
|
||||
.catch(this.logger.logError);
|
||||
} catch (e: any) {
|
||||
this.logger.logError('[OneBot] [Http Client] 新消息事件HTTP上报返回快速操作失败', e);
|
||||
this.logger.logError('新消息事件 HTTP 上报返回快速操作失败', e);
|
||||
}
|
||||
}).catch((e) => {
|
||||
this.logger.logError('[OneBot] [Http Client] 新消息事件HTTP上报失败', e);
|
||||
this.logger.logError('新消息事件 HTTP 上报失败', e);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -85,13 +85,13 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
this.connection?.pong();
|
||||
});
|
||||
this.connection.on('pong', () => {
|
||||
//this.logger.logDebug('[OneBot] [WebSocket Client] 收到pong');
|
||||
//this.logger.logDebug('收到pong');
|
||||
});
|
||||
this.connection.on('open', () => {
|
||||
try {
|
||||
this.connectEvent(this.core);
|
||||
} catch (e) {
|
||||
this.logger.logError('[OneBot] [WebSocket Client] 发送连接生命周期失败', e);
|
||||
this.logger.logError('发送连接生命周期失败', e);
|
||||
}
|
||||
|
||||
});
|
||||
@@ -100,8 +100,8 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
});
|
||||
this.connection.once('close', () => {
|
||||
if (!isClosedByError) {
|
||||
this.logger.logError(`[OneBot] [WebSocket Client] 反向WebSocket (${this.url}) 连接意外关闭`);
|
||||
this.logger.logError(`[OneBot] [WebSocket Client] 在 ${Math.floor(this.reconnectIntervalInMillis / 1000)} 秒后尝试重新连接`);
|
||||
this.logger.logError(`反向WebSocket (${this.url}) 连接意外关闭`);
|
||||
this.logger.logError(`在 ${Math.floor(this.reconnectIntervalInMillis / 1000)} 秒后尝试重新连接`);
|
||||
if (!this.isClosed) {
|
||||
this.connection = null;
|
||||
setTimeout(() => this.tryConnect(), this.reconnectIntervalInMillis);
|
||||
@@ -110,8 +110,8 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
});
|
||||
this.connection.on('error', (err) => {
|
||||
isClosedByError = true;
|
||||
this.logger.logError(`[OneBot] [WebSocket Client] 反向WebSocket (${this.url}) 连接错误`, err);
|
||||
this.logger.logError(`[OneBot] [WebSocket Client] 在 ${Math.floor(this.reconnectIntervalInMillis / 1000)} 秒后尝试重新连接`);
|
||||
this.logger.logError(`反向WebSocket (${this.url}) 连接错误`, err);
|
||||
this.logger.logError(`在 ${Math.floor(this.reconnectIntervalInMillis / 1000)} 秒后尝试重新连接`);
|
||||
if (!this.isClosed) {
|
||||
this.connection = null;
|
||||
setTimeout(() => this.tryConnect(), this.reconnectIntervalInMillis);
|
||||
@@ -124,7 +124,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
try {
|
||||
this.checkStateAndReply<any>(new OB11LifeCycleEvent(core, LifeCycleSubType.CONNECT));
|
||||
} catch (e) {
|
||||
this.logger.logError('[OneBot] [WebSocket Client] 发送生命周期失败', e);
|
||||
this.logger.logError('发送生命周期失败', e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
try {
|
||||
receiveData = JSON.parse(message.toString());
|
||||
echo = receiveData.echo;
|
||||
this.logger.logDebug('[OneBot] [WebSocket Client] 收到正向Websocket消息', receiveData);
|
||||
this.logger.logDebug('收到正向Websocket消息', receiveData);
|
||||
} catch (e) {
|
||||
this.checkStateAndReply<any>(OB11Response.error('json解析失败,请检查数据格式', 1400, echo));
|
||||
return;
|
||||
@@ -143,8 +143,8 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
receiveData.params = (receiveData?.params) ? receiveData.params : {};//兼容类型验证
|
||||
const action = this.actions.get(receiveData.action);
|
||||
if (!action) {
|
||||
this.logger.logError('[OneBot] [WebSocket Client] 发生错误', '不支持的api ' + receiveData.action);
|
||||
this.checkStateAndReply<any>(OB11Response.error('不支持的api ' + receiveData.action, 1404, echo));
|
||||
this.logger.logError('不支持的 api' + receiveData.action);
|
||||
this.checkStateAndReply<any>(OB11Response.error('不支持的 api ' + receiveData.action, 1404, echo));
|
||||
return;
|
||||
}
|
||||
const retdata = await action.websocketHandle(receiveData.params, echo ?? '');
|
||||
|
||||
@@ -26,7 +26,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
open() {
|
||||
try {
|
||||
if (this.isOpen) {
|
||||
this.core.context.logger.logError('Cannot open a closed HTTP server');
|
||||
this.core.context.logger.logError('Http 服务已经启动');
|
||||
return;
|
||||
}
|
||||
if (!this.isOpen) {
|
||||
@@ -34,7 +34,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
this.isOpen = true;
|
||||
}
|
||||
} catch (e) {
|
||||
this.core.context.logger.logError(`[OneBot] [HTTP Server Adapter] Boot Error: ${e}`);
|
||||
this.core.context.logger.logError('Http 服务启动失败', e);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,7 +67,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
this.app.use((req, res) => this.handleRequest(req, res));
|
||||
|
||||
this.server.listen(this.port, () => {
|
||||
this.core.context.logger.log(`[OneBot] [HTTP Server Adapter] Start On Port ${this.port}`);
|
||||
this.core.context.logger.logDebug(`OneBot 11 Http 服务在 ${this.port} 上启动`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
|
||||
private async handleRequest(req: Request, res: Response) {
|
||||
if (!this.isOpen) {
|
||||
this.core.context.logger.log(`[OneBot] [HTTP Server Adapter] Server is closed`);
|
||||
this.core.context.logger.log(`OneBot 11 Http 服务已关闭`);
|
||||
return res.json(OB11Response.error('Server is closed', 200));
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
//鉴权
|
||||
this.authorize(token, wsClient, wsReq);
|
||||
this.connectEvent(core, wsClient);
|
||||
wsClient.on('error', (err) => this.logger.log('[OneBot] [WebSocket Server] Client Error:', err.message));
|
||||
wsClient.on('error', (err) => this.logger.logError('OneBot 11 WS 客户端连接异常中断', err.message));
|
||||
wsClient.on('message', (message) => {
|
||||
this.handleMessage(wsClient, message).then().catch(this.logger.logError);
|
||||
});
|
||||
@@ -68,14 +68,14 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
await this.wsClientsMutex.runExclusive(async () => {
|
||||
this.wsClients.push(wsClient);
|
||||
});
|
||||
}).on('error', (err) => this.logger.log('[OneBot] [WebSocket Server] Server Error:', err.message));
|
||||
}).on('error', (err) => this.logger.logError('OneBot 11 WS 服务端错误', err.message));
|
||||
}
|
||||
|
||||
connectEvent(core: NapCatCore, wsClient: WebSocket) {
|
||||
try {
|
||||
this.checkStateAndReply<any>(new OB11LifeCycleEvent(core, LifeCycleSubType.CONNECT), wsClient);
|
||||
} catch (e) {
|
||||
this.logger.logError('[OneBot] [WebSocket Server] 发送生命周期失败', e);
|
||||
this.logger.logError('WS 服务发送生命周期失败', e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,15 +89,13 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
|
||||
open() {
|
||||
if (this.isOpen) {
|
||||
this.logger.logError('[OneBot] [WebSocket Server] Cannot open a opened WebSocket server');
|
||||
return;
|
||||
throw 'WS 服务已经打开, 不能再次打开';
|
||||
}
|
||||
if (this.hasBeenClosed) {
|
||||
this.logger.logError('[OneBot] [WebSocket Server] Cannot open a WebSocket server that has been closed');
|
||||
return;
|
||||
throw 'WS 服务已经关闭, 不能再次打开';
|
||||
}
|
||||
const addressInfo = this.wsServer.address();
|
||||
this.logger.log('[OneBot] [WebSocket Server] Server Started', typeof (addressInfo) === 'string' ? addressInfo : addressInfo?.address + ':' + addressInfo?.port);
|
||||
this.logger.logDebug('WS 服务启动', typeof (addressInfo) === 'string' ? addressInfo : addressInfo?.address + ':' + addressInfo?.port);
|
||||
|
||||
this.isOpen = true;
|
||||
this.registerHeartBeat();
|
||||
@@ -156,7 +154,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
receiveData.params = (receiveData?.params) ? receiveData.params : {};//兼容类型验证
|
||||
const action = this.actions.get(receiveData.action);
|
||||
if (!action) {
|
||||
this.logger.logError('[OneBot] [WebSocket Client] 发生错误', '不支持的api ' + receiveData.action);
|
||||
this.logger.logError(`不支持的 api ${receiveData.action}`);
|
||||
this.checkStateAndReply<any>(OB11Response.error('不支持的api ' + receiveData.action, 1404, echo), wsClient);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user