refactor: parseGroupEvent

This commit is contained in:
手瓜一十雪
2024-11-25 20:39:44 +08:00
parent 876bfbd3cb
commit 62ea4b98e1
3 changed files with 189 additions and 142 deletions

View File

@@ -527,8 +527,11 @@ export class NapCatOneBot11Adapter {
const network = Object.values(this.configLoader.configData.network).flat() as Array<AdapterConfigWrap>;
this.context.logger.logDebug('收到新消息 RawMessage', message);
await this.handleMsg(message, network);
await this.handleGroupEvent(message);
await this.handlePrivateMsgEvent(message);
if (message.chatType == ChatType.KCHATTYPEGROUP) {
await this.handleGroupEvent(message);
} else {
await this.handlePrivateMsgEvent(message);
}
}
private async handleMsg(message: RawMessage, network: Array<AdapterConfigWrap>) {
try {
@@ -597,10 +600,10 @@ export class NapCatOneBot11Adapter {
private async handleGroupEvent(message: RawMessage) {
try {
const groupEvent = await this.apis.GroupApi.parseGroupEvent(message);
if (groupEvent) {
this.networkManager.emitEvent(groupEvent);
}
const grayTipElement = message.elements.find((element) => element.grayTipElement)?.grayTipElement;
if (!grayTipElement) return;
const events = await this.apis.GroupApi.parseGrayTipElement(message, grayTipElement);
await this.networkManager.emitEvents(events);
} catch (e) {
this.context.logger.logError('constructGroupEvent error: ', e);
}