mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
feat(db): custom_avatar_path column + accessors
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
ff5502be2f
commit
366edf7843
2 files changed
+38
No files matched your search
@@ -98,4 +98,26 @@ describe("database", () => {
|
|||||||
expect(botDb.getBotInstances()).toHaveLength(0);
|
expect(botDb.getBotInstances()).toHaveLength(0);
|
||||||
expect(botDb.deleteBotInstance("nonexistent")).toBe(false);
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -60,6 +60,8 @@ export interface BotDatabase {
|
|||||||
deleteBotInstance(id: string): boolean;
|
deleteBotInstance(id: string): boolean;
|
||||||
getProfileConfig(botId: string): ProfileConfig;
|
getProfileConfig(botId: string): ProfileConfig;
|
||||||
saveProfileConfig(botId: string, config: ProfileConfig): void;
|
saveProfileConfig(botId: string, config: ProfileConfig): void;
|
||||||
|
getCustomAvatarPath(botId: string): string | null;
|
||||||
|
setCustomAvatarPath(botId: string, path: string | null): void;
|
||||||
close(): 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`);
|
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 {
|
function initTables(db: Database.Database): void {
|
||||||
@@ -179,6 +184,9 @@ export function createDatabase(dbPath: string): BotDatabase {
|
|||||||
WHERE id = @id
|
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 {
|
return {
|
||||||
db,
|
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() {
|
close() {
|
||||||
db.close();
|
db.close();
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user