diff --git a/src/bot/instance.ts b/src/bot/instance.ts index e2c8392..69921ad 100644 --- a/src/bot/instance.ts +++ b/src/bot/instance.ts @@ -43,7 +43,7 @@ export interface BotStatus { export class BotInstance extends EventEmitter { readonly id: string; - readonly name: string; + name: string; private tsClient: TS3Client; private player: AudioPlayer; diff --git a/src/bot/manager.ts b/src/bot/manager.ts index 052100b..9488a88 100644 --- a/src/bot/manager.ts +++ b/src/bot/manager.ts @@ -107,7 +107,12 @@ export class BotManager { defaultChannel: params.defaultChannel ?? existing.defaultChannel, channelPassword: params.channelPassword ?? existing.channelPassword, }); - this.logger.info({ botId: id }, "Bot instance config updated (restart to apply)"); + // Update in-memory name immediately (other fields need reconnect) + const bot = this.bots.get(id); + if (bot && params.name) { + bot.name = params.name; + } + this.logger.info({ botId: id }, "Bot instance config updated (connection changes need restart)"); } getBotConfig(id: string): import("../data/database.js").BotInstance | undefined { diff --git a/web/src/views/Settings.vue b/web/src/views/Settings.vue index ce2d82c..f6759a1 100644 --- a/web/src/views/Settings.vue +++ b/web/src/views/Settings.vue @@ -562,32 +562,36 @@ async function deleteBot(botId: string, botName: string) { if (!confirm(`确认删除机器人 "${botName}"?此操作不可撤销。`)) return; try { await axios.delete(`/api/bot/${botId}`); + // If deleted bot was the active one, reset activeBotId + if (store.activeBotId === botId) { + store.activeBotId = null; + } + store.removeBotStatus(botId); await store.fetchBots(); } catch { // Ignore } } -function openEditBot(bot: any) { +async function openEditBot(bot: any) { editingBot.value = bot.id; - // We need to fetch the saved config from server - // For now use the status info we have editForm.name = bot.name; - editForm.serverAddress = ''; - editForm.serverPort = 9987; - editForm.nickname = ''; - editForm.defaultChannel = ''; - editForm.channelPassword = ''; - // Try to get saved config - axios.get(`/api/bot/${bot.id}/config`).then(res => { - if (res.data) { - editForm.serverAddress = res.data.serverAddress ?? ''; - editForm.serverPort = res.data.serverPort ?? 9987; - editForm.nickname = res.data.nickname ?? ''; - editForm.defaultChannel = res.data.defaultChannel ?? ''; - editForm.channelPassword = res.data.channelPassword ?? ''; - } - }).catch(() => {}); + // Fetch saved config to fill all fields + try { + const res = await axios.get(`/api/bot/${bot.id}/config`); + editForm.serverAddress = res.data.serverAddress ?? ''; + editForm.serverPort = res.data.serverPort ?? 9987; + editForm.nickname = res.data.nickname ?? ''; + editForm.defaultChannel = res.data.defaultChannel ?? ''; + editForm.channelPassword = res.data.channelPassword ?? ''; + } catch { + // Config not found — use defaults + editForm.serverAddress = ''; + editForm.serverPort = 9987; + editForm.nickname = bot.name; + editForm.defaultChannel = ''; + editForm.channelPassword = ''; + } } async function saveEditBot() {