Migration
This commit is contained in:
19
src/db/init.ts
Normal file
19
src/db/init.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import type { AppDatabase } from "./db.js";
|
||||||
|
|
||||||
|
export async function initializeSchema(db: AppDatabase): Promise<void> {
|
||||||
|
await db.exec(`
|
||||||
|
CREATE TABLE IF NOT EXISTS BotState (
|
||||||
|
key TEXT PRIMARY KEY,
|
||||||
|
value TEXT NOT NULL
|
||||||
|
);
|
||||||
|
CREATE TABLE IF NOT EXISTS TTSPreferences (
|
||||||
|
user_id TEXT PRIMARY KEY,
|
||||||
|
engine TEXT NOT NULL,
|
||||||
|
voice TEXT NOT NULL
|
||||||
|
);
|
||||||
|
CREATE TABLE IF NOT EXISTS WBWStories (
|
||||||
|
story_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
story_text TEXT NOT NULL
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ process.on("uncaughtException", (err) => {
|
|||||||
console.error("Uncaught exception:", err);
|
console.error("Uncaught exception:", err);
|
||||||
});
|
});
|
||||||
import { openDatabase } from "./db/db.js";
|
import { openDatabase } from "./db/db.js";
|
||||||
|
import { initializeSchema } from "./db/init.js";
|
||||||
import type { BotStateRow } from "./db/schema.js";
|
import type { BotStateRow } from "./db/schema.js";
|
||||||
import { loadStrings, makeT } from "./i18n/strings.js";
|
import { loadStrings, makeT } from "./i18n/strings.js";
|
||||||
import { TTSRegistry } from "./tts/registry.js";
|
import { TTSRegistry } from "./tts/registry.js";
|
||||||
@@ -32,6 +33,7 @@ client.on(Events.Error, (err) => console.error("Discord client error:", err));
|
|||||||
client.on(Events.Warn, (msg) => console.warn("Discord client warning:", msg));
|
client.on(Events.Warn, (msg) => console.warn("Discord client warning:", msg));
|
||||||
|
|
||||||
const db = await openDatabase(config.DB_FILE);
|
const db = await openDatabase(config.DB_FILE);
|
||||||
|
await initializeSchema(db);
|
||||||
const savedEngine = await db.get<BotStateRow>(
|
const savedEngine = await db.get<BotStateRow>(
|
||||||
"select value from BotState where key='announcement_engine'",
|
"select value from BotState where key='announcement_engine'",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -59,7 +59,10 @@ export const wordbyword: Module = ({ audio, commands, db, t, rootDir }) => {
|
|||||||
currentWBW.indexOf(".") === -1 ? currentWBW : currentWBW.slice(currentWBW.lastIndexOf(".") + 2);
|
currentWBW.indexOf(".") === -1 ? currentWBW : currentWBW.slice(currentWBW.lastIndexOf(".") + 2);
|
||||||
const voiceChannel = message.member?.voice.channel;
|
const voiceChannel = message.member?.voice.channel;
|
||||||
if (voiceChannel) await audio.speak(voiceChannel, toSay);
|
if (voiceChannel) await audio.speak(voiceChannel, toSay);
|
||||||
await db.run("update BotState set value=? where key='last_wbw'", [message.author.id]);
|
await db.run("insert or replace into BotState (key, value) values (?, ?)", [
|
||||||
|
"last_wbw",
|
||||||
|
message.author.id,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user