chore: merge branch dev to main #200

Merged
Anri merged 19 commits from dev into main 2024-11-02 17:36:38 +01:00
3 changed files with 30 additions and 23 deletions
Showing only changes of commit a5bddd8c6f - Show all commits

13
src/sql/init.sql Normal file
View file

@ -0,0 +1,13 @@
CREATE TABLE IF NOT EXISTS
reminder (
id INTEGER PRIMARY KEY,
data TEXT,
expiration_date TEXT,
option_id INTEGER,
channel_id TEXT,
creation_date TEXT,
user_id TEXT,
guild_id TEXT,
locale TEXT,
timeout_id TEXT
);

View file

@ -5,6 +5,7 @@ import { Database } from "sqlite3";
import "../modules/client"; import "../modules/client";
import { loadLocales } from "./locales"; import { loadLocales } from "./locales";
import { YoutubeiExtractor } from "discord-player-youtubei"; import { YoutubeiExtractor } from "discord-player-youtubei";
import { readSQL } from "./db";
/** Creation of the client and definition of its properties */ /** Creation of the client and definition of its properties */
export default async (isDev: boolean) => { export default async (isDev: boolean) => {
@ -59,7 +60,7 @@ export default async (isDev: boolean) => {
client.db = new Database(`${process.env.DOCKERIZED === "1" ? "/config" : "./config"}/db.sqlite3`); client.db = new Database(`${process.env.DOCKERIZED === "1" ? "/config" : "./config"}/db.sqlite3`);
initDatabase(client.db); client.db.run(readSQL("init"));
return client; return client;
}; };
@ -75,25 +76,3 @@ export const quit = (client: Client) => {
// Close client // Close client
client.destroy(); client.destroy();
}; };
/**
* Initalize the database
* @param db Database
*/
const initDatabase = (db: Database) => {
// Table for reminders
db.run(
"CREATE TABLE IF NOT EXISTS reminder ( \
id INTEGER PRIMARY KEY, \
data TEXT, \
expiration_date TEXT, \
option_id INTEGER, \
channel_id TEXT, \
creation_date TEXT, \
user_id TEXT, \
guild_id TEXT, \
locale TEXT, \
timeout_id TEXT \
);",
);
};

15
src/utils/db.ts Normal file
View file

@ -0,0 +1,15 @@
import fs from "node:fs";
export const readSQL = (path: string) => {
const dir = "./src/sql/";
if (!path.startsWith(dir)) {
path = dir + path;
}
const ext = ".sql";
if (!path.endsWith(ext)) {
path += ext;
}
return fs.readFileSync(path, "utf8");
};