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/
|
/data/
|
||||||
*.db
|
*.db
|
||||||
.env
|
.env
|
||||||
|
config.json
|
||||||
.superpowers/
|
.superpowers/
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { describe, it, expect, afterEach } from "vitest";
|
import { describe, it, expect, afterEach } from "vitest";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { mkdtempSync, rmSync } from "node:fs";
|
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { getDefaultConfig, loadConfig, saveConfig } from "./config.js";
|
import { getDefaultConfig, loadConfig, saveConfig } from "./config.js";
|
||||||
|
|
||||||
@@ -41,7 +41,6 @@ describe("config", () => {
|
|||||||
|
|
||||||
// Save a partial config by writing only some fields
|
// Save a partial config by writing only some fields
|
||||||
const partial = { webPort: 8080, locale: "en" };
|
const partial = { webPort: 8080, locale: "en" };
|
||||||
const { writeFileSync } = require("node:fs");
|
|
||||||
writeFileSync(path, JSON.stringify(partial), "utf-8");
|
writeFileSync(path, JSON.stringify(partial), "utf-8");
|
||||||
|
|
||||||
const loaded = loadConfig(path);
|
const loaded = loadConfig(path);
|
||||||
|
|||||||
+2
-2
@@ -3,8 +3,8 @@ import { dirname } from "node:path";
|
|||||||
|
|
||||||
export interface BotConfig {
|
export interface BotConfig {
|
||||||
webPort: number;
|
webPort: number;
|
||||||
locale: string;
|
locale: "zh" | "en";
|
||||||
theme: string;
|
theme: "dark" | "light";
|
||||||
commandPrefix: string;
|
commandPrefix: string;
|
||||||
commandAliases: Record<string, string>;
|
commandAliases: Record<string, string>;
|
||||||
neteaseApiPort: number;
|
neteaseApiPort: number;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
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", () => {
|
describe("database", () => {
|
||||||
let botDb: BotDatabase;
|
let botDb: BotDatabase;
|
||||||
@@ -32,7 +32,6 @@ describe("database", () => {
|
|||||||
album: "Test Album",
|
album: "Test Album",
|
||||||
platform: "netease",
|
platform: "netease",
|
||||||
coverUrl: "https://example.com/cover.jpg",
|
coverUrl: "https://example.com/cover.jpg",
|
||||||
playedAt: new Date().toISOString(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
botDb.addPlayHistory({
|
botDb.addPlayHistory({
|
||||||
@@ -43,7 +42,6 @@ describe("database", () => {
|
|||||||
album: "Another Album",
|
album: "Another Album",
|
||||||
platform: "qq",
|
platform: "qq",
|
||||||
coverUrl: "https://example.com/cover2.jpg",
|
coverUrl: "https://example.com/cover2.jpg",
|
||||||
playedAt: new Date().toISOString(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const history = botDb.getPlayHistory("bot1", 10);
|
const history = botDb.getPlayHistory("bot1", 10);
|
||||||
|
|||||||
+10
-7
@@ -1,14 +1,17 @@
|
|||||||
import Database from "better-sqlite3";
|
import Database from "better-sqlite3";
|
||||||
|
|
||||||
export interface PlayHistoryRecord {
|
export interface PlayHistoryEntry {
|
||||||
id?: number;
|
|
||||||
botId: string;
|
botId: string;
|
||||||
songId: string;
|
songId: string;
|
||||||
songName: string;
|
songName: string;
|
||||||
artist: string;
|
artist: string;
|
||||||
album: string;
|
album: string;
|
||||||
platform: string;
|
platform: "netease" | "qq";
|
||||||
coverUrl: string;
|
coverUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PlayHistoryRecord extends PlayHistoryEntry {
|
||||||
|
id: number;
|
||||||
playedAt: string;
|
playedAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +28,7 @@ export interface BotInstance {
|
|||||||
|
|
||||||
export interface BotDatabase {
|
export interface BotDatabase {
|
||||||
db: Database.Database;
|
db: Database.Database;
|
||||||
addPlayHistory(record: Omit<PlayHistoryRecord, "id">): void;
|
addPlayHistory(entry: PlayHistoryEntry): void;
|
||||||
getPlayHistory(botId: string, limit: number): PlayHistoryRecord[];
|
getPlayHistory(botId: string, limit: number): PlayHistoryRecord[];
|
||||||
saveBotInstance(instance: BotInstance): void;
|
saveBotInstance(instance: BotInstance): void;
|
||||||
getBotInstances(): BotInstance[];
|
getBotInstances(): BotInstance[];
|
||||||
@@ -44,7 +47,7 @@ function initTables(db: Database.Database): void {
|
|||||||
album TEXT NOT NULL,
|
album TEXT NOT NULL,
|
||||||
platform TEXT NOT NULL,
|
platform TEXT NOT NULL,
|
||||||
coverUrl 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 (
|
CREATE TABLE IF NOT EXISTS bot_instances (
|
||||||
@@ -66,8 +69,8 @@ export function createDatabase(dbPath: string): BotDatabase {
|
|||||||
initTables(db);
|
initTables(db);
|
||||||
|
|
||||||
const insertHistory = db.prepare(`
|
const insertHistory = db.prepare(`
|
||||||
INSERT INTO play_history (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, @playedAt)
|
VALUES (@botId, @songId, @songName, @artist, @album, @platform, @coverUrl)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
const selectHistory = db.prepare(`
|
const selectHistory = db.prepare(`
|
||||||
|
|||||||
Reference in new issue
Block a user