mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
refactor: codebase cleanup + critical player state bug fixes
This commit is contained in:
1 parent
82aa296fbc
commit
fbf725d29f
15 files changed
+166
-184
No files matched your search
@@ -91,6 +91,7 @@ export async function run(msg, data) {
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
logger.warn("[Autoplay] Handler error:", err?.message);
|
||||
if (!p.queue?.getCurrent() && p.queue?.isEmpty() && !p._is247Enabled()) {
|
||||
p._startInactivityTimer();
|
||||
}
|
||||
|
||||
+2
-1
@@ -248,7 +248,8 @@ export async function playLastFmCategory(ctx, msg, userId, category, options = {
|
||||
if (!p.queue.getCurrent()) {
|
||||
p.playNext();
|
||||
}
|
||||
} catch {
|
||||
} catch (e) {
|
||||
logger.warn("[LastfmCmd] Track resolve failed:", e?.message);
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-56
@@ -9,64 +9,9 @@ import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
import { logger } from "../src/constants/Logger.mjs";
|
||||
import { PROVIDER_CHOICES, parseInlineProvider } from "../src/constants/providers.mjs";
|
||||
import { playLastFmCategory } from "./lastfm.mjs";
|
||||
import { parseLastFmUrl, isLastFmUrl } from "../src/LastFmManager.mjs";
|
||||
import { ERROR_COLOR } from "../src/constants/UI.mjs";
|
||||
|
||||
/**
|
||||
* Parse a Last.fm music URL and extract artist and track info.
|
||||
* Supports:
|
||||
* 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}
|
||||
*/
|
||||
function parseLastFmUrl(url) {
|
||||
try {
|
||||
const u = new URL(url);
|
||||
if (!/^(?:www\.)?last\.fm$/i.test(u.hostname)) return null;
|
||||
|
||||
const match = u.pathname.match(/^\/music\/([^/]+)(?:\/([^/]+))?(?:\/([^/]+))?/);
|
||||
if (!match) return null;
|
||||
|
||||
const artist = decodeURIComponent(match[1].replace(/\+/g, " "));
|
||||
const segment2 = match[2] ? decodeURIComponent(match[2].replace(/\+/g, " ")) : null;
|
||||
const segment3 = match[3] ? decodeURIComponent(match[3].replace(/\+/g, " ")) : null;
|
||||
|
||||
let track = null;
|
||||
let album = null;
|
||||
|
||||
if (segment3) {
|
||||
album = segment2 === "_" ? null : segment2;
|
||||
track = segment3;
|
||||
} else if (segment2 && segment2 !== "_") {
|
||||
track = segment2;
|
||||
}
|
||||
|
||||
return { artist, track, album, url };
|
||||
} catch (e) {
|
||||
logger.warn("[Play] Error:", e?.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string is a Last.fm music URL.
|
||||
* @param {string} str
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isLastFmUrl(str) {
|
||||
if (!str || typeof str !== "string") return false;
|
||||
try {
|
||||
const u = new URL(str);
|
||||
return /^(?:www\.)?last\.fm$/i.test(u.hostname) && /^\/music\//.test(u.pathname);
|
||||
} catch (e) {
|
||||
logger.warn("[Play] Error:", e?.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const LASTFM_PLAY_CATEGORIES = ["loved", "top", "recent", "albums"];
|
||||
|
||||
/**
|
||||
|
||||
+2
-1
@@ -126,7 +126,8 @@ async function getGuildCount(client) {
|
||||
cachedGuildCount = total;
|
||||
guildCacheExpiresAt = Date.now() + CACHE_TTL_MS;
|
||||
return total;
|
||||
} catch {
|
||||
} catch (e) {
|
||||
logger.warn("[Stats] REST guild count fetch failed:", e?.message);
|
||||
if (typeof client.guilds?.size === "number") return client.guilds.size;
|
||||
return Object.keys(client.guilds ?? {}).length;
|
||||
}
|
||||
|
||||
+2
-2
@@ -40,7 +40,7 @@ export const command = new CommandBuilder()
|
||||
.setRequired(false)
|
||||
);
|
||||
|
||||
function notConfigured(prefix, t, guildId) {
|
||||
function notConfigured(t, guildId) {
|
||||
return {
|
||||
embeds: [new EmbedBuilder()
|
||||
.setColor(ERROR_COLOR)
|
||||
@@ -156,7 +156,7 @@ export async function run(msg, data) {
|
||||
|
||||
case "check":
|
||||
case "voters": {
|
||||
if (!fluxerlist || !fluxerlist.enabled) return msg.reply(notConfigured(prefix, t, guildId));
|
||||
if (!fluxerlist || !fluxerlist.enabled) return msg.reply(notConfigured(t, guildId));
|
||||
|
||||
const resolvedType = type || "bot";
|
||||
const id = resourceId || (resolvedType === "server" ? fluxerlist.serverId : fluxerlist.botId);
|
||||
|
||||
Reference in new issue
Block a user