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

+16 -12
View File
@@ -1,3 +1,8 @@
/**
* @file LastFmManager.mjs — LastFmManager — Last.fm API integration for scrobbling, now-playing, loved tracks, top tracks, and track recommendations
* @module src.LastFmManager
*/
/**
* LastFmManager.mjs — Last.fm API client for scrobbling, auth, and user data.
*
@@ -8,26 +13,22 @@
* - Fetch loved / top / recent tracks for %play lastfm loved/top/recent
* - Per-user session key storage in MySQL table `lastfm_users`
*
* Last.fm API docs: https:
* Last.fm API docs: https://www.last.fm/api
*/
import crypto from "node:crypto";
import { logger } from "./constants/Logger.mjs";
import { Utils } from "./Utils.mjs";
const BASE_URL = "https://ws.audioscrobbler.com/2.0/";
function normalizeTrackText(value) {
return String(value ?? "")
.normalize("NFKD")
.replace(/[^\w\s]+/g, " ")
.replace(/\s+/g, " ")
.trim()
.toLowerCase();
return Utils.normalizeText(value);
}
/**
* Build the API signature required by Last.fm for authenticated calls.
* See: https:
* See: https://www.last.fm/api/authentication
*/
function buildSignature(params, apiSecret) {
const sorted = Object.keys(params).sort();
@@ -70,6 +71,9 @@ async function apiCall(params, apiSecret, post = false) {
return data;
}
/**
* LastFmManager class.
*/
export class LastFmManager {
/**
* @param {object} config - The `lastfm` section from config.json
@@ -1261,10 +1265,10 @@ export class LastFmManager {
/**
* 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}