mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -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,136 @@
|
||||
/**
|
||||
* @module commands/settings/setters
|
||||
* @description Value application (applySet) and
|
||||
* shortcut dispatch (handleShortcut) for the settings command. Bodies are
|
||||
* verbatim from the original single-file command.
|
||||
*/
|
||||
|
||||
|
||||
import { cleanId, getMessageGuildId } from "../../src/ui/index.mjs";
|
||||
import runnables from "../../settings/runnables.mjs";
|
||||
import {
|
||||
parseBool, displayValue, getGuildName, embed, tWrap, prettifySettingLabel,
|
||||
BOOL_SETTINGS, VALID_LOCALES, VOLUME_MIN, VOLUME_MAX, PREFIX_MAX, SHORTCUTS,
|
||||
} from "./utils.mjs";
|
||||
import {
|
||||
get247Channels, save247Channels, build247Panel, disable247, handle247Toggle,
|
||||
} from "./channels247.mjs";
|
||||
|
||||
/**
|
||||
* Apply a new value to a setting, with type-specific validation.
|
||||
* @param {object} ctx - The bot (Remix) context.
|
||||
* @param {object} message - The command message.
|
||||
* @param {ServerSettings} set - The guild settings instance.
|
||||
* @param {string} key - The setting key.
|
||||
* @param {string} rawValue - The raw string value from the command.
|
||||
* @returns {Promise<string|null>} Error message string, or null on success.
|
||||
*/
|
||||
export async function applySet(ctx, message, set, key, rawValue) {
|
||||
if (BOOL_SETTINGS.has(key)) {
|
||||
const bool = parseBool(rawValue);
|
||||
if (bool === null) {
|
||||
return ctx.t(message, "responses.settings.mustBeBool", { setting: key });
|
||||
}
|
||||
set.set(key, bool);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (key === "volume") {
|
||||
const num = parseInt(rawValue, 10);
|
||||
if (isNaN(num) || num < VOLUME_MIN || num > VOLUME_MAX) {
|
||||
return ctx.t(message, "responses.settings.volumeRange");
|
||||
}
|
||||
set.set(key, num);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (key === "locale") {
|
||||
if (!VALID_LOCALES.has(rawValue)) {
|
||||
return ctx.t(message, "responses.settings.invalidLocale", {
|
||||
locale: rawValue,
|
||||
locales: [...VALID_LOCALES].map(l => "`" + l + "`").join(", ")
|
||||
});
|
||||
}
|
||||
set.set(key, rawValue);
|
||||
const gid = getMessageGuildId(message);
|
||||
if (gid) ctx.locale.invalidateCache(gid);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (key === "prefix") {
|
||||
if (!rawValue || rawValue.length > PREFIX_MAX) {
|
||||
return ctx.t(message, "responses.settings.prefixLength");
|
||||
}
|
||||
if (/\s/.test(rawValue)) {
|
||||
return ctx.t(message, "responses.settings.prefixSpaces");
|
||||
}
|
||||
}
|
||||
|
||||
if (runnables[key]) {
|
||||
const err = runnables[key].call(ctx, rawValue, { msg: message });
|
||||
if (err) return "\u274c " + err;
|
||||
}
|
||||
|
||||
set.set(key, rawValue);
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
* @async
|
||||
* Handle a settings shortcut command (e.g. `prefix`, `247`).
|
||||
* Dispatches to 24/7 toggle, value display, or value set depending on arguments.
|
||||
* @param {object} ctx - The bot (Remix) context.
|
||||
* @param {object} message - The command message.
|
||||
* @param {string} settingKey - The resolved setting key.
|
||||
* @param {string[]} valueTokens - Remaining argument tokens after the shortcut alias.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function handleShortcut(ctx, message, settingKey, valueTokens) {
|
||||
const set = ctx.getSettings(message);
|
||||
const guildId = getMessageGuildId(message);
|
||||
const t247 = ctx.locale?.translate?.bind(ctx.locale);
|
||||
|
||||
if (valueTokens.length === 0) {
|
||||
if (settingKey === "stay_247") {
|
||||
return handle247Toggle(ctx, message, set, guildId);
|
||||
}
|
||||
const val = set.get(settingKey);
|
||||
const label = prettifySettingLabel(settingKey, t247, guildId);
|
||||
return message.reply(embed("**" + label + "**\nValue: " + displayValue(settingKey, val)));
|
||||
}
|
||||
|
||||
const rawValue = valueTokens.join(" ");
|
||||
|
||||
if (settingKey === "stay_247") {
|
||||
const mode = rawValue.toLowerCase().trim();
|
||||
if (mode === "off" || mode === "false" || mode === "disable" || mode === "0") {
|
||||
const loc = tWrap(ctx, guildId);
|
||||
if (!guildId) return message.reply(embed(loc("responses.settings.noServer")));
|
||||
const { channelId } = await ctx.players.checkVoiceChannels(message);
|
||||
if (channelId) {
|
||||
await disable247(ctx, set, guildId, channelId);
|
||||
return message.reply(build247Panel(set, ctx, guildId, cleanId(channelId)));
|
||||
}
|
||||
for (const [chId, player] of [...ctx.players.playerMap.entries()]) {
|
||||
if (cleanId(player?._guildId ?? "") === cleanId(guildId)) {
|
||||
const activeId = cleanId(player._channelId ?? chId);
|
||||
ctx.markIntentionalLeave?.(activeId);
|
||||
ctx.players.playerMap.delete(activeId);
|
||||
if (activeId !== chId) ctx.players.playerMap.delete(chId);
|
||||
await player.leave().catch(() => {});
|
||||
player.destroy();
|
||||
}
|
||||
}
|
||||
save247Channels(set, new Set());
|
||||
return message.reply(build247Panel(set, ctx, guildId, null));
|
||||
}
|
||||
return handle247Toggle(ctx, message, set, guildId);
|
||||
}
|
||||
|
||||
const err = await applySet(ctx, message, set, settingKey, rawValue);
|
||||
if (err) return message.reply(embed(err));
|
||||
|
||||
const val = set.get(settingKey);
|
||||
const label = prettifySettingLabel(settingKey, t247, guildId);
|
||||
return message.reply(embed(ctx.t(message, "responses.settings.setSuccess", { label, value: displayValue(settingKey, val) })));
|
||||
}
|
||||
Reference in new issue
Block a user