Skip to content

Commit

Permalink
fix: 删除的移除
Browse files Browse the repository at this point in the history
  • Loading branch information
MliKiowa committed Nov 25, 2024
1 parent 86cbdf7 commit 93904dc
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/onebot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,20 @@ export class NapCatOneBot11Adapter {
const newLog = await this.creatOneBotLog(now);
this.context.logger.log(`[Notice] [OneBot11] 配置变更前:\n${prevLog}`);
this.context.logger.log(`[Notice] [OneBot11] 配置变更后:\n${newLog}`);
await this.handleConfigChange(now.network.httpServers, OB11PassiveHttpAdapter);
await this.handleConfigChange(now.network.httpClients, OB11ActiveHttpAdapter);
await this.handleConfigChange(now.network.websocketServers, OB11PassiveWebSocketAdapter);
await this.handleConfigChange(now.network.websocketClients, OB11ActiveWebSocketAdapter);

await this.handleConfigChange(prev.network.httpServers, now.network.httpServers, OB11PassiveHttpAdapter);
await this.handleConfigChange(prev.network.httpClients, now.network.httpClients, OB11ActiveHttpAdapter);
await this.handleConfigChange(prev.network.websocketServers, now.network.websocketServers, OB11PassiveWebSocketAdapter);
await this.handleConfigChange(prev.network.websocketClients, now.network.websocketClients, OB11ActiveWebSocketAdapter);
}

private async handleConfigChange(adapters: NetworkConfigAdapter[], adapterClass: new (...args: any[]) => IOB11NetworkAdapter): Promise<void> {
for (const adapterConfig of adapters) {

private async handleConfigChange(
prevConfig: NetworkConfigAdapter[],
nowConfig: NetworkConfigAdapter[],
adapterClass: new (...args: any[]) => IOB11NetworkAdapter
): Promise<void> {
// 通知新配置重载 删除关闭的 加入新开的
for (const adapterConfig of nowConfig) {
const existingAdapter = this.networkManager.findSomeAdapter(adapterConfig.name);
if (existingAdapter) {
const networkChange = await existingAdapter.reload(adapterConfig);
Expand All @@ -201,6 +206,16 @@ export class NapCatOneBot11Adapter {
await this.networkManager.registerAdapterAndOpen(newAdapter);
}
}
// 比较旧的找不到的回收
for (const adapterConfig of prevConfig) {
const existingAdapter = nowConfig.find((e) => e.name === adapterConfig.name);
if (!existingAdapter) {
const existingAdapter = this.networkManager.findSomeAdapter(adapterConfig.name);
if (existingAdapter) {
await this.networkManager.closeSomeAdaterWhenOpen([existingAdapter]);
}
}
}
}

private initMsgListener() {
Expand Down

0 comments on commit 93904dc

Please sign in to comment.