mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
refactor: centralize shared utilities, fix voice intent, and improve error visibility
- extract `cleanId()` to `Utils.mjs` and remove 97+ inline `String(x).replace(/\D/g, "")` duplicates
- add `VoiceStateResolver.mjs` with `iterateVoiceStates`, `hasHumansInChannel`, `getChannelsWithHumans` — eliminates 12+ duplicated voice-state-iteration blocks across `Player`, `PlayerManager`, `GatewayHandler`, `Dashboard`
- add `UI.mjs` for shared color, emoji, and timeout constants
- move `parseInlineProvider` to `providers.mjs`, `getMessageGuildId` to `MessageHandler.mjs`
- fix `VoiceStateCache.removeGuild` and `TrackOptionsManager` cache deletion mutating Maps during iteration
- fix `checkVoiceChannels` now async returning `{channelId, alreadyInVoice, hasHumans}` — all callers updated
- fix `FluxerRevoice` global `console.log` monkey-patch replaced with scoped `withSuppressedLiveKitLogs(fn)`
- fix `Player._get247Mode()` settings resolution chain
- fix `runnables.mjs` validators were no-ops
- promote `Player` magic numbers to named static constants
- replace all silent `catch (_) {}` with `logger.warn()` throughout
- remove unused deps: `express`, `genius-lyrics`, `ws`
- add `@file` JSDoc headers to all modules
This commit is contained in:
1 parent
0d3035b093
commit
092268281a
67 files changed
+2520
-2179
No files matched your search
+29
-23
@@ -1,23 +1,23 @@
|
||||
/**
|
||||
* @file join command — Make the bot join a voice channel and initialise a player
|
||||
* @module commands/join
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
import { getGlobalColor, cleanId, getMessageGuildId } from "../src/MessageHandler.mjs";
|
||||
import { logger } from "../src/constants/Logger.mjs";
|
||||
import Player from "../src/Player.mjs";
|
||||
|
||||
function getGuildId(message) {
|
||||
return message?.channel?.guildId
|
||||
?? message?.channel?.guild?.id
|
||||
?? message?.message?.guildId
|
||||
?? message?.message?.guild?.id
|
||||
?? message?.channel?.server_id
|
||||
?? message?.channel?.serverId
|
||||
?? null;
|
||||
}
|
||||
|
||||
function cleanId(value) {
|
||||
return String(value ?? "").replace(/\D/g, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Join a voice channel, create a Player, and register event listeners.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* @param {string} cid - The voice channel ID to join
|
||||
* @param {Function} [cb] - Callback invoked with the player on success
|
||||
* @param {Function} [ecb] - Callback invoked on error
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
|
||||
const cleanChannelId = cleanId(cid);
|
||||
if (!this.client.channels.has(cleanChannelId)) {
|
||||
@@ -54,9 +54,9 @@ export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
|
||||
});
|
||||
|
||||
p.on("autoleave", () => {
|
||||
const activeChannelId = String(p._channelId ?? cid).replace(/\D/g, "") || cid;
|
||||
const homeChannelId = String(p._home247Channel ?? activeChannelId).replace(/\D/g, "") || activeChannelId;
|
||||
const guildId = getGuildId(message);
|
||||
const activeChannelId = cleanId(p._channelId ?? cid) || cid;
|
||||
const homeChannelId = cleanId(p._home247Channel ?? activeChannelId) || activeChannelId;
|
||||
const guildId = getMessageGuildId(message);
|
||||
|
||||
const is247 = (() => {
|
||||
try {
|
||||
@@ -106,13 +106,13 @@ export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
|
||||
});
|
||||
|
||||
p.on("message", m => {
|
||||
const guildId = getGuildId(message);
|
||||
const guildId = getMessageGuildId(message);
|
||||
const raw = this.settingsMgr?.getServer?.(guildId)?.get("songAnnouncements");
|
||||
const disabled = raw === false || raw === 0 ||
|
||||
["false","0","no","off","disable"].includes(String(raw).toLowerCase().trim());
|
||||
if (disabled) return;
|
||||
const embed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(m);
|
||||
message.channel.send({ embeds: [embed] });
|
||||
message.channel.send({ embeds: [embed] }).catch(() => {});
|
||||
});
|
||||
|
||||
this.players._pendingJoins.add(cleanChannelId);
|
||||
@@ -147,6 +147,12 @@ export const command = new CommandBuilder()
|
||||
.setRequired(false)
|
||||
);
|
||||
|
||||
/**
|
||||
* Execute the join command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message, data) {
|
||||
const rawArg = data?.get?.("channel")?.value?.trim?.() ?? null;
|
||||
|
||||
@@ -160,7 +166,7 @@ export async function run(message, data) {
|
||||
} else if (idMatch) {
|
||||
resolvedId = idMatch[1];
|
||||
} else {
|
||||
const guildId = cleanId(getGuildId(message));
|
||||
const guildId = cleanId(getMessageGuildId(message));
|
||||
const allChannels = [
|
||||
...(this.client?.channels?.values?.() ?? [])
|
||||
];
|
||||
@@ -182,10 +188,10 @@ export async function run(message, data) {
|
||||
return this.players.initPlayer(message, resolvedId);
|
||||
}
|
||||
|
||||
const cid = this.players.checkVoiceChannels(message);
|
||||
const { channelId: cid } = await this.players.checkVoiceChannels(message);
|
||||
|
||||
if (!cid) {
|
||||
const prefix = this.handler.getPrefix(getGuildId(message));
|
||||
const prefix = this.handler.getPrefix(getMessageGuildId(message));
|
||||
const embed = new EmbedBuilder().setColor(getGlobalColor())
|
||||
.setDescription(this.t(message, "responses.join.noVoiceChannel", { prefix }));
|
||||
return message.reply({ embeds: [embed] });
|
||||
@@ -197,4 +203,4 @@ export async function run(message, data) {
|
||||
export const exportDef = {
|
||||
name: "joinChannel",
|
||||
object: joinChannel
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user