mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
Merge PR #121: show requester names in play history
Merges feature/play-history-requester (@Fa1nttt) into main. The PR records the WebUI/TeamSpeak requester on queued songs and persists it to play history (schema migration for requestedBy), rendering it as a badge in SongCard (gray for 游客/guest). Conflicts (frontend platform union) resolved to keep both 'spotify' (from #118) and the new requestedBy/playedAt fields. Integration fix: the Spotify playback branch in resolveAndPlay (added by #118, which did not exist on the PR's base) also records play history — added `requestedBy: song.requestedBy` there so Spotify tracks carry attribution too, matching the non-Spotify path. Verified on the merged tree: tsc --noEmit clean, full suite 1309/1309, web build clean. Co-Authored-By: Fa1nttt <noreply@github.com> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
commit
b9767a7471
7 files changed
+102
-39
No files matched your search
+11
-3
@@ -10,6 +10,7 @@ export interface PlayHistoryEntry {
|
||||
album: string;
|
||||
platform: "netease" | "qq" | "bilibili" | "youtube" | "local" | "kugou" | "spotify";
|
||||
coverUrl: string;
|
||||
requestedBy?: string;
|
||||
}
|
||||
|
||||
export interface PlayHistoryRecord extends PlayHistoryEntry {
|
||||
@@ -124,6 +125,12 @@ function migrateSchema(db: Database.Database): void {
|
||||
if (!userColNames.includes("role")) {
|
||||
db.exec("ALTER TABLE users ADD COLUMN role TEXT NOT NULL DEFAULT 'admin'");
|
||||
}
|
||||
|
||||
const historyColumns = db.prepare("PRAGMA table_info(play_history)").all() as Array<{ name: string }>;
|
||||
const historyColNames = historyColumns.map((c) => c.name);
|
||||
if (!historyColNames.includes("requestedBy")) {
|
||||
db.exec("ALTER TABLE play_history ADD COLUMN requestedBy TEXT NOT NULL DEFAULT ''");
|
||||
}
|
||||
}
|
||||
|
||||
function initTables(db: Database.Database): void {
|
||||
@@ -137,6 +144,7 @@ function initTables(db: Database.Database): void {
|
||||
album TEXT NOT NULL,
|
||||
platform TEXT NOT NULL,
|
||||
coverUrl TEXT NOT NULL,
|
||||
requestedBy TEXT NOT NULL DEFAULT '',
|
||||
playedAt TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
@@ -265,8 +273,8 @@ export function createDatabase(dbPath: string): BotDatabase {
|
||||
ensureGuestUser(db);
|
||||
|
||||
const insertHistory = db.prepare(`
|
||||
INSERT INTO play_history (botId, songId, songName, artist, album, platform, coverUrl)
|
||||
VALUES (@botId, @songId, @songName, @artist, @album, @platform, @coverUrl)
|
||||
INSERT INTO play_history (botId, songId, songName, artist, album, platform, coverUrl, requestedBy)
|
||||
VALUES (@botId, @songId, @songName, @artist, @album, @platform, @coverUrl, @requestedBy)
|
||||
`);
|
||||
|
||||
const selectHistory = db.prepare(`
|
||||
@@ -338,7 +346,7 @@ export function createDatabase(dbPath: string): BotDatabase {
|
||||
db,
|
||||
|
||||
addPlayHistory(record) {
|
||||
insertHistory.run(record);
|
||||
insertHistory.run({ ...record, requestedBy: record.requestedBy ?? "" });
|
||||
},
|
||||
|
||||
getPlayHistory(botId, limit) {
|
||||
|
||||
Reference in new issue
Block a user