Skip to content

Commit

Permalink
fix: 消息上报
Browse files Browse the repository at this point in the history
  • Loading branch information
MliKiowa committed Nov 17, 2024
1 parent 417ef5d commit 372452f
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/onebot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,20 +543,19 @@ export class NapCatOneBot11Adapter {
}

private async emitMsg(message: RawMessage) {
const network = Object.values(this.configLoader.configData.network) as Array<AdapterConfigWrap>;
const network = Object.values(this.configLoader.configData.network).flat() as Array<AdapterConfigWrap>;
this.context.logger.logDebug('收到新消息 RawMessage', message);
try {
const ob11Msg = await this.apis.MsgApi.parseMessageV2(message);
if (!ob11Msg) return;

const isSelfMsg = this.isSelfMessage(ob11Msg);
this.context.logger.logDebug('转化为 OB11Message', ob11Msg);

const msgMap = this.createMsgMap(network, ob11Msg, isSelfMsg, message);
this.handleDebugNetwork(network, msgMap, message);
this.handleNotReportSelfNetwork(network, msgMap, isSelfMsg);
if (ob11Msg) {
const isSelfMsg = this.isSelfMessage(ob11Msg);
this.context.logger.logDebug('转化为 OB11Message', ob11Msg);
const msgMap = this.createMsgMap(network, ob11Msg, isSelfMsg, message);
this.handleDebugNetwork(network, msgMap, message);
this.handleNotReportSelfNetwork(network, msgMap, isSelfMsg);
this.networkManager.emitEventByNames(msgMap);
}

this.networkManager.emitEventByNames(msgMap);
} catch (e) {
this.context.logger.logError('constructMessage error: ', e);
}
Expand All @@ -575,7 +574,7 @@ export class NapCatOneBot11Adapter {

private createMsgMap(network: Array<AdapterConfigWrap>, ob11Msg: any, isSelfMsg: boolean, message: RawMessage): Map<string, OB11Message> {
const msgMap: Map<string, OB11Message> = new Map();
network.flat().filter(e => e.enable).forEach(e => {
network.filter(e => e.enable).forEach(e => {
if (e.messagePostFormat == 'string') {
msgMap.set(e.name, structuredClone(ob11Msg.stringMsg));
} else {
Expand All @@ -590,7 +589,7 @@ export class NapCatOneBot11Adapter {
}

private handleDebugNetwork(network: Array<AdapterConfigWrap>, msgMap: Map<string, OB11Message>, message: RawMessage) {
const debugNetwork = network.flat().filter(e => e.enable && e.debug);
const debugNetwork = network.filter(e => e.enable && e.debug);
if (debugNetwork.length > 0) {
debugNetwork.forEach(adapter => {
const msg = msgMap.get(adapter.name);
Expand All @@ -605,7 +604,7 @@ export class NapCatOneBot11Adapter {

private handleNotReportSelfNetwork(network: Array<AdapterConfigWrap>, msgMap: Map<string, OB11Message>, isSelfMsg: boolean) {
if (isSelfMsg) {
const notReportSelfNetwork = network.flat().filter(e => e.enable && (('reportSelfMessage' in e && !e.reportSelfMessage) || !('reportSelfMessage' in e)));
const notReportSelfNetwork = network.filter(e => e.enable && (('reportSelfMessage' in e && !e.reportSelfMessage) || !('reportSelfMessage' in e)));
notReportSelfNetwork.forEach(adapter => {
msgMap.delete(adapter.name);
});
Expand Down

0 comments on commit 372452f

Please sign in to comment.