Refactor to more consistent structure (e.g. "plugins")

This commit is contained in:
2025-07-06 15:23:03 -04:00
parent a6255de889
commit 6fb38d36f3
22 changed files with 567 additions and 600 deletions

View File

@@ -3,32 +3,41 @@ import {Model, Sequelize, STRING} from 'sequelize';
import 'node:fs/promises';
import {readFile} from 'node:fs';
export const sql = new Sequelize('sqlite://./blitzcrank.sqlite');
export const sequelize = new Sequelize('sqlite://./blitzcrank.sqlite');
export class GuildSetting extends Model {
// Discord ID for the Guild (server)
declare guildId: string;
// Name of the option
declare key: string;
// Value being set
declare value?: string;
}
GuildSetting.init(
{
guildId: {type: STRING},
key: {type: STRING},
value: {type: STRING},
},
{sequelize: sql},
);
export async function initDb() {
export async function initializeDatabase() {
try {
await sql.authenticate();
await sequelize.authenticate();
console.log('Connected to database');
} catch (error) {
console.error('Unable to connect to the database:', error);
}
}
export async function initializeModels() {
GuildSetting.init(
{
guildId: {type: STRING},
key: {type: STRING},
value: {type: STRING},
},
{sequelize},
);
}
export async function syncModels() {
await GuildSetting.sync();
}
export async function readSettingsFromFile(path: string) {
readFile(path, async (err, data) => {
try {