mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
feat(guest): prune deleted bot from guest scope on removeBot
When a bot is deleted, prune its id from config.guestMode.bots (when an array) and persist, mirroring the existing permissions.pruneBot(id) member-access pruning. Thread CONFIG_PATH into BotManager so removeBot can save the updated config. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f142c514cd
commit
45414b3baa
3 files changed
+99
-3
No files matched your search
+10
-2
@@ -7,7 +7,7 @@ import {
|
||||
import type { MusicProvider } from "../music/provider.js";
|
||||
import { YouTubeProvider } from "../music/youtube.js";
|
||||
import type { BotDatabase } from "../data/database.js";
|
||||
import type { BotConfig } from "../data/config.js";
|
||||
import { saveConfig, type BotConfig } from "../data/config.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
|
||||
import type { ServerProtocol } from "../ts-protocol/client.js";
|
||||
@@ -79,6 +79,7 @@ export class BotManager extends EventEmitter {
|
||||
private logger: Logger;
|
||||
private avatarStore: AvatarStore;
|
||||
private permissions: PermissionStore;
|
||||
private configPath: string;
|
||||
|
||||
constructor(
|
||||
neteaseProvider: MusicProvider,
|
||||
@@ -88,7 +89,8 @@ export class BotManager extends EventEmitter {
|
||||
config: BotConfig,
|
||||
logger: Logger,
|
||||
avatarStore: AvatarStore,
|
||||
permissions: PermissionStore
|
||||
permissions: PermissionStore,
|
||||
configPath: string
|
||||
) {
|
||||
super();
|
||||
this.neteaseProvider = neteaseProvider;
|
||||
@@ -100,6 +102,7 @@ export class BotManager extends EventEmitter {
|
||||
this.logger = logger;
|
||||
this.avatarStore = avatarStore;
|
||||
this.permissions = permissions;
|
||||
this.configPath = configPath;
|
||||
}
|
||||
|
||||
async createBot(params: CreateBotParams): Promise<BotInstance> {
|
||||
@@ -160,6 +163,11 @@ export class BotManager extends EventEmitter {
|
||||
}
|
||||
this.database.deleteBotInstance(id);
|
||||
this.permissions.pruneBot(id);
|
||||
// Prune the deleted bot from the guest scope allow-list (mirrors permissions.pruneBot).
|
||||
if (Array.isArray(this.config.guestMode.bots) && this.config.guestMode.bots.includes(id)) {
|
||||
this.config.guestMode.bots = this.config.guestMode.bots.filter((b) => b !== id);
|
||||
saveConfig(this.configPath, this.config);
|
||||
}
|
||||
this.emit("botInstanceRemoved", id);
|
||||
this.logger.info({ botId: id }, "Bot instance removed");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user