diff --git a/commands/autoplay.mjs b/commands/autoplay.mjs index 16904c8..c5c6fd2 100644 --- a/commands/autoplay.mjs +++ b/commands/autoplay.mjs @@ -6,6 +6,7 @@ import { CommandBuilder } from "../src/CommandHandler.mjs"; import { EmbedBuilder } from "@fluxerjs/core"; import { getGlobalColor } from "../src/MessageHandler.mjs"; +import { logger } from "../src/constants/Logger.mjs"; export const command = new CommandBuilder() .setName("autoplay") @@ -50,7 +51,7 @@ export async function run(msg, data) { const pick = similar[Math.floor(Math.random() * Math.min(3, similar.length))]; query = `${pick.name} ${pick.artist}`.trim(); } - } catch(e) { } + } catch(e) { logger.warn("[Autoplay] Error:", e?.message); } } if (!query) { diff --git a/commands/debug.mjs b/commands/debug.mjs index da1993f..ceb6f17 100644 --- a/commands/debug.mjs +++ b/commands/debug.mjs @@ -6,7 +6,8 @@ import { CommandBuilder } from "../src/CommandHandler.mjs"; import { EmbedBuilder } from "@fluxerjs/core"; import { getGlobalColor } from "../src/MessageHandler.mjs"; -import { cleanId } from "../src/Utils.mjs"; +import { cleanId } from "../src/MessageHandler.mjs"; +import { logger } from "../src/constants/Logger.mjs"; import { getVoiceManager } from "@fluxerjs/voice"; import { ERROR_COLOR, WARN_COLOR, SUCCESS_COLOR, DANGER_COLOR } from "../src/constants/UI.mjs"; import { EMOJI_REMOVE_TIMEOUT } from "../src/constants/UI.mjs"; @@ -78,7 +79,7 @@ function getBotGatewayVoiceState(client, guildId) { if (channelId) return { userId: botId, channelId: cleanId(channelId) }; } } - } catch(e) { } + } catch(e) { logger.warn("[Debug] Error:", e?.message); } try { const cleanGuild = cleanId(guildId); const guild = client.guilds.get(cleanGuild) ?? client.guilds.get(guildId); @@ -100,7 +101,7 @@ function getBotGatewayVoiceState(client, guildId) { if (chId) return { userId: botId, channelId: cleanId(chId) }; } } - } catch(e) { } + } catch(e) { logger.warn("[Debug] Error:", e?.message); } } /** @@ -170,16 +171,16 @@ async function forceRejoinPlayer(ctx, player) { const revoiceConn = ctx.revoice?.connections?.get(cleanChannelId); if (revoiceConn) { - try { await ctx.revoice._destroyStaleConnection(cleanChannelId, revoiceConn); } catch(e) { } + try { await ctx.revoice._destroyStaleConnection(cleanChannelId, revoiceConn); } catch(e) { logger.warn("[Debug] Error:", e?.message); } } else if (player.connection) { - try { player.connection.removeAllListeners(); } catch(e) { } - try { ctx.revoice?._leaveGateway?.(cleanChannelId, cleanGuildId); } catch(e) { } - try { ctx.revoice?.deleteConnection?.(cleanChannelId); } catch(e) { } - try { await player.connection.disconnect(); } catch(e) { } + try { player.connection.removeAllListeners(); } catch(e) { logger.warn("[Debug] Error:", e?.message); } + try { ctx.revoice?._leaveGateway?.(cleanChannelId, cleanGuildId); } catch(e) { logger.warn("[Debug] Error:", e?.message); } + try { ctx.revoice?.deleteConnection?.(cleanChannelId); } catch(e) { logger.warn("[Debug] Error:", e?.message); } + try { await player.connection.disconnect(); } catch(e) { logger.warn("[Debug] Error:", e?.message); } } - try { await player.leave(); } catch(e) { } - try { player.destroy(); } catch(e) { } + try { await player.leave(); } catch(e) { logger.warn("[Debug] Error:", e?.message); } + try { player.destroy(); } catch(e) { logger.warn("[Debug] Error:", e?.message); } await new Promise(r => setTimeout(r, REJOIN_DELAY_MS)); @@ -195,7 +196,7 @@ async function forceRejoinPlayer(ctx, player) { newPlayer.queue.current = null; await newPlayer.playNext(); if (wasPaused) newPlayer.pause(); - } catch(e) { } + } catch(e) { logger.warn("[Debug] Error:", e?.message); } } if (wasAutoplay) newPlayer._autoplay = true; @@ -579,7 +580,7 @@ export async function run(msg, data) { : `Player Detail${pages[pageIdx].includes(",") ? "s" : ""}`; const footerText = expired ? this.t(msg, "responses._common.controlsExpired") - : `${this.t(msg, "responses.eval.pageLabel", { page: pageIdx + 1, total: totalPages })} • ${this.t(msg, "responses.eval.navigateHint")}`; + : `${this.t(msg, "responses.debug.pageLabel", { page: pageIdx + 1, total: totalPages })} • ${this.t(msg, "responses.eval.navigateHint")}`; const embedColor = (pageIdx === 0 && ghostConnections.length > 0) ? DANGER_COLOR : getGlobalColor(); const titleSuffix = (pageIdx === 0 && ghostConnections.length > 0) ? ` — ${ghostConnections.length} Ghost(s) Detected!` : ""; @@ -606,7 +607,7 @@ export async function run(msg, data) { await replyMsg.message.removeAllReactions(); } catch { for (const emoji of navEmojis) { - try { await replyMsg.message.removeReaction(emoji); } catch(e) { } + try { await replyMsg.message.removeReaction(emoji); } catch(e) { logger.warn("[Debug] Error:", e?.message); } } } }; diff --git a/commands/eval.mjs b/commands/eval.mjs index 89c279c..ea6a1c6 100644 --- a/commands/eval.mjs +++ b/commands/eval.mjs @@ -6,6 +6,7 @@ import { CommandBuilder } from "../src/CommandHandler.mjs"; import { EmbedBuilder } from "@fluxerjs/core"; import { getGlobalColor } from "../src/MessageHandler.mjs"; +import { logger } from "../src/constants/Logger.mjs"; import { inspect } from "node:util"; import { ERROR_COLOR, EMOJI_REMOVE_TIMEOUT } from "../src/constants/UI.mjs"; @@ -245,7 +246,7 @@ export async function run(msg, data) { for (const emoji of navEmojis) { try { await replyMsg.message.removeReaction(emoji); - } catch(e) { } + } catch(e) { logger.warn("[Eval] Error:", e?.message); } } } }; diff --git a/commands/filter.mjs b/commands/filter.mjs index a7e1fd9..28f6834 100644 --- a/commands/filter.mjs +++ b/commands/filter.mjs @@ -8,6 +8,7 @@ import { EmbedBuilder } from "@fluxerjs/core"; import { getGlobalColor } from "../src/MessageHandler.mjs"; import { Utils } from "../src/Utils.mjs"; import { PREV_EMOJI, NEXT_EMOJI, CANCEL_EMOJI } from "../src/constants/UI.mjs"; +import { logger } from "../src/constants/Logger.mjs"; const NAV_EMOJIS = [PREV_EMOJI, NEXT_EMOJI, CANCEL_EMOJI]; @@ -286,14 +287,14 @@ export async function run(msg) { try { await menuMsg.message.react(emoji); await Utils.sleep(50); - } catch(e) { } + } catch(e) { logger.warn("[Filter] Error:", e?.message); } } }; const removePageFilterEmojis = async (p) => { const pageEmojis = getPageItems(p).map(f => f.emoji); for (const emoji of pageEmojis) { - try { await menuMsg.message.removeReaction(emoji); } catch(e) { } + try { await menuMsg.message.removeReaction(emoji); } catch(e) { logger.warn("[Filter] Error:", e?.message); } } }; @@ -307,7 +308,7 @@ export async function run(msg) { await menuMsg.message.removeAllReactions(); } catch (_) { for (const emoji of [...FILTERS.map(f => f.emoji), ...NAV_EMOJIS]) { - try { await menuMsg.message.removeReaction(emoji); } catch(e) { } + try { await menuMsg.message.removeReaction(emoji); } catch(e) { logger.warn("[Filter] Error:", e?.message); } } } }; diff --git a/commands/lastfm.mjs b/commands/lastfm.mjs index 4d766d0..e550f04 100644 --- a/commands/lastfm.mjs +++ b/commands/lastfm.mjs @@ -7,6 +7,7 @@ import { CommandBuilder } from "../src/CommandHandler.mjs"; import { EmbedBuilder } from "@fluxerjs/core"; import { getGlobalColor } from "../src/MessageHandler.mjs"; import { Utils } from "../src/Utils.mjs"; +import { logger } from "../src/constants/Logger.mjs"; import { PROVIDER_CHOICES } from "../src/constants/providers.mjs"; import { ERROR_COLOR, EMOJI_REMOVE_TIMEOUT } from "../src/constants/UI.mjs"; @@ -118,7 +119,7 @@ async function getGuildLinkedUsers(guild) { if (userId && !m.user?.bot) memberIds.push(String(userId)); } } - } catch(e) { } + } catch(e) { logger.warn("[LastFm] Error:", e?.message); } return memberIds; } @@ -199,7 +200,7 @@ export async function playLastFmCategory(ctx, msg, userId, category, options = { `${categoryEmoji} Fetching your ${categoryLabel} tracks from Last.fm${resolveLabel}...` )] }); - } catch { statusMsg = null; } + } catch (e) { logger.warn("[LastfmCmd] Error:", e?.message); statusMsg = null; } let result; try { @@ -382,8 +383,7 @@ export async function run(msg, data) { ] }); sent = true; - } catch { - } + } catch(e) { logger.warn("[LastFm] Error:", e?.message); } const replyEmbed = new EmbedBuilder() .setColor(getGlobalColor()) @@ -705,7 +705,7 @@ export async function run(msg, data) { await replyMsg.message.removeAllReactions(); } catch { for (const emoji of navEmojis) { - try { await replyMsg.message.removeReaction(emoji); } catch(e) { } + try { await replyMsg.message.removeReaction(emoji); } catch(e) { logger.warn("[LastFm] Error:", e?.message); } } } }; @@ -738,9 +738,7 @@ export async function run(msg, data) { try { lb = await lastfm.getLeaderboard(currentPage, 10); - } catch { - - } + } catch(e) { logger.warn("[LastFm] Error:", e?.message); } await replyMsg.edit(buildPage(currentPage)).catch(() => {}); }); @@ -898,7 +896,7 @@ export async function run(msg, data) { this.t(msg, "responses.lastfm.whoknowsChecking", { artist: artistName }) )] }); - } catch { statusMsg = null; } + } catch (e) { logger.warn("[LastfmCmd] Error:", e?.message); statusMsg = null; } const guild = msg.message?.guild ?? msg.message?.member?.guild; const memberIds = await getGuildLinkedUsers(guild); @@ -1144,7 +1142,7 @@ export async function run(msg, data) { artistName = searchResult.artist; trackName = searchResult.name; } - } catch(e) { } + } catch(e) { logger.warn("[LastFm] Error:", e?.message); } } } @@ -1227,7 +1225,7 @@ export async function run(msg, data) { let similarTracks = []; try { similarTracks = await lastfm.getSimilarTracks(artistName, trackName, 5); - } catch(e) { } + } catch(e) { logger.warn("[LastFm] Error:", e?.message); } if (similarTracks.length) { const simStr = similarTracks.map(t => { @@ -1485,7 +1483,7 @@ export async function run(msg, data) { coverUrl = albumInfo.image; albumTitle = `${albumInfo.name} by ${albumInfo.artist}`; } - } catch(e) { } + } catch(e) { logger.warn("[LastFm] Error:", e?.message); } } if (!coverUrl) { @@ -1498,7 +1496,7 @@ export async function run(msg, data) { albumTitle = trackInfo.album.title; } } - } catch(e) { } + } catch(e) { logger.warn("[LastFm] Error:", e?.message); } } if (!coverUrl) { @@ -1561,7 +1559,7 @@ export async function run(msg, data) { statusMsg = await msg.reply({ embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(msg, "responses.lastfm.affinityChecking"))] }); - } catch { statusMsg = null; } + } catch (e) { logger.warn("[LastfmCmd] Error:", e?.message); statusMsg = null; } let affinityResults; try { @@ -1612,7 +1610,7 @@ export async function run(msg, data) { statusMsg = await msg.reply({ embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(msg, "responses.lastfm.crownsChecking"))] }); - } catch { statusMsg = null; } + } catch (e) { logger.warn("[LastfmCmd] Error:", e?.message); statusMsg = null; } let crowns; try { @@ -1692,7 +1690,7 @@ export async function run(msg, data) { artistName = searchResult.artist; trackName = searchResult.name; } - } catch(e) { } + } catch(e) { logger.warn("[LastFm] Error:", e?.message); } } } @@ -1707,7 +1705,7 @@ export async function run(msg, data) { statusMsg = await msg.reply({ embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(msg, "responses.lastfm.whoknowsTrackChecking", { track: trackName, artist: artistName }))] }); - } catch { statusMsg = null; } + } catch (e) { logger.warn("[LastfmCmd] Error:", e?.message); statusMsg = null; } const guild = msg.message?.guild ?? msg.message?.member?.guild; const memberIds = await getGuildLinkedUsers(guild); @@ -1788,7 +1786,7 @@ export async function run(msg, data) { statusMsg = await msg.reply({ embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(msg, "responses.lastfm.whoknowsAlbumChecking", { album: albumName, artistClause: artistName ? ` by **${artistName}**` : "" }))] }); - } catch { statusMsg = null; } + } catch (e) { logger.warn("[LastfmCmd] Error:", e?.message); statusMsg = null; } const guild = msg.message?.guild ?? msg.message?.member?.guild; const memberIds = await getGuildLinkedUsers(guild); @@ -1969,7 +1967,7 @@ export async function run(msg, data) { artistName = searchResult.artist; trackName = searchResult.name; } - } catch(e) { } + } catch(e) { logger.warn("[LastFm] Error:", e?.message); } } } diff --git a/commands/leave.mjs b/commands/leave.mjs index 3d25015..f96e1af 100644 --- a/commands/leave.mjs +++ b/commands/leave.mjs @@ -32,7 +32,7 @@ function resolvePlayerGuildId(player, mapKey, client) { /** * Execute the leave command. * @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(msg, data) { diff --git a/commands/list.mjs b/commands/list.mjs index 822d8f2..d6054f1 100644 --- a/commands/list.mjs +++ b/commands/list.mjs @@ -24,7 +24,7 @@ export const command = new CommandBuilder() /** * Execute the list command. * @param {import("../src/MessageHandler.mjs").Message} message - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(message, data) { diff --git a/commands/loop.mjs b/commands/loop.mjs index 08cd20c..e894e67 100644 --- a/commands/loop.mjs +++ b/commands/loop.mjs @@ -20,7 +20,7 @@ export const command = new CommandBuilder() /** * Execute the loop command. * @param {import("../src/MessageHandler.mjs").Message} message - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(message, data) { diff --git a/commands/lyrics.mjs b/commands/lyrics.mjs index fbcde47..159e4f2 100644 --- a/commands/lyrics.mjs +++ b/commands/lyrics.mjs @@ -64,7 +64,7 @@ export async function run(message) { ] }); } - try { await loadingMsg.message.delete(); } catch(e) { } + try { await loadingMsg.message.delete(); } catch(e) { logger.warn("[Lyrics] Error:", e?.message); } const syncIndicator = result.synced ? this.t(message, "responses.lyrics.syncedBadge") : ""; const displayTitle = Utils.cleanTitle(current.title); @@ -193,7 +193,6 @@ export async function run(message) { if (current.thumbnail) closedEmbed.setThumbnail(current.thumbnail); msg.edit({ embeds: [closedEmbed] }).catch(() => {}); }, SESSION_MS); - } catch (err) { clearInterval(loadingInterval); logger.error("[Lyrics Command] Error:", err); diff --git a/commands/move.mjs b/commands/move.mjs index 14501a9..e3adc01 100644 --- a/commands/move.mjs +++ b/commands/move.mjs @@ -24,7 +24,7 @@ export const command = new CommandBuilder() /** * Execute the move command. * @param {import("../src/MessageHandler.mjs").Message} message - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(message, data) { @@ -32,8 +32,8 @@ export async function run(message, data) { if (!p) return; const from = data.get("from")?.value; const to = data.get("to")?.value; - if (from == null || from < 1) return message.replyEmbed("Source position must be 1 or greater.").catch(() => {}); - if (to == null || to < 1) return message.replyEmbed("Target position must be 1 or greater.").catch(() => {}); + if (from === null || from === undefined || from < 1) return message.replyEmbed("Source position must be 1 or greater.").catch(() => {}); + if (to === null || to === undefined || to < 1) return message.replyEmbed("Target position must be 1 or greater.").catch(() => {}); const res = p.move(from, to); message.replyEmbed(res).catch(() => {}); } diff --git a/commands/play.mjs b/commands/play.mjs index 47af60a..60fbc4b 100644 --- a/commands/play.mjs +++ b/commands/play.mjs @@ -6,6 +6,7 @@ import { CommandBuilder } from "../src/CommandHandler.mjs"; import { EmbedBuilder } from "@fluxerjs/core"; 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 { ERROR_COLOR } from "../src/constants/UI.mjs"; @@ -44,8 +45,9 @@ function parseLastFmUrl(url) { } return { artist, track, album, url }; - } catch { - return null; + } catch (e) { + logger.warn("[Play] Error:", e?.message); + return null; } } @@ -59,8 +61,9 @@ function isLastFmUrl(str) { try { const u = new URL(str); return /^(?:www\.)?last\.fm$/i.test(u.hostname) && /^\/music\//.test(u.pathname); - } catch { - return false; + } catch (e) { + logger.warn("[Play] Error:", e?.message); + return false; } } @@ -179,7 +182,7 @@ export const command = new CommandBuilder() /** * Execute the play command. * @param {import("../src/MessageHandler.mjs").Message} message - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(message, data) { @@ -207,7 +210,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(e) { } + try { statusMsg = await message.reply({ embeds: [searchEmbed] }); } catch(e) { logger.warn("[Play] Error:", e?.message); } const playQuery = `${parsed.track} ${parsed.artist}`.trim(); const messages = p.play(playQuery, false, provider === "lastfm" || provider === "lf" ? "yt" : provider, lastfmTrackMeta); @@ -227,7 +230,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(e) { } + try { statusMsg = await message.reply({ embeds: [searchEmbed] }); } catch(e) { logger.warn("[Play] Error:", e?.message); } const playQuery = parsed.artist; const messages = p.play(playQuery, false, provider === "lastfm" || provider === "lf" ? "yt" : provider); @@ -298,11 +301,11 @@ export async function run(message, data) { `🔍 Searching Last.fm for **${query}**...` )] }); - } catch(e) { } + } catch(e) { logger.warn("[Play] Error:", e?.message); } try { searchResult = await lastfm.searchTrack(query); - } catch(e) { } + } catch(e) { logger.warn("[Play] Error:", e?.message); } if (!searchResult) { const noResult = { embeds: [new EmbedBuilder().setColor(ERROR_COLOR).setDescription( @@ -361,6 +364,7 @@ export async function run(message, data) { try { statusMsg = await message.reply({ embeds: [searchEmbed] }); } catch (err) { + logger.warn("[Play] Error:", err?.message); } const playQuery = lastfmTrackMeta diff --git a/commands/player.mjs b/commands/player.mjs index 4e98c60..5af9ed0 100644 --- a/commands/player.mjs +++ b/commands/player.mjs @@ -8,6 +8,7 @@ import { Utils } from "../src/Utils.mjs"; import { EmbedBuilder } from "@fluxerjs/core"; import { getGlobalColor } from "../src/MessageHandler.mjs"; import { EMOJI_REMOVE_TIMEOUT } from "../src/constants/UI.mjs"; +import { logger } from "../src/constants/Logger.mjs"; export const command = new CommandBuilder() .setName("player") @@ -148,7 +149,7 @@ export async function run(msg) { try { await message.message.react(control.emoji); await Utils.sleep(50); - } catch(e) { } + } catch(e) { logger.warn("[Player] Error:", e?.message); } } } @@ -168,7 +169,7 @@ export async function run(msg) { for (const emoji of controlEmojis) { try { await message.message.removeReaction(emoji); - } catch(e) { } + } catch(e) { logger.warn("[Player] Error:", e?.message); } } } }; @@ -191,7 +192,7 @@ export async function run(msg) { for (const emoji of ["⬅️", "➡️", "❌"]) { try { await lyricsMsg.message.removeReaction(emoji); - } catch(e) { } + } catch(e) { logger.warn("[Player] Error:", e?.message); } } } }; diff --git a/commands/playnext.mjs b/commands/playnext.mjs index fe428c4..1ca0d4b 100644 --- a/commands/playnext.mjs +++ b/commands/playnext.mjs @@ -36,7 +36,7 @@ export const command = new CommandBuilder() /** * Execute the playnext command. * @param {import("../src/MessageHandler.mjs").Message} message - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(message, data) { diff --git a/commands/radio.mjs b/commands/radio.mjs index 9d202ae..f434b85 100644 --- a/commands/radio.mjs +++ b/commands/radio.mjs @@ -6,6 +6,7 @@ import { CommandBuilder } from "../src/CommandHandler.mjs"; import { EmbedBuilder } from "@fluxerjs/core"; import { getGlobalColor } from "../src/MessageHandler.mjs"; +import { logger } from "../src/constants/Logger.mjs"; import { NUMBER_EMOJIS, CANCEL_EMOJI, PREV_EMOJI, NEXT_EMOJI } from "../src/constants/UI.mjs"; @@ -26,7 +27,7 @@ export const command = function() { /** * Execute the radio command. * @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(msg, data) { @@ -69,7 +70,7 @@ export async function run(msg, data) { await rawMsg.removeAllReactions(); } catch (_) { for (const emoji of baseEmojis) { - try { await rawMsg.removeReaction(emoji); } catch(e) { } + try { await rawMsg.removeReaction(emoji); } catch(e) { logger.warn("[Radio] Error:", e?.message); } } } }; diff --git a/commands/reload.mjs b/commands/reload.mjs index 08e5e14..9737be2 100644 --- a/commands/reload.mjs +++ b/commands/reload.mjs @@ -125,7 +125,7 @@ async function showResults(msg, results, label) { /** * Execute the reload command. * @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(msg, data) { diff --git a/commands/remove.mjs b/commands/remove.mjs index a02614d..86a607c 100644 --- a/commands/remove.mjs +++ b/commands/remove.mjs @@ -17,14 +17,14 @@ export const command = new CommandBuilder() /** * Execute the remove command. * @param {import("../src/MessageHandler.mjs").Message} message - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(message, data) { const p = await this.getPlayer(message, false, false, false); if (!p) return; const index = data.get("index")?.value; - if (index == null || index < 1) return message.replyEmbed("Queue position must be 1 or greater.").catch(() => {}); + if (index === null || index === undefined || index < 1) return message.replyEmbed("Queue position must be 1 or greater.").catch(() => {}); const res = p.remove(index - 1); message.replyEmbed(res).catch(() => {}); } diff --git a/commands/search.mjs b/commands/search.mjs index 7778441..bed887c 100644 --- a/commands/search.mjs +++ b/commands/search.mjs @@ -8,6 +8,7 @@ import { Message, getGlobalColor } from "../src/MessageHandler.mjs"; import { EmbedBuilder } from "@fluxerjs/core"; import { PROVIDER_CHOICES, PROVIDER_NAMES, parseInlineProvider } from "../src/constants/providers.mjs"; import { NUMBER_EMOJIS, CANCEL_EMOJI } from "../src/constants/UI.mjs"; +import { logger } from "../src/constants/Logger.mjs"; export const command = new CommandBuilder() .setName("search") @@ -38,7 +39,7 @@ export const command = new CommandBuilder() /** * Execute the search command. * @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(msg, data) { @@ -115,7 +116,7 @@ export async function run(msg, data) { const clearReactions = async () => { try { await rawMsg.removeAllReactions(); - } catch(e) { } + } catch(e) { logger.warn("[Search] Error:", e?.message); } }; const wrapped = new Message(rawMsg, this.messages); diff --git a/commands/seek.mjs b/commands/seek.mjs index e15c931..194acfa 100644 --- a/commands/seek.mjs +++ b/commands/seek.mjs @@ -22,7 +22,7 @@ export const command = new CommandBuilder() /** * Execute the seek command. * @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(msg, data) { diff --git a/commands/servers.mjs b/commands/servers.mjs index 6faab38..39650aa 100644 --- a/commands/servers.mjs +++ b/commands/servers.mjs @@ -7,6 +7,7 @@ import { CommandBuilder } from "../src/CommandHandler.mjs"; import { EmbedBuilder } from "@fluxerjs/core"; import { getGlobalColor } from "../src/MessageHandler.mjs"; import { EMOJI_REMOVE_TIMEOUT } from "../src/constants/UI.mjs"; +import { logger } from "../src/constants/Logger.mjs"; export const command = new CommandBuilder() .setName("servers") @@ -96,7 +97,7 @@ export async function run(msg) { for (const emoji of navEmojis) { try { await replyMsg.message.removeReaction(emoji); - } catch(e) { } + } catch(e) { logger.warn("[Servers] Error:", e?.message); } } } }; diff --git a/commands/settings.mjs b/commands/settings.mjs index 9a86466..08e7a5a 100644 --- a/commands/settings.mjs +++ b/commands/settings.mjs @@ -6,6 +6,7 @@ import { CommandBuilder } from "../src/CommandHandler.mjs"; import { EmbedBuilder } from "@fluxerjs/core"; import { getGlobalColor, cleanId, getMessageGuildId } from "../src/MessageHandler.mjs"; +import { logger } from "../src/constants/Logger.mjs"; import runnables from "../settings/runnables.mjs"; function embed(desc, opts = {}) { @@ -15,9 +16,11 @@ function embed(desc, opts = {}) { return { embeds: [b] }; } -/** Build a rich embed with fields for the 24/7 status panel. - * Instead, we build the base embed with EmbedBuilder, call .toJSON() - * to get the raw object, then attach a `fields` array directly. +/** + * Build a rich embed with fields for the 24/7 status panel. + * Instead of using the standard addField API, we build the base embed with + * EmbedBuilder, call .toJSON() to get the raw object, then attach a `fields` + * array directly. */ function richEmbed(fields, opts = {}) { const b = new EmbedBuilder().setColor(getGlobalColor()); @@ -183,7 +186,7 @@ function resolveChannelName(client, channelId) { try { const ch = client?.channels?.get?.(channelId); if (ch?.name) return ch.name; - } catch(e) { } + } catch(e) { logger.warn("[Settings] Error:", e?.message); } return null; } @@ -689,7 +692,7 @@ export const command = function() { /** * Execute the settings command. * @param {import("../src/MessageHandler.mjs").Message} message - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(message, data) { diff --git a/commands/stats.mjs b/commands/stats.mjs index ca33ed8..4c294cb 100644 --- a/commands/stats.mjs +++ b/commands/stats.mjs @@ -52,8 +52,9 @@ async function fetchGuildMemberCount(guild) { }, "0"); } return total; - } catch { - return guild.memberCount ?? guild.members?.size ?? 0; + } catch (e) { + logger.warn("[Stats] Error:", e?.message); + return guild.memberCount ?? guild.members?.size ?? 0; } } diff --git a/commands/support.mjs b/commands/support.mjs index d5da081..ead40c5 100644 --- a/commands/support.mjs +++ b/commands/support.mjs @@ -15,8 +15,8 @@ export const command = new CommandBuilder() /** * run function. - * @param {{*}} msg - * @returns {*} + * @param {object} msg + * @returns {void} */ export function run(msg) { const embed = new EmbedBuilder() diff --git a/commands/test.mjs b/commands/test.mjs index 7c4dfe1..2271a06 100644 --- a/commands/test.mjs +++ b/commands/test.mjs @@ -6,6 +6,7 @@ import { CommandBuilder } from "../src/CommandHandler.mjs"; import { EmbedBuilder } from "@fluxerjs/core"; import { getGlobalColor } from "../src/MessageHandler.mjs"; +import { logger } from "../src/constants/Logger.mjs"; export const command = new CommandBuilder() .setName("test") @@ -15,7 +16,7 @@ export const command = new CommandBuilder() /** * Execute the test command. * @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(msg, data) { @@ -67,7 +68,7 @@ export async function run(msg, data) { try { const fetched = await this.client.channels.fetch(channelId); if (fetched?.name) return fetched.name; - } catch(e) { } + } catch(e) { logger.warn("[Test] Error:", e?.message); } return `Unknown (${channelId})`; }; diff --git a/commands/trackopt.mjs b/commands/trackopt.mjs index 052ca6f..1417868 100644 --- a/commands/trackopt.mjs +++ b/commands/trackopt.mjs @@ -72,7 +72,7 @@ function extractAlias(parts) { /** * Execute the trackopt command. * @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(msg, data) { diff --git a/commands/volume.mjs b/commands/volume.mjs index 6ba9fbc..f2654a2 100644 --- a/commands/volume.mjs +++ b/commands/volume.mjs @@ -23,7 +23,7 @@ export const command = new CommandBuilder() /** * Execute the volume command. * @param {import("../src/MessageHandler.mjs").Message} message - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(message, data) { @@ -35,7 +35,7 @@ export async function run(message, data) { const embed = new EmbedBuilder().setColor(getGlobalColor()); - if (!volOption || raw == null || isNaN(Number(raw))) { + if (!volOption || raw === null || raw === undefined || isNaN(Number(raw))) { const current = Math.round((p.preferredVolume ?? 1) * 100); embed.setDescription(this.t(message, "responses.volume.current", { volume: current })); } else { diff --git a/commands/volumedefault.mjs b/commands/volumedefault.mjs index 8415ec2..3ce1358 100644 --- a/commands/volumedefault.mjs +++ b/commands/volumedefault.mjs @@ -24,7 +24,7 @@ export const command = new CommandBuilder() /** * Execute the volumedefault command. * @param {import("../src/MessageHandler.mjs").Message} message - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(message, data) { diff --git a/commands/vote.mjs b/commands/vote.mjs index 6443ed3..9043bd5 100644 --- a/commands/vote.mjs +++ b/commands/vote.mjs @@ -9,6 +9,7 @@ import { getGlobalColor } from "../src/MessageHandler.mjs"; import { Utils } from "../src/Utils.mjs"; import { FLUXERLIST, buildVoteLink } from "../src/constants/API.mjs"; import { ERROR_COLOR, EMOJI_REMOVE_TIMEOUT } from "../src/constants/UI.mjs"; +import { logger } from "../src/constants/Logger.mjs"; export const command = new CommandBuilder() @@ -102,7 +103,7 @@ function buildVotersEmbed(voters, total, page, limit, type, resourceId, expired /** * Execute the vote command. * @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message - * @param {Map>} data - Slash-command options map + * @param {Map} data - Slash-command options map * @returns {Promise} */ export async function run(msg, data) { @@ -207,7 +208,7 @@ export async function run(msg, data) { await replyMsg.message.removeAllReactions(); } catch { for (const emoji of navEmojis) { - try { await replyMsg.message.removeReaction(emoji); } catch(e) { } + try { await replyMsg.message.removeReaction(emoji); } catch(e) { logger.warn("[Vote] Error:", e?.message); } } } }; @@ -240,10 +241,11 @@ export async function run(msg, data) { try { voterData = await fluxerlist.getVoters(resolvedType, id, { page: currentPage, limit: 20 }); - } catch { - + } catch (e) { + logger.warn("[Vote] Re-fetch failed for page " + currentPage + ":", e?.message); } + if (!voterData) return; await replyMsg.edit(buildPage(currentPage, voterData)).catch(() => {}); }); diff --git a/index.mjs b/index.mjs index df3a142..3888a9e 100644 --- a/index.mjs +++ b/index.mjs @@ -188,7 +188,7 @@ export class Remix { commands.owners = config.owners ?? []; this.moonlink = null; - let moonlinkInitialised = false; + const moonlinkInitialised = false; this.voiceCache = new VoiceStateCache({ maxUsers: 50_000, maxBots: 10_000 }); @@ -376,7 +376,7 @@ export class Remix { } } } - } catch(e) { } + } catch(e) { logger.warn("[AloneCheck] Voice state check error:", e?.message); } } if (!hasHuman) { @@ -386,7 +386,7 @@ export class Remix { hasHuman = true; logger.aloneCheck(`[AloneCheck] Found ${room.remoteParticipants.size} LiveKit remote participant(s) in ${channelId}`); } - } catch(e) { } + } catch(e) { logger.warn("[AloneCheck] LiveKit check error:", e?.message); } } logger.aloneCheck(`[AloneCheck] channel=${channelId} guild=${guildId} hasHuman=${hasHuman} paused=${player._paused}`); @@ -409,7 +409,6 @@ export class Remix { } }, ALONE_CHECK_INTERVAL); - const self = this; this.players.checkVoiceChannels = async function (message) { const userId = message?.author?.id ?? message?.message?.author?.id; const guildId = @@ -570,7 +569,7 @@ export class Remix { })) .then(results => { const succeeded = results.filter(r => r.status === "fulfilled").length; - const failed = results.filter(r => r.status === "rejected").length; + const failed = results.length - succeeded; logger.commands(`Modules loaded (${succeeded} succeeded, ${failed} failed).`); }); @@ -791,7 +790,7 @@ export class Remix { } }); } catch(e) { - + logger.warn("[Player] Song announcement error:", e?.message); } }); @@ -821,7 +820,7 @@ export class Remix { this.players._pendingJoins.delete(cleanChannelId); } this.players.playerMap.delete(cleanChannelId); - try { player.destroy(); } catch(e) { } + try { player.destroy(); } catch(e) { logger.warn("[_spawnPlayer] Cleanup destroy error:", e?.message); } logger.warn(`[_spawnPlayer] Failed to spawn player for channel ${cleanChannelId}:`, err.message); throw err; } @@ -939,7 +938,7 @@ export class Remix { try { const member = await guild.members.fetch(user.id).catch(() => null); if (member) isMember = true; - } catch (_) { } + } catch (_) { logger.warn("[AloneCheck] Member fetch error for", user.id); } } if (!isMember) continue; diff --git a/src/CommandHandler.mjs b/src/CommandHandler.mjs index 309cb44..33c8d88 100644 --- a/src/CommandHandler.mjs +++ b/src/CommandHandler.mjs @@ -176,8 +176,6 @@ export class Option { const results = this.channelRegex.exec(i) ?? this.idRegex.exec(i); const guildId = msg?.channel?.guildId ?? msg?.guildId; - if (guildId === "eval") return (results) ? results.groups["id"] : i; - const voiceTypes = [2, 13]; const byName = msg?.guild?.channels?.find(c => c.name === i && voiceTypes.includes(c.type)); const cObj = results @@ -573,7 +571,7 @@ export class CommandHandler extends EventEmitter { try { const names = botPermResult.missing.map(k => REQUIRED_BOT_PERMISSIONS.get(k)?.name ?? k); msg.message?.reply?.("I'm missing critical permissions: **" + names.join("**, **") + "**. Ask an admin to fix this.", { ping: false }); - } catch (__) { } + } catch (__) { logger.warn("[CommandHandler] Fallback perm reply failed"); } } return; } @@ -639,7 +637,8 @@ export class CommandHandler extends EventEmitter { const data = collectArguments(argIndex, value, [value]); if (!data) { const twGuildId = msg.channel?.channel?.guildId ?? msg.message?.guildId; return this.replyHandler(this._textWrapErrorMsg(twGuildId, args.slice(argIndex).join(" "), args[argIndex].charAt(0)), msg); } argIndex += data.index - argIndex; - value = data.args.join(" ").slice(1, data.args.join(" ").length - 1); + const _joined = data.args.join(" "); + value = _joined.slice(1, _joined.length - 1); } argIndex++; i--; diff --git a/src/GatewayHandler.mjs b/src/GatewayHandler.mjs index e93c45b..5318dd2 100644 --- a/src/GatewayHandler.mjs +++ b/src/GatewayHandler.mjs @@ -102,7 +102,7 @@ export class GatewayHandler { if (guild.members && !guild.members.me) { await guild.members.fetchMe(); } - } catch (_) { } + } catch (_) { logger.warn("[GatewayHandler] fetchMe failed"); } const channels = guild.channels; if (!channels) return; diff --git a/src/LastFmManager.mjs b/src/LastFmManager.mjs index 517e0f3..e4052d9 100644 --- a/src/LastFmManager.mjs +++ b/src/LastFmManager.mjs @@ -233,7 +233,8 @@ export class LastFmManager { try { await pool.execute("ALTER TABLE \`lastfm_users\` ADD COLUMN \`scrobble_count\` BIGINT NOT NULL DEFAULT 0 AFTER \`scrobble\`"); - } catch { + } catch (e) { + logger.warn("[LastFm] Migration warning:", e?.message); } await pool.execute(` @@ -296,7 +297,8 @@ export class LastFmManager { `UPDATE lastfm_stats SET linked_users = linked_users + 1 WHERE id = 1${f.where} AND NOT EXISTS (SELECT 1 FROM (SELECT 1 FROM lastfm_users WHERE user_id = ?${f.where} AND linked_at < NOW()) AS tmp)`, [...f.params, String(userId), ...f.params] ); - } catch { + } catch (e) { + logger.warn("[LastFm] Migration warning:", e?.message); } return data; @@ -520,8 +522,9 @@ export class LastFmManager { try { const data = await apiCall(params, this.apiSecret); return data.track; - } catch { - return null; + } catch (e) { + logger.warn("[LastFm] Error:", e?.message); + return null; } } @@ -729,9 +732,7 @@ export class LastFmManager { url: t.url ?? "", match: parseFloat(t.match ?? 0), })).filter(t => t.match > 0.1); - } catch { - return []; - } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -776,8 +777,9 @@ export class LastFmManager { })), userplaycount: a.stats?.userplaycount ? Number(a.stats.userplaycount) : null, }; - } catch { - return null; + } catch (e) { + logger.warn("[LastFm] Error:", e?.message); + return null; } } @@ -822,8 +824,9 @@ export class LastFmManager { })), userplaycount: a.userplaycount ? Number(a.userplaycount) : null, }; - } catch { - return null; + } catch (e) { + logger.warn("[LastFm] Error:", e?.message); + return null; } } @@ -854,9 +857,7 @@ export class LastFmManager { playcount: Number(t.playcount ?? 0), image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "", })); - } catch { - return []; - } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -886,9 +887,7 @@ export class LastFmManager { playcount: Number(a.playcount ?? 0), image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", })); - } catch { - return []; - } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -917,9 +916,7 @@ export class LastFmManager { image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", match: parseFloat(a.match ?? 0), })); - } catch { - return []; - } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -950,9 +947,7 @@ export class LastFmManager { url: t.url ?? "", count: Number(t.count ?? 0), })); - } catch { - return []; - } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -983,8 +978,9 @@ export class LastFmManager { count: Number(t.taggings?.total ?? t.total ?? 0), summary: t.wiki?.summary ?? "", }; - } catch { - return null; + } catch (e) { + logger.warn("[LastFm] Error:", e?.message); + return null; } } @@ -1015,9 +1011,7 @@ export class LastFmManager { playcount: Number(t.playcount ?? 0), image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "", })); - } catch { - return []; - } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -1046,9 +1040,7 @@ export class LastFmManager { playcount: Number(a.playcount ?? 0), image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", })); - } catch { - return []; - } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -1082,8 +1074,9 @@ export class LastFmManager { username: user.username, playcount, }; - } catch { - return { + } catch (e) { + logger.warn("[LastFm] Error:", e?.message); + return { userId: uid, username: user.username, playcount: 0, @@ -1151,8 +1144,9 @@ export class LastFmManager { commonArtists, matchPercentage, }; - } catch { - return null; + } catch (e) { + logger.warn("[LastFm] Error:", e?.message); + return null; } } @@ -1181,9 +1175,7 @@ export class LastFmManager { from: Number(c.from ?? 0), to: Number(c.to ?? 0), })); - } catch { - return []; - } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -1219,9 +1211,7 @@ export class LastFmManager { image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", listeners: Number(a.listeners ?? 0), })); - } catch { - return []; - } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -1257,9 +1247,7 @@ export class LastFmManager { url: a.url ?? "", image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", })); - } catch { - return []; - } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -1296,8 +1284,9 @@ export class LastFmManager { } return { artist, track, album, url }; - } catch { - return null; + } catch (e) { + logger.warn("[LastFm] Error:", e?.message); + return null; } } @@ -1311,8 +1300,9 @@ export class LastFmManager { try { const u = new URL(str); return /^(?:www\.)?last\.fm$/i.test(u.hostname) && /^\/music\//.test(u.pathname); - } catch { - return false; + } catch (e) { + logger.warn("[LastFm] Error:", e?.message); + return false; } } @@ -1604,9 +1594,7 @@ export class LastFmManager { query: `${t.name} ${t.artist ?? ar.name}`, image: t.image ?? ar.image ?? "", })); - } catch { - return []; - } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } }) ); for (const r of artistResults) { @@ -1716,8 +1704,9 @@ export class LastFmManager { [...f.params] ); return Number(rows[0]?.linked_users ?? 0); - } catch { - return 0; + } catch (e) { + logger.warn("[LastFm] Error:", e?.message); + return 0; } } @@ -1776,8 +1765,9 @@ export class LastFmManager { [String(playcount), String(userId), ...f.params] ); return playcount; - } catch { - return 0; + } catch (e) { + logger.warn("[LastFm] Error:", e?.message); + return 0; } } @@ -1805,7 +1795,7 @@ export class LastFmManager { realname: f.realname ?? "", country: f.country ?? "", })); - } catch { return []; } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -1834,7 +1824,7 @@ export class LastFmManager { playcount: Number(a.playcount ?? 0), image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", })); - } catch { return []; } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -1864,7 +1854,7 @@ export class LastFmManager { playcount: Number(t.playcount ?? 0), image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "", })); - } catch { return []; } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -1894,7 +1884,7 @@ export class LastFmManager { playcount: Number(a.playcount ?? 0), image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", })); - } catch { return []; } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -1917,7 +1907,7 @@ export class LastFmManager { url: t.url ?? "", count: Number(t.count ?? 0), })); - } catch { return []; } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -1942,7 +1932,7 @@ export class LastFmManager { url: t.url ?? "", count: Number(t.count ?? 0), })); - } catch { return []; } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -1967,7 +1957,7 @@ export class LastFmManager { url: t.url ?? "", count: Number(t.count ?? 0), })); - } catch { return []; } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -1992,7 +1982,7 @@ export class LastFmManager { playcount: Number(a.playcount ?? 0), image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", })); - } catch { return []; } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -2016,7 +2006,7 @@ export class LastFmManager { listeners: Number(a.listeners ?? 0), image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", })); - } catch { return []; } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -2041,7 +2031,7 @@ export class LastFmManager { listeners: Number(t.listeners ?? 0), image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "", })); - } catch { return []; } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -2065,7 +2055,7 @@ export class LastFmManager { playcount: Number(t.playcount ?? 0), image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "", })); - } catch { return []; } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -2088,7 +2078,7 @@ export class LastFmManager { playcount: Number(a.playcount ?? 0), image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", })); - } catch { return []; } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } /** @@ -2121,8 +2111,9 @@ export class LastFmManager { username: user.username, playcount, }; - } catch { - return { + } catch (e) { + logger.warn("[LastFm] Error:", e?.message); + return { userId: uid, username: user.username, playcount: 0, @@ -2172,8 +2163,9 @@ export class LastFmManager { username: user.username, playcount, }; - } catch { - return { + } catch (e) { + logger.warn("[LastFm] Error:", e?.message); + return { userId: uid, username: user.username, playcount: 0, @@ -2216,8 +2208,9 @@ export class LastFmManager { try { const artists = await this.getTopArtists(uid, "overall", 50); return { uid, username: user.username, artists }; - } catch { - return null; + } catch (e) { + logger.warn("[LastFm] Error:", e?.message); + return null; } }) ); @@ -2295,7 +2288,7 @@ export class LastFmManager { crowns.sort((a, b) => b.userPlaycount - a.userPlaycount); return crowns; - } catch { return []; } + } catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } _assertEnabled() { diff --git a/src/MessageHandler.mjs b/src/MessageHandler.mjs index 509defa..e817667 100644 --- a/src/MessageHandler.mjs +++ b/src/MessageHandler.mjs @@ -245,7 +245,7 @@ export class MessageHandler { async assertPermissions(permissions, message) { const guild = message.guild ?? await message.client?.guilds?.resolve?.(message.guildId); if (guild && !guild.members?.me) { - try { await guild.members.fetchMe(); } catch (_) { } + try { await guild.members.fetchMe(); } catch (_) { logger.warn("[MessageHandler] fetchMe failed"); } } const missing = this.checkPermissions(permissions, message.channel ?? message.channel?.channel); if (missing.length === 0) return true; @@ -270,7 +270,7 @@ export class MessageHandler { try { const names = missing.map(k => REQUIRED_BOT_PERMISSIONS.get(k)?.name ?? k); await message.reply(this.t(message.guildId, "responses.messages.needPermsFallback", { perms: names.join("** **") }), { ping: false }); - } catch (_) { } + } catch (_) { logger.warn("[MessageHandler] Fallback permission reply failed"); } } return false; } @@ -991,7 +991,7 @@ export class RichPaginator { for (const emoji of allReactions) { try { await rawMsg.removeReaction(emoji); - } catch(e) { } + } catch(e) { logger.warn("[MessageHandler] Error:", e?.message); } } }; @@ -1090,7 +1090,7 @@ export class QueuePaginator { for (const emoji of [prev, next]) { try { await rawMsg.removeReaction(emoji); - } catch(e) { } + } catch(e) { logger.warn("[MessageHandler] Error:", e?.message); } } } }; diff --git a/src/Player.mjs b/src/Player.mjs index 8fa9499..46df061 100644 --- a/src/Player.mjs +++ b/src/Player.mjs @@ -17,8 +17,7 @@ * that occurs when a Fluxer bot token is sent to an incompatible API. */ -import Revoicejs from "revoice.js"; -const { MediaPlayer } = Revoicejs; +import { MediaPlayer } from "revoice.js"; import { ConnectionState, LKRoomEvent } from "./constants/FluxerRevoice.mjs"; import { getVoiceManager } from "@fluxerjs/voice"; @@ -33,7 +32,6 @@ import { getGlobalColor } from "./MessageHandler.mjs"; import { logger } from "./constants/Logger.mjs"; import { get247ChannelMode } from "./constants/Helpers247.mjs"; import { PROVIDER_NAMES } from "./constants/providers.mjs"; -import { cleanId } from "./Utils.mjs"; import { hasHumansInChannel } from "./constants/VoiceStateResolver.mjs"; @@ -587,7 +585,7 @@ export default class Player extends EventEmitter { logger.mediaplayer("[Player] Existing MediaPlayer unhealthy, cleaning up..."); try { if (this._mediaPlayer.fProc) { - try { this._mediaPlayer.fProc.removeAllListeners(); } catch(e) { } + try { this._mediaPlayer.fProc.removeAllListeners(); } catch(e) { logger.warn("[Player] Error removing listeners:", e?.message); } } await this._mediaPlayer.stop(); } catch(e) { logger.warn("[Player] MediaPlayer stop error:", e?.message); } @@ -674,7 +672,7 @@ export default class Player extends EventEmitter { if (this._mediaPlayer) { try { if (this._mediaPlayer.fProc) { - try { this._mediaPlayer.fProc.removeAllListeners(); } catch(e) { } + try { this._mediaPlayer.fProc.removeAllListeners(); } catch(e) { logger.warn("[Player] Error removing listeners:", e?.message); } } await this._mediaPlayer.stop(); @@ -720,7 +718,7 @@ export default class Player extends EventEmitter { if (_redirects >= 5) return reject(new Error("Too many redirects")); const redirectUrl = new URL(loc); if (redirectUrl.host !== urlObj.host) { - delete options.headers?.Authorization; + if (options.headers) delete options.headers.Authorization; } return fetchUrl(loc, _redirects + 1); } @@ -801,7 +799,7 @@ export default class Player extends EventEmitter { try { if (typeof audioStream.unpipe === "function") audioStream.unpipe(); if (typeof audioStream.destroy === "function") audioStream.destroy(); - } catch (e) { } + } catch (e) { logger.warn("[Player] Error:", e?.message); } } this._currentPassthrough = null; }; @@ -885,10 +883,9 @@ export default class Player extends EventEmitter { this._mediaPlayer.once("finish", onFinish); this._mediaPlayer.once("error", onError); }); - } catch (e) { if (audioStream && !audioStream.destroyed) { - try { audioStream.destroy(); } catch (e2) { } + try { audioStream.destroy(); } catch (e2) { logger.warn("[Player] Error destroying stream:", e2?.message); } } this._currentPassthrough = null; if (isIgnorableMediaStateError(e)) { @@ -1266,7 +1263,7 @@ export default class Player extends EventEmitter { } this._stopMediaPlayer().catch(() => {}).then(() => { if (connToDestroy) { - try { connToDestroy.removeAllListeners?.(); } catch(e) { } + try { connToDestroy.removeAllListeners?.(); } catch(e) { logger.warn("[Player] Error removing listeners:", e?.message); } const disconnectPromise = connToDestroy.disconnect?.(); if (disconnectPromise instanceof Promise) { disconnectPromise.catch((err) => { @@ -1779,8 +1776,9 @@ export default class Player extends EventEmitter { msg: `${vcLine}📻 **[${current.title}](${current.author?.url || current.url})**\n${current.description || ""}\n\n🎵 Now playing: ${data?.title || "Unknown"}\n\n🔉 ${vol} │ ${loopqueue} Queue │ ${songloop} Song │ ${autoplay} Autoplay`, image: current.thumbnail }; - } catch { - return { + } catch (e) { + logger.warn("[Player] Error:", e?.message); + return { msg: `${vcLine}📻 **[${current.title}](${current.author?.url || current.url})**\n\n🔉 ${vol} │ ${loopqueue} Queue │ ${songloop} Song │ ${autoplay} Autoplay`, image: current.thumbnail }; @@ -2036,7 +2034,7 @@ export default class Player extends EventEmitter { if (this._mediaPlayer) { try { if (this._mediaPlayer.fProc) { - try { this._mediaPlayer.fProc.removeAllListeners(); } catch(e) { } + try { this._mediaPlayer.fProc.removeAllListeners(); } catch(e) { logger.warn("[Player] Error removing listeners:", e?.message); } } await this._mediaPlayer.stop(); } catch(e) { logger.warn("[Player] MediaPlayer stop on next track:", e?.message); } diff --git a/src/TrackOptionsManager.mjs b/src/TrackOptionsManager.mjs index f021fcd..c4a404f 100644 --- a/src/TrackOptionsManager.mjs +++ b/src/TrackOptionsManager.mjs @@ -107,8 +107,9 @@ export class TrackOptionsManager { try { const u = new URL(track.url); return `${u.hostname}${u.pathname}`.replace(/\/+$/, "").toLowerCase().trim(); - } catch { - return track.url.toLowerCase().trim(); + } catch (e) { + logger.warn("[TrackOptions] Error:", e?.message); + return track.url.toLowerCase().trim(); } } const artist = track.artist || track.author?.name || ""; diff --git a/src/Utils.mjs b/src/Utils.mjs index 715fbdc..3052670 100644 --- a/src/Utils.mjs +++ b/src/Utils.mjs @@ -216,8 +216,9 @@ export class Utils { try { new URL(str); return true; - } catch { - return false; + } catch (e) { + logger.warn("[Utils] Error:", e?.message); + return false; } } diff --git a/src/constants/FluxerRevoice.mjs b/src/constants/FluxerRevoice.mjs index f2710a3..28f868c 100644 --- a/src/constants/FluxerRevoice.mjs +++ b/src/constants/FluxerRevoice.mjs @@ -62,7 +62,7 @@ function isLiveKitLogMessage(...args) { try { const parsed = JSON.parse(args[0]); if (parsed.name === "lk-rtc") return true; - } catch (_e) { } + } catch (_e) { logger.warn("[FluxerRevoice] Error parsing livekit args"); } } if (LIVEKIT_LOG_PREFIXES.some(p => args[0].includes(p))) return true; } @@ -370,7 +370,7 @@ export class FluxerRevoice extends EventEmitter { existing._destroyed = true; existing._connected = false; - try { existing.removeAllListeners(); } catch (e) { } + try { existing.removeAllListeners(); } catch (e) { logger.warn("[FluxerRevoice] Error removing listeners:", e?.message); } } /** @@ -474,7 +474,7 @@ export class FluxerRevoice extends EventEmitter { warn: (...args) => { if (!isLiveKitLogMessage(...args)) logger.warn("[LiveKit]", ...args); }, error: (...args) => logger.error("[LiveKit]", ...args), }); - } catch (_e) { } + } catch (_e) { logger.warn("[FluxerRevoice] Error creating LiveKit logger adapter"); } } if (!room) { diff --git a/src/constants/Locale.mjs b/src/constants/Locale.mjs index b01a98f..8515d09 100644 --- a/src/constants/Locale.mjs +++ b/src/constants/Locale.mjs @@ -6,6 +6,7 @@ import { readFileSync, readdirSync, existsSync } from "fs"; import path from "path"; import { fileURLToPath } from "url"; +import { logger } from "./Logger.mjs"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const LOCALES_DIR = path.resolve(__dirname, "../../storage/locales/bot"); @@ -53,7 +54,7 @@ export class Locale { this._resolved.clear(); if (!existsSync(LOCALES_DIR)) { - console.warn(`[Locale] Locales directory not found: ${LOCALES_DIR}`); + logger.warn("[Locale] Locales directory not found:", LOCALES_DIR); return; } @@ -61,7 +62,7 @@ export class Locale { try { files = readdirSync(LOCALES_DIR).filter(f => f.endsWith(".json")); } catch (e) { - console.warn(`[Locale] Failed to read locales directory: ${e.message}`); + logger.warn("[Locale] Failed to read locales directory:", e.message); return; } @@ -72,13 +73,11 @@ export class Locale { const data = JSON.parse(readFileSync(filePath, "utf8")); this.locales.set(code, data); } catch (e) { - console.warn(`[Locale] Failed to load ${file}: ${e.message}`); + logger.warn("[Locale] Failed to load " + file + ":", e.message); } } - console.log( - `[Locale] Loaded ${this.locales.size} locale(s): ${[...this.locales.keys()].join(", ")}` - ); + logger.info("[Locale] Loaded " + this.locales.size + " locale(s): " + [...this.locales.keys()].join(", ")); } /** @@ -113,7 +112,7 @@ export class Locale { code = setting; } } - } catch(e) { } + } catch(e) { logger.warn("[Locale] Error:", e?.message); } const data = this.locales.get(code) ?? this.locales.get(this.defaultLocale) ?? {}; this._resolved.set(guildId, data); @@ -161,7 +160,7 @@ export class Locale { const prefix = serverSettings.get("prefix"); if (prefix) return prefix; } - } catch(e) { } + } catch(e) { logger.warn("[Locale] Error:", e?.message); } return this._defaultPrefix || "!"; } diff --git a/src/constants/audio/StreamMerger.mjs b/src/constants/audio/StreamMerger.mjs index 371bf7e..1027b99 100644 --- a/src/constants/audio/StreamMerger.mjs +++ b/src/constants/audio/StreamMerger.mjs @@ -1,3 +1,13 @@ +/** + * @file StreamMerger.mjs — StreamMerger — Transform stream that mixes multiple audio inputs through FFmpeg amix filter + * @module src.constants.audio.StreamMerger + */ + +/** + * StreamMerger extends Transform to mix multiple audio streams into one + * using FFmpeg’s amix filter. Supports dynamic stream addition with + * a tree-based node structure for managing merge slots. + */ import { logger } from "../Logger.mjs"; import ffmpeg from "ffmpeg-static"; import { Transform } from "node:stream"; @@ -26,7 +36,14 @@ class StreamMerger extends Transform { this.ffmpeg.stdout.on("data", (chunk) => { this.push(chunk); }); } spawnFfmpeg() { - const args = "-i pipe:3 -re -i pipe:4 -vn -fflags nobuffer -filter_complex amix=inputs=2:duration=longest pipe:1".split(" "); + const args = [ + "-i", "pipe:3", + "-re", "-i", "pipe:4", + "-vn", + "-fflags", "nobuffer", + "-filter_complex", "amix=inputs=2:duration=longest", + "pipe:1", + ]; return spawn(this.ffmpegPath, args, { windowsHide: true, stdio: ["pipe", "pipe", "pipe", "pipe", "pipe"] @@ -60,6 +77,7 @@ class StreamMerger extends Transform { open.children.push(node); s.pipe(p.stdio[3]); p.stderr.on("data", (c) => { logger.mediaplayer("[ffmpeg]", c.toString().trim()); }); + /** Write initial silence to prime the ffmpeg stdin pipe (required for amix to detect the input). */ p.stdio[4].write(Buffer.alloc(1024, 0)); p.stdout.pipe(open.process.stdio[open.pipes[0]]); const pipeNumber = open.pipes[0]; diff --git a/src/constants/audio/Tuna.mjs b/src/constants/audio/Tuna.mjs index b97601c..c695a82 100644 --- a/src/constants/audio/Tuna.mjs +++ b/src/constants/audio/Tuna.mjs @@ -1,3 +1,12 @@ +/** + * @file Tuna.mjs — Tuna — Voicemod Tuna API client for sound effect search and download + * @module src.constants.audio.Tuna + */ + +/** + * Tuna API client for searching and downloading sound effects + * from the Voicemod Tuna service (tuna-api.voicemod.net). + */ import pkg from "follow-redirects"; const { https } = pkg; @@ -7,11 +16,9 @@ class Tuna { this.apiKey = auth.key; } get(path, params = {}) { - return new Promise((resolve, rej) => { - let query = ""; - for (let key in params) { - query += ((query.length === 0) ? "?" : "&") + key + "=" + encodeURIComponent(params[key]); - } + return new Promise((resolve, reject) => { + const qs = new URLSearchParams(params).toString(); + const query = qs ? "?" + qs : ""; const options = { method: "GET", hostname: "tuna-api.voicemod.net", @@ -19,21 +26,21 @@ class Tuna { headers: { "x-api-key": this.apiKey }, maxRedirects: 20 }; - const req = https.request(options, function(res) { + const req = https.request(options, (res) => { const chunks = []; res.on("data", (chunk) => { chunks.push(chunk); }); res.on("end", () => { try { resolve(JSON.parse(Buffer.concat(chunks).toString())); } catch (e) { - rej(new Error(`Tuna API JSON parse error: ${e.message}`)); + reject(new Error(`Tuna API JSON parse error: ${e.message}`)); } }); }); - req.on("error", (error) => { rej(error); }); + req.on("error", (error) => { reject(error); }); req.setTimeout(15_000, () => { req.destroy(); - rej(new Error("Tuna API request timeout")); + reject(new Error("Tuna API request timeout")); }); req.end(); }); @@ -41,9 +48,10 @@ class Tuna { search(query, page = 1, size = 10) { return this.get("/v1/sounds/search", { size, page, search: query }).then(results => { results.items = results.items.map(s => { - s.download = function() { + const oggPath = s.oggPath; + s.download = () => { return new Promise((resolve, reject) => { - const req = https.get(this.oggPath, { maxRedirects: 20 }, (r) => { resolve(r); }); + const req = https.get(oggPath, { maxRedirects: 20 }, (r) => { resolve(r); }); req.on("error", (err) => { reject(err); }); req.setTimeout(15_000, () => { req.destroy(); reject(new Error("Tuna download timeout")); }); }); @@ -55,9 +63,10 @@ class Tuna { } getSound(id) { return this.get("/v1/sounds/" + id).then(sound => { - sound.download = function() { + const oggPath = sound.oggPath; + sound.download = () => { return new Promise((resolve, reject) => { - const req = https.get(this.oggPath, { maxRedirects: 20 }, (result) => { resolve(result); }); + const req = https.get(oggPath, { maxRedirects: 20 }, (result) => { resolve(result); }); req.on("error", (err) => { reject(err); }); req.setTimeout(15_000, () => { req.destroy(); reject(new Error("Tuna download timeout")); }); }); diff --git a/src/dashboard/Dashboard.mjs b/src/dashboard/Dashboard.mjs index 50f23f6..41faac5 100644 --- a/src/dashboard/Dashboard.mjs +++ b/src/dashboard/Dashboard.mjs @@ -42,7 +42,7 @@ export class Dashboard { case "fetchPlayers": return [...this.remix.players.playerMap.values()] .filter(p => !p._destroyed) - .map(p => { try { return Dashboard.convertPlayer(p); } catch(_) { return null; } }) + .map(p => { try { return Dashboard.convertPlayer(p); } catch(e) { logger.warn("[Dashboard] convertPlayer error:", e?.message); return null; } }) .filter(Boolean); case "user": { @@ -209,7 +209,7 @@ export class Dashboard { data: String(user.id) })); } - } catch (_) { } + } catch (_) { logger.warn("[Dashboard] Error:", _.message); } } return { message: "Already Connected" }; } @@ -349,7 +349,7 @@ export class Dashboard { data: String(user.id) })); } - } catch (_) { } + } catch (_) { logger.warn("[Dashboard] Error:", _.message); } return { message: "Left channel" }; } try { @@ -465,7 +465,7 @@ export class Dashboard { if (!vid) return null; const durationMs = typeof vid.duration === "number" ? vid.duration : - typeof vid.duration === "object" && vid.duration?.seconds != null ? vid.duration.seconds * 1000 : + typeof vid.duration === "object" && vid.duration?.seconds !== null ? vid.duration.seconds * 1000 : 0; return { title: vid.title, @@ -542,7 +542,7 @@ export class Dashboard { if (guild.icon) { iconUrl = `https://fluxerusercontent.com/icons/${guild.id}/${guild.icon}.webp`; } else if (typeof guild.iconURL === "function") { - try { iconUrl = guild.iconURL() ?? null; } catch (_) { iconUrl = null; } + try { iconUrl = guild.iconURL() ?? null; } catch (e) { logger.warn("[Dashboard] iconURL error:", e?.message); iconUrl = null; } } return { @@ -566,7 +566,7 @@ export class Dashboard { if (guild.icon) { iconUrl = `https://fluxerusercontent.com/icons/${guild.id}/${guild.icon}.webp`; } else if (typeof guild.iconURL === "function") { - try { iconUrl = guild.iconURL() ?? null; } catch (_) { iconUrl = null; } + try { iconUrl = guild.iconURL() ?? null; } catch (e) { logger.warn("[Dashboard] iconURL error:", e?.message); iconUrl = null; } } return { name: guild.name, @@ -625,7 +625,7 @@ export class Dashboard { for (const [mapUserId, info] of vc) { if (seen.has(mapUserId)) continue; const infoCh = cleanId(info.channelId); - const infoG = cleanId(info.guildId); + const infoG = cleanId(info.guildId); if (infoCh === cleanChannelId && infoG === cleanGuildId) { const botId = player.client?.user?.id; if (botId && String(mapUserId) === String(botId)) continue; @@ -800,7 +800,7 @@ export class Dashboard { let res; try { - res = await this.db.execute("SELECT * FROM login_codes WHERE user=? AND (verified IS NULL OR verified != true)", [user]); + res = await this.db.execute("SELECT * FROM login_codes WHERE user=? AND (verified IS NULL OR verified !== true)", [user]); } catch (e) { const id = Utils.uid(); logger.dashboard("[Dashboard] MySQL error, id:", id, e); diff --git a/src/probe.mjs b/src/probe.mjs index ff04038..b4c4819 100644 --- a/src/probe.mjs +++ b/src/probe.mjs @@ -24,7 +24,7 @@ export default function probe(file) { const cleanup = () => { settled = true; clearTimeout(timeoutHandle); - try { proc.kill(); } catch(e) { } + try { proc.kill(); } catch(e) { /* process already exited */ } }; const timeoutHandle = setTimeout(() => {