From 366edf7843a120429ef0773706be31f739a6e1a7 Mon Sep 17 00:00:00 2001 From: saopig1 <4x7sw862st@gmail.com> Date: Thu, 7 May 2026 19:59:20 +0800 Subject: [PATCH] feat(db): custom_avatar_path column + accessors Co-Authored-By: Claude Sonnet 4.6 --- src/data/database.test.ts | 22 ++++++++++++++++++++++ src/data/database.ts | 16 ++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/data/database.test.ts b/src/data/database.test.ts index f9c4108..de49541 100644 --- a/src/data/database.test.ts +++ b/src/data/database.test.ts @@ -98,4 +98,26 @@ describe("database", () => { expect(botDb.getBotInstances()).toHaveLength(0); expect(botDb.deleteBotInstance("nonexistent")).toBe(false); }); + + it("persists and clears customAvatarPath on a bot instance", () => { + const inst = { + id: "bot-1", + name: "B", + serverAddress: "x", + serverPort: 9987, + nickname: "n", + defaultChannel: "", + channelPassword: "", + autoStart: false, + serverProtocol: "", + ts6ApiKey: "", + serverPassword: "", + }; + botDb.saveBotInstance(inst); + expect(botDb.getCustomAvatarPath("bot-1")).toBeNull(); + botDb.setCustomAvatarPath("bot-1", "avatars/bot-1.png"); + expect(botDb.getCustomAvatarPath("bot-1")).toBe("avatars/bot-1.png"); + botDb.setCustomAvatarPath("bot-1", null); + expect(botDb.getCustomAvatarPath("bot-1")).toBeNull(); + }); }); diff --git a/src/data/database.ts b/src/data/database.ts index 3ca4631..fdcdb8f 100644 --- a/src/data/database.ts +++ b/src/data/database.ts @@ -60,6 +60,8 @@ export interface BotDatabase { deleteBotInstance(id: string): boolean; getProfileConfig(botId: string): ProfileConfig; saveProfileConfig(botId: string, config: ProfileConfig): void; + getCustomAvatarPath(botId: string): string | null; + setCustomAvatarPath(botId: string, path: string | null): void; close(): void; } @@ -92,6 +94,9 @@ function migrateSchema(db: Database.Database): void { db.exec(`ALTER TABLE bot_instances ADD COLUMN ${col} INTEGER NOT NULL DEFAULT 1`); } } + if (!names.includes("custom_avatar_path")) { + db.exec("ALTER TABLE bot_instances ADD COLUMN custom_avatar_path TEXT"); + } } function initTables(db: Database.Database): void { @@ -179,6 +184,9 @@ export function createDatabase(dbPath: string): BotDatabase { WHERE id = @id `); + const selectCustomAvatar = db.prepare(`SELECT custom_avatar_path FROM bot_instances WHERE id = ?`); + const updateCustomAvatar = db.prepare(`UPDATE bot_instances SET custom_avatar_path = ? WHERE id = ?`); + return { db, @@ -242,6 +250,14 @@ export function createDatabase(dbPath: string): BotDatabase { }); }, + getCustomAvatarPath(botId) { + const row = selectCustomAvatar.get(botId) as { custom_avatar_path: string | null } | undefined; + return row?.custom_avatar_path ?? null; + }, + setCustomAvatarPath(botId, path) { + updateCustomAvatar.run(path, botId); + }, + close() { db.close(); },