feat: 机器人管理 — 删除、编辑配置、完整创建表单

- PUT /api/bot/:id 更新机器人配置(保存到数据库,重启生效)
- GET /api/bot/:id/config 获取保存的配置
- BotManager.updateBot/getBotConfig 方法
- Settings 页面:删除按钮(带确认)、编辑弹窗(修改所有字段)
- 创建表单:完整字段(名称、地址、端口、昵称、默认频道)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
saopig1andClaude Opus 4.6 committed 2026-03-30 20:50:49 +08:00
1 parent bc9b2366d0
commit 067a30233f
3 files changed
+250 -6

No files matched your search

+21
View File
@@ -93,6 +93,27 @@ export class BotManager {
this.logger.info({ botId: id }, "Bot instance removed");
}
updateBot(id: string, params: Partial<CreateBotParams>): void {
const instances = this.database.getBotInstances();
const existing = instances.find((i) => i.id === id);
if (!existing) throw new Error(`Bot ${id} not found`);
this.database.saveBotInstance({
...existing,
name: params.name ?? existing.name,
serverAddress: params.serverAddress ?? existing.serverAddress,
serverPort: params.serverPort ?? existing.serverPort,
nickname: params.nickname ?? existing.nickname,
defaultChannel: params.defaultChannel ?? existing.defaultChannel,
channelPassword: params.channelPassword ?? existing.channelPassword,
});
this.logger.info({ botId: id }, "Bot instance config updated (restart to apply)");
}
getBotConfig(id: string): import("../data/database.js").BotInstance | undefined {
return this.database.getBotInstances().find((i) => i.id === id);
}
getBot(id: string): BotInstance | undefined {
return this.bots.get(id);
}
+30
View File
@@ -24,6 +24,16 @@ export function createBotRouter(
res.json(bot.getStatus());
});
// Get saved config for a bot
router.get("/:id/config", (req, res) => {
const saved = botManager.getBotConfig(req.params.id);
if (!saved) {
res.status(404).json({ error: "Bot config not found" });
return;
}
res.json(saved);
});
router.post("/", async (req, res) => {
try {
const {
@@ -57,6 +67,26 @@ export function createBotRouter(
}
});
// Update bot config (must be stopped first to apply connection changes)
router.put("/:id", async (req, res) => {
try {
const bot = botManager.getBot(req.params.id);
if (!bot) {
res.status(404).json({ error: "Bot not found" });
return;
}
const { name, serverAddress, serverPort, nickname, defaultChannel, channelPassword } = req.body;
// Update in database
botManager.updateBot(req.params.id, {
name, serverAddress, serverPort, nickname, defaultChannel, channelPassword,
});
res.json({ success: true });
} catch (err) {
logger.error({ err }, "Failed to update bot");
res.status(500).json({ error: (err as Error).message });
}
});
router.delete("/:id", async (req, res) => {
try {
await botManager.removeBot(req.params.id);