mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-01 20:42:50 +08:00
fix: address Phase 1 review — union types, auto playedAt, ESM imports, gitignore config.json
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
9931d8b40d
commit
bc89c553b7
5 files changed
+15
-14
No files matched your search
@@ -3,4 +3,5 @@ dist/
|
||||
/data/
|
||||
*.db
|
||||
.env
|
||||
config.json
|
||||
.superpowers/
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, afterEach } from "vitest";
|
||||
import { join } from "node:path";
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { getDefaultConfig, loadConfig, saveConfig } from "./config.js";
|
||||
|
||||
@@ -41,7 +41,6 @@ describe("config", () => {
|
||||
|
||||
// Save a partial config by writing only some fields
|
||||
const partial = { webPort: 8080, locale: "en" };
|
||||
const { writeFileSync } = require("node:fs");
|
||||
writeFileSync(path, JSON.stringify(partial), "utf-8");
|
||||
|
||||
const loaded = loadConfig(path);
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@ import { dirname } from "node:path";
|
||||
|
||||
export interface BotConfig {
|
||||
webPort: number;
|
||||
locale: string;
|
||||
theme: string;
|
||||
locale: "zh" | "en";
|
||||
theme: "dark" | "light";
|
||||
commandPrefix: string;
|
||||
commandAliases: Record<string, string>;
|
||||
neteaseApiPort: number;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
||||
import { createDatabase, type BotDatabase, type BotInstance } from "./database.js";
|
||||
import { createDatabase, type BotDatabase, type BotInstance, type PlayHistoryEntry } from "./database.js";
|
||||
|
||||
describe("database", () => {
|
||||
let botDb: BotDatabase;
|
||||
@@ -32,7 +32,6 @@ describe("database", () => {
|
||||
album: "Test Album",
|
||||
platform: "netease",
|
||||
coverUrl: "https://example.com/cover.jpg",
|
||||
playedAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
botDb.addPlayHistory({
|
||||
@@ -43,7 +42,6 @@ describe("database", () => {
|
||||
album: "Another Album",
|
||||
platform: "qq",
|
||||
coverUrl: "https://example.com/cover2.jpg",
|
||||
playedAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const history = botDb.getPlayHistory("bot1", 10);
|
||||
|
||||
+10
-7
@@ -1,14 +1,17 @@
|
||||
import Database from "better-sqlite3";
|
||||
|
||||
export interface PlayHistoryRecord {
|
||||
id?: number;
|
||||
export interface PlayHistoryEntry {
|
||||
botId: string;
|
||||
songId: string;
|
||||
songName: string;
|
||||
artist: string;
|
||||
album: string;
|
||||
platform: string;
|
||||
platform: "netease" | "qq";
|
||||
coverUrl: string;
|
||||
}
|
||||
|
||||
export interface PlayHistoryRecord extends PlayHistoryEntry {
|
||||
id: number;
|
||||
playedAt: string;
|
||||
}
|
||||
|
||||
@@ -25,7 +28,7 @@ export interface BotInstance {
|
||||
|
||||
export interface BotDatabase {
|
||||
db: Database.Database;
|
||||
addPlayHistory(record: Omit<PlayHistoryRecord, "id">): void;
|
||||
addPlayHistory(entry: PlayHistoryEntry): void;
|
||||
getPlayHistory(botId: string, limit: number): PlayHistoryRecord[];
|
||||
saveBotInstance(instance: BotInstance): void;
|
||||
getBotInstances(): BotInstance[];
|
||||
@@ -44,7 +47,7 @@ function initTables(db: Database.Database): void {
|
||||
album TEXT NOT NULL,
|
||||
platform TEXT NOT NULL,
|
||||
coverUrl TEXT NOT NULL,
|
||||
playedAt TEXT NOT NULL
|
||||
playedAt TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS bot_instances (
|
||||
@@ -66,8 +69,8 @@ export function createDatabase(dbPath: string): BotDatabase {
|
||||
initTables(db);
|
||||
|
||||
const insertHistory = db.prepare(`
|
||||
INSERT INTO play_history (botId, songId, songName, artist, album, platform, coverUrl, playedAt)
|
||||
VALUES (@botId, @songId, @songName, @artist, @album, @platform, @coverUrl, @playedAt)
|
||||
INSERT INTO play_history (botId, songId, songName, artist, album, platform, coverUrl)
|
||||
VALUES (@botId, @songId, @songName, @artist, @album, @platform, @coverUrl)
|
||||
`);
|
||||
|
||||
const selectHistory = db.prepare(`
|
||||
|
||||
Reference in new issue
Block a user