Add LFM integration to link_track

This commit is contained in:
2024-04-03 18:21:52 +02:00
parent 37515177e3
commit cb3e6df0bd
6 changed files with 166 additions and 11 deletions

39
core/db.js Normal file
View File

@@ -0,0 +1,39 @@
const fs = require("fs");
const sqlite3 = require("sqlite3").verbose();
const { open } = require('sqlite');
const filepath = "./data/minzbot.db";
async function createDbConnection() {
if (fs.existsSync(filepath)) {
//new sqlite3.Database(filepath);
const db = await open({filename: filepath, driver: sqlite3.Database});
await initDB(db);
return db;
} else {
const db = await open({filename: filepath, driver: sqlite3.Database});
await initDB(db);
console.log("[DATABASE] Connection with SQLite has been established");
return db;
}
}
async function initDB(db) {
await db.exec(`
CREATE TABLE IF NOT EXISTS anniversaries (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(50) NOT NULL,
guild_id TEXT NOT NULL,
discord_id VARCHAR(50) NOT NULL,
last_anniversary_notification TEXT
);
`);
await db.exec(`
CREATE TABLE IF NOT EXISTS lastfm (
discord_id TEXT PRIMARY KEY NOT NULL,
lastfm_name TEXT
);
`);
console.log('[DATABASE] Created new DB table');
}
module.exports = createDbConnection();