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:
NoLogicAlan committed 2026-06-15 16:56:10 +03:00
1 parent 0d3035b093
commit 092268281a
67 files changed
+2520 -2179

No files matched your search

+24 -21
View File
@@ -1,16 +1,22 @@
/**
* @file play.mjs — Play a song, playlist, or Last.fm URL — the main music command with provider selection
* @module commands.play
*/
import { CommandBuilder } from "../src/CommandHandler.mjs";
import { EmbedBuilder } from "@fluxerjs/core";
import { getGlobalColor } from "../src/MessageHandler.mjs";
import { PROVIDER_CHOICES } from "../src/constants/providers.mjs";
import { PROVIDER_CHOICES, parseInlineProvider } from "../src/constants/providers.mjs";
import { playLastFmCategory } from "./lastfm.mjs";
import { ERROR_COLOR } from "../src/constants/UI.mjs";
/**
* Parse a Last.fm music URL and extract artist and track info.
* Supports:
* https:
* https:
* https:
* https:
* https://www.last.fm/music/Artist
* https://www.last.fm/music/Artist/Track
* https://www.last.fm/music/Artist/Album/Track
* https://www.last.fm/music/Artist/_/Track
*
* @param {string} url
* @returns {{ artist: string, track: string|null, album: string|null, url: string } | null}
@@ -106,15 +112,6 @@ function parseLastFmSubProvider(query) {
return { category: lower, resolveProvider: null };
}
function parseInlineProvider(raw) {
const match = raw.match(/^([a-z]+):\s*(.+)$/i);
if (!match) return { provider: null, query: raw.trim() };
const maybeProvider = match[1].toLowerCase();
if (PROVIDER_CHOICES.includes(maybeProvider)) {
return { provider: maybeProvider, query: match[2].trim() };
}
return { provider: null, query: raw.trim() };
}
function parseLastFmTrackQuery(raw) {
const value = String(raw ?? "").trim();
@@ -179,6 +176,12 @@ export const command = new CommandBuilder()
, true)
.addAlias("p");
/**
* Execute the play 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 rawQuery = data.get("query").value;
const flagProvider = data.get("provider")?.value;
@@ -204,7 +207,7 @@ export async function run(message, data) {
.setColor(getGlobalColor())
.setDescription(this.t(message, "responses.play.searching"));
let statusMsg = null;
try { statusMsg = await message.reply({ embeds: [searchEmbed] }); } catch {}
try { statusMsg = await message.reply({ embeds: [searchEmbed] }); } catch(e) { }
const playQuery = `${parsed.track} ${parsed.artist}`.trim();
const messages = p.play(playQuery, false, provider === "lastfm" || provider === "lf" ? "yt" : provider, lastfmTrackMeta);
@@ -224,7 +227,7 @@ export async function run(message, data) {
.setColor(getGlobalColor())
.setDescription(this.t(message, "responses.play.searching"));
let statusMsg = null;
try { statusMsg = await message.reply({ embeds: [searchEmbed] }); } catch {}
try { statusMsg = await message.reply({ embeds: [searchEmbed] }); } catch(e) { }
const playQuery = parsed.artist;
const messages = p.play(playQuery, false, provider === "lastfm" || provider === "lf" ? "yt" : provider);
@@ -244,7 +247,7 @@ export async function run(message, data) {
if (parsed.invalidCategory) {
return message.reply({
embeds: [new EmbedBuilder().setColor("#ff0000").setDescription(
embeds: [new EmbedBuilder().setColor(ERROR_COLOR).setDescription(
`❌ \`${resolveProvider}:${parsed.invalidCategory}\` is not valid. Non-Last.fm providers only support \`top\`.\nUse \`lastfm:${resolveProvider}\` or \`lastfm:${resolveProvider}:top\` instead.\nFor other categories, use Last.fm as the resolve provider: \`lastfm:lf:${parsed.invalidCategory}\``
)]
});
@@ -252,7 +255,7 @@ export async function run(message, data) {
if (!lowerQuery && resolveProvider && (resolveProvider === "lf" || resolveProvider === "lastfm")) {
return message.reply({
embeds: [new EmbedBuilder().setColor("#ff0000").setDescription([
embeds: [new EmbedBuilder().setColor(ERROR_COLOR).setDescription([
`❌ Specify a Last.fm category after \`lf:\``,
``,
`**Available categories:**`,
@@ -295,14 +298,14 @@ export async function run(message, data) {
`🔍 Searching Last.fm for **${query}**...`
)]
});
} catch {}
} catch(e) { }
try {
searchResult = await lastfm.searchTrack(query);
} catch {}
} catch(e) { }
if (!searchResult) {
const noResult = { embeds: [new EmbedBuilder().setColor("#ff0000").setDescription(
const noResult = { embeds: [new EmbedBuilder().setColor(ERROR_COLOR).setDescription(
`❌ No results found on Last.fm for **${query}**.`
)] };
if (statusMsg) statusMsg.edit(noResult).catch(() => message.reply(noResult));