mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-13 00:10:27 +00:00
refactor: logger bind (#577)
This commit is contained in:
@@ -159,7 +159,7 @@ export class OneBotGroupApi {
|
||||
}
|
||||
const replyMsg = replyMsgList[0];
|
||||
if (!replyMsg) {
|
||||
this.core.context.logger.logError.bind(this.core.context.logger)('解析表情回应消息失败: 未找到回应消息');
|
||||
this.core.context.logger.logError('解析表情回应消息失败: 未找到回应消息');
|
||||
return undefined;
|
||||
}
|
||||
return new OB11GroupMsgEmojiLikeEvent(
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,20 +24,19 @@ export class OneBotQuickActionApi {
|
||||
}
|
||||
|
||||
async handleQuickOperation(eventContext: QuickActionEvent, quickAction: QuickAction) {
|
||||
const logger = this.core.context.logger;
|
||||
if (eventContext.post_type === 'message') {
|
||||
await this.handleMsg(eventContext as OB11Message, quickAction)
|
||||
.catch(logger.logError.bind(logger));
|
||||
.catch(e => this.core.context.logger.logError(e));
|
||||
}
|
||||
if (eventContext.post_type === 'request') {
|
||||
const friendRequest = eventContext as OB11FriendRequestEvent;
|
||||
const groupRequest = eventContext as OB11GroupRequestEvent;
|
||||
if ((friendRequest).request_type === 'friend') {
|
||||
await this.handleFriendRequest(friendRequest, quickAction)
|
||||
.catch(logger.logError.bind(logger));
|
||||
.catch(e => this.core.context.logger.logError(e));
|
||||
} else if (groupRequest.request_type === 'group') {
|
||||
await this.handleGroupRequest(groupRequest, quickAction)
|
||||
.catch(logger.logError.bind(logger));
|
||||
.catch(e => this.core.context.logger.logError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,7 +50,7 @@ export class OneBotQuickActionApi {
|
||||
group_id: msg.group_id?.toString(),
|
||||
user_id: msg.user_id?.toString(),
|
||||
}, peerContextMode);
|
||||
|
||||
|
||||
if (reply) {
|
||||
// let group: Group | undefined;
|
||||
let replyMessage: OB11MessageData[] = [];
|
||||
@@ -78,7 +77,7 @@ export class OneBotQuickActionApi {
|
||||
sendElements,
|
||||
deleteAfterSentFiles,
|
||||
} = await this.obContext.apis.MsgApi.createSendElements(replyMessage, peer);
|
||||
this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, sendElements, deleteAfterSentFiles, false).then().catch(this.core.context.logger.logError.bind(this.core.context.logger));
|
||||
this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, sendElements, deleteAfterSentFiles, false).then().catch(e => this.core.context.logger.logError(e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,13 +87,13 @@ export class OneBotQuickActionApi {
|
||||
request.flag,
|
||||
quickAction.approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
|
||||
quickAction.reason,
|
||||
).catch(this.core.context.logger.logError.bind(this.core.context.logger));
|
||||
).catch(e => this.core.context.logger.logError(e));
|
||||
}
|
||||
}
|
||||
|
||||
async handleFriendRequest(request: OB11FriendRequestEvent, quickAction: QuickActionFriendRequest) {
|
||||
if (!isNull(quickAction.approve)) {
|
||||
this.core.apis.FriendApi.handleFriendRequest(request.flag, !!quickAction.approve).then().catch(this.core.context.logger.logError.bind(this.core.context.logger));
|
||||
this.core.apis.FriendApi.handleFriendRequest(request.flag, !!quickAction.approve).then().catch(e => this.core.context.logger.logError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user