mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
fix: 删除bot后重置activeBotId,编辑立即更新名称,config fetch await防空值
1. 删除活跃bot后将activeBotId置null,由fetchBots自动选新的 2. updateBot同时更新内存中的name(无需重启即可看到名称变化) 3. openEditBot改为async await config请求,失败时用bot名称做fallback Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
067a30233f
commit
4dbbaaf8f5
3 files changed
+23
-14
No files matched your search
+1
-1
@@ -43,7 +43,7 @@ export interface BotStatus {
|
|||||||
|
|
||||||
export class BotInstance extends EventEmitter {
|
export class BotInstance extends EventEmitter {
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
readonly name: string;
|
name: string;
|
||||||
|
|
||||||
private tsClient: TS3Client;
|
private tsClient: TS3Client;
|
||||||
private player: AudioPlayer;
|
private player: AudioPlayer;
|
||||||
|
|||||||
+6
-1
@@ -107,7 +107,12 @@ export class BotManager {
|
|||||||
defaultChannel: params.defaultChannel ?? existing.defaultChannel,
|
defaultChannel: params.defaultChannel ?? existing.defaultChannel,
|
||||||
channelPassword: params.channelPassword ?? existing.channelPassword,
|
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 {
|
getBotConfig(id: string): import("../data/database.js").BotInstance | undefined {
|
||||||
|
|||||||
+16
-12
@@ -562,32 +562,36 @@ async function deleteBot(botId: string, botName: string) {
|
|||||||
if (!confirm(`确认删除机器人 "${botName}"?此操作不可撤销。`)) return;
|
if (!confirm(`确认删除机器人 "${botName}"?此操作不可撤销。`)) return;
|
||||||
try {
|
try {
|
||||||
await axios.delete(`/api/bot/${botId}`);
|
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();
|
await store.fetchBots();
|
||||||
} catch {
|
} catch {
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function openEditBot(bot: any) {
|
async function openEditBot(bot: any) {
|
||||||
editingBot.value = bot.id;
|
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.name = bot.name;
|
||||||
editForm.serverAddress = '';
|
// Fetch saved config to fill all fields
|
||||||
editForm.serverPort = 9987;
|
try {
|
||||||
editForm.nickname = '';
|
const res = await axios.get(`/api/bot/${bot.id}/config`);
|
||||||
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.serverAddress = res.data.serverAddress ?? '';
|
||||||
editForm.serverPort = res.data.serverPort ?? 9987;
|
editForm.serverPort = res.data.serverPort ?? 9987;
|
||||||
editForm.nickname = res.data.nickname ?? '';
|
editForm.nickname = res.data.nickname ?? '';
|
||||||
editForm.defaultChannel = res.data.defaultChannel ?? '';
|
editForm.defaultChannel = res.data.defaultChannel ?? '';
|
||||||
editForm.channelPassword = res.data.channelPassword ?? '';
|
editForm.channelPassword = res.data.channelPassword ?? '';
|
||||||
|
} catch {
|
||||||
|
// Config not found — use defaults
|
||||||
|
editForm.serverAddress = '';
|
||||||
|
editForm.serverPort = 9987;
|
||||||
|
editForm.nickname = bot.name;
|
||||||
|
editForm.defaultChannel = '';
|
||||||
|
editForm.channelPassword = '';
|
||||||
}
|
}
|
||||||
}).catch(() => {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveEditBot() {
|
async function saveEditBot() {
|
||||||
|
|||||||
Reference in new issue
Block a user