mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
Remix — the complete rewrite
Upgrades the bot from fluxerjs 2.2 to 3.0 and restructures everything into a layered architecture (~28K lines): Dependencies: - @fluxerjs/core, util, voice: ^2.2.0 -> ^3.0.0 (typed events, PartialMessage payloads, camelCase API) - @fluxerjs/sharding ^3.0.0 added — built-in sharding mode (shard.mjs, one process per shard) - @discordjs/opus dropped — opusscript + prism-media cover encoding Architecture: - commands: every command split into submodules (player, lastfm, settings, debug) with a shared CommandBuilder/Loader/Handler core - ui: embeds, paginators, help command, permission checks - voice: gateway event routing, rejoin/247 boot recovery, state resolver - music: player split into Queue/Search/Playback/Display mixins, stream pipeline + WebM/Opus muxer (no FFmpeg needed) - dashboard: Redis pub/sub, RPC handlers, serializers - db: MySQL manager + per-guild settings - services: LastFm manager split into focused mixins - utils: sharding, 24/7 helpers, API client Runtime fixes over v2: - Redis v5 reconnect: capped numeric backoff (0.5s ramp to 15s), never exhausts, auto-recovers when the server comes back - Redis main/subscriber clients connect in parallel; clean shutdown - Logger storm guard: identical error/warn lines deduped in a 60s window - self-deaf fix on voice join - config example uses redis://127.0.0.1 (avoids IPv6 ENETUNREACH) Housekeeping: dead code removed (Tuna.mjs + follow-redirects dep), .gitignore added (config.json, .env, node_modules, runtime state).
This commit is contained in:
1 parent
0f085a6ae4
commit
253d11cd57
150 files changed
+19935
-16894
No files matched your search
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* @module src/db/DatabaseManager
|
||||
* @description MySQL connection pool wrapper for the dashboard. Provides parameterised
|
||||
* query execution and bcrypt hashing utilities for login code management.
|
||||
*/
|
||||
|
||||
import { compare, genSalt, hash } from "bcryptjs";
|
||||
import { createPool } from "mysql2/promise";
|
||||
import { logger } from "../core/Logger.mjs";
|
||||
|
||||
/**
|
||||
* @class
|
||||
* @description Wraps a mysql2 connection pool with convenience methods for
|
||||
* parameterised queries and bcrypt hash operations.
|
||||
*/
|
||||
export class DatabaseManager {
|
||||
/**
|
||||
* Create a new DatabaseManager.
|
||||
* @param {object} config - mysql2 pool configuration (host, user, password, database, etc.).
|
||||
*/
|
||||
constructor(config) {
|
||||
this.db = createPool({
|
||||
connectionLimit: 15,
|
||||
...config,
|
||||
});
|
||||
this.db.on("error", (err) => {
|
||||
logger.error("[DashboardDB] MySQL pool error:", err.code ?? err.message);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a raw SQL query (no parameter binding).
|
||||
* @async
|
||||
* @param {string} query - The SQL query string.
|
||||
* @returns {Promise<Array>} The query result rows and fields.
|
||||
*/
|
||||
async query(query) {
|
||||
return this.db.query(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a parameterised SQL query.
|
||||
* @async
|
||||
* @param {string} query - The SQL query with `?` placeholders.
|
||||
* @param {Array} data - The values to bind.
|
||||
* @returns {Promise<Array>} The result rows.
|
||||
*/
|
||||
async execute(query, data) {
|
||||
const [res, _fields] = await this.db.execute(query, data);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a bcrypt hash of the given plaintext.
|
||||
* @async
|
||||
* @param {string} plain - The plaintext string.
|
||||
* @returns {Promise<string>} The hashed string.
|
||||
*/
|
||||
async hash(plain) {
|
||||
const salt = await genSalt(10);
|
||||
return hash(plain, salt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare a plaintext string against a bcrypt hash.
|
||||
* @async
|
||||
* @param {string} plain - The plaintext string.
|
||||
* @param {string} hashed - The bcrypt hash.
|
||||
* @returns {Promise<boolean>} True if the plaintext matches the hash.
|
||||
*/
|
||||
async compareHash(plain, hashed) {
|
||||
return await compare(plain, hashed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the underlying MySQL connection pool.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
close() {
|
||||
return this.db.end();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user