refactor: logger bind (#577)

This commit is contained in:
手瓜一十雪
2024-11-28 20:55:28 +08:00
committed by GitHub
parent 9f19ceca87
commit cd6dbd69cc
19 changed files with 109 additions and 117 deletions

View File

@@ -130,7 +130,7 @@ export class OneBotMsgApi {
},
};
} catch (e: any) {
this.core.context.logger.logError.bind(this.core.context.logger)('获取图片url失败', e.stack);
this.core.context.logger.logError('获取图片url失败', e.stack);
return null;
}
},
@@ -213,7 +213,7 @@ export class OneBotMsgApi {
guildId: '',
};
if (!records || !element.replyMsgTime || !element.senderUidStr) {
this.core.context.logger.logError.bind(this.core.context.logger)('似乎是旧版客户端,获取不到引用的消息', element.replayMsgSeq);
this.core.context.logger.logError('似乎是旧版客户端,获取不到引用的消息', element.replayMsgSeq);
return null;
}
@@ -231,7 +231,7 @@ export class OneBotMsgApi {
let replyMsg = replyMsgList.find(msg => msg.msgRandom === records.msgRandom);
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
this.core.context.logger.logError.bind(this.core.context.logger)(
this.core.context.logger.logError(
'筛选结果,筛选消息失败,将使用Fallback-1 Seq: ',
element.replayMsgSeq,
',消息长度:',
@@ -242,7 +242,7 @@ export class OneBotMsgApi {
}
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
this.core.context.logger.logWarn.bind(this.core.context.logger)(
this.core.context.logger.logWarn(
'筛选消息失败,将使用Fallback-2 Seq:',
element.replayMsgSeq,
',消息长度:',
@@ -256,7 +256,7 @@ export class OneBotMsgApi {
// 丢弃该消息段
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
this.core.context.logger.logError.bind(this.core.context.logger)(
this.core.context.logger.logError(
'最终筛选结果,筛选消息失败,获取不到引用的消息 Seq: ',
element.replayMsgSeq,
',消息长度:',
@@ -458,7 +458,7 @@ export class OneBotMsgApi {
const sysFaces = faceConfig.sysface;
const face: any = sysFaces.find((systemFace) => systemFace.QSid === parsedFaceId.toString());
if (!face) {
this.core.context.logger.logError.bind(this.core.context.logger)('不支持的ID', id);
this.core.context.logger.logError('不支持的ID', id);
return undefined;
}
parsedFaceId = parseInt(parsedFaceId.toString());
@@ -581,20 +581,20 @@ export class OneBotMsgApi {
// 保留, 直到...找到更好的解决方案
if (data.id !== undefined) {
if (!['qq', '163', 'kugou', 'kuwo', 'migu'].includes(data.type)) {
this.core.context.logger.logError.bind(this.core.context.logger)('音乐卡片type错误, 只支持qq、163、kugou、kuwo、migu当前type:', data.type);
this.core.context.logger.logError('音乐卡片type错误, 只支持qq、163、kugou、kuwo、migu当前type:', data.type);
return undefined;
}
} else {
if (!['qq', '163', 'kugou', 'kuwo', 'migu', 'custom'].includes(data.type)) {
this.core.context.logger.logError.bind(this.core.context.logger)('音乐卡片type错误, 只支持qq、163、kugou、kuwo、migu、custom当前type:', data.type);
this.core.context.logger.logError('音乐卡片type错误, 只支持qq、163、kugou、kuwo、migu、custom当前type:', data.type);
return undefined;
}
if (!data.url) {
this.core.context.logger.logError.bind(this.core.context.logger)('自定义音卡缺少参数url');
this.core.context.logger.logError('自定义音卡缺少参数url');
return undefined;
}
if (!data.image) {
this.core.context.logger.logError.bind(this.core.context.logger)('自定义音卡缺少参数image');
this.core.context.logger.logError('自定义音卡缺少参数image');
return undefined;
}
}
@@ -618,7 +618,7 @@ export class OneBotMsgApi {
type: OB11MessageDataType.json
}, context);
} catch (e) {
this.core.context.logger.logError.bind(this.core.context.logger)('生成音乐消息失败', e);
this.core.context.logger.logError('生成音乐消息失败', e);
}
},
@@ -907,7 +907,7 @@ export class OneBotMsgApi {
timeout += PredictTime;// 10S Basic Timeout + PredictTime( For File 512kb/s )
}
} catch (e) {
this.core.context.logger.logError.bind(this.core.context.logger)('发送消息计算预计时间异常', e);
this.core.context.logger.logError('发送消息计算预计时间异常', e);
}
const returnMsg = await this.core.apis.MsgApi.sendMsg(peer, sendElements, waitComplete, timeout);
if (!returnMsg) throw new Error('发送消息失败');
@@ -921,10 +921,10 @@ export class OneBotMsgApi {
deleteAfterSentFiles.forEach(file => {
try {
if (fs.existsSync(file)) {
fsPromise.unlink(file).then().catch(e => this.core.context.logger.logError.bind(this.core.context.logger)('发送消息删除文件失败', e));
fsPromise.unlink(file).then().catch(e => this.core.context.logger.logError('发送消息删除文件失败', e));
}
} catch (error) {
this.core.context.logger.logError.bind(this.core.context.logger)('发送消息删除文件失败', (error as Error).message);
this.core.context.logger.logError('发送消息删除文件失败', (error as Error).message);
}
});
}, 60000);
@@ -938,7 +938,7 @@ export class OneBotMsgApi {
) {
const realUri = inputdata.url || inputdata.file || inputdata.path || '';
if (realUri.length === 0) {
this.core.context.logger.logError.bind(this.core.context.logger)('文件消息缺少参数', inputdata);
this.core.context.logger.logError('文件消息缺少参数', inputdata);
throw Error('文件消息缺少参数');
}
const {
@@ -949,7 +949,7 @@ export class OneBotMsgApi {
} = (await uri2local(this.core.NapCatTempPath, realUri));
if (!success) {
this.core.context.logger.logError.bind(this.core.context.logger)('文件下载失败', errMsg);
this.core.context.logger.logError('文件下载失败', errMsg);
throw Error('文件下载失败' + errMsg);
}
@@ -959,14 +959,14 @@ export class OneBotMsgApi {
}
groupChangDecreseType2String(type: number): GroupDecreaseSubType {
switch (type) {
case 130:
return 'leave';
case 131:
return 'kick';
case 3:
return 'kick_me';
default:
return 'kick';
case 130:
return 'leave';
case 131:
return 'kick';
case 3:
return 'kick_me';
default:
return 'kick';
}
}