mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
no comment still working on it
This commit is contained in:
1 parent
cea0014e18
commit
e11fca151c
87 files changed
+5710
-10182
No files matched your search
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file autoplay command — Toggle autoplay to automatically play similar tracks when the queue ends
|
||||
* @module commands/autoplay
|
||||
* @description Toggle autoplay mode — automatically play similar tracks when the queue ends.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -8,6 +8,7 @@ import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
import { logger } from "../src/constants/Logger.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the autoplay command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("autoplay")
|
||||
.setDescription("Toggle autoplay — automatically play similar tracks when the queue ends.", "commands.autoplay")
|
||||
@@ -15,9 +16,12 @@ export const command = new CommandBuilder()
|
||||
.addAliases("ap");
|
||||
|
||||
/**
|
||||
* Execute the autoplay command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* @async
|
||||
* Run handler for the autoplay command.
|
||||
* Toggles autoplay on the player. When enabled, registers a queueEnd listener
|
||||
* that fetches similar tracks (via Last.fm or YouTube) and adds them to the queue.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} data - Parsed command data (unused, no options required).
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg, data) {
|
||||
|
||||
+9
-4
@@ -1,12 +1,16 @@
|
||||
/**
|
||||
* @file clear command — Remove all songs from the queue
|
||||
* @module commands/clear
|
||||
* @description Remove all songs from the playback queue.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
|
||||
/**
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the clear command.
|
||||
*/
|
||||
export const command = new CommandBuilder()
|
||||
.setName("clear")
|
||||
.setDescription("Remove all songs from the queue.", "commands.clear")
|
||||
@@ -14,9 +18,10 @@ export const command = new CommandBuilder()
|
||||
.setCategory("music");
|
||||
|
||||
/**
|
||||
* Execute the clear command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* Run handler for the clear command.
|
||||
* Clears the entire queue and sends a confirmation embed.
|
||||
*
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg) {
|
||||
|
||||
+68
-55
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file debug command — Owner-only debug utilities for voice connections, ghost detection, and forced rejoins
|
||||
* @module commands/debug
|
||||
* @description Owner-only debug command for voice diagnostics, ghost connection detection, and forced rejoin.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -15,9 +15,10 @@ const INTENTIONAL_LEAVE_TTL = 30_000;
|
||||
const MAX_DESC = 4096;
|
||||
|
||||
/**
|
||||
* Return a human-readable label for a voice room's connection state.
|
||||
* @param {object} room - The voice room instance
|
||||
* @returns {string}
|
||||
* Get a human-readable label for a voice room's connection state.
|
||||
* @private
|
||||
* @param {object|null} room - The voice room object.
|
||||
* @returns {string} Connection state label.
|
||||
*/
|
||||
function roomStateLabel(room) {
|
||||
if (!room) return "none";
|
||||
@@ -33,10 +34,10 @@ function roomStateLabel(room) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect whether a player has a "ghost" connection — the player object exists
|
||||
* but the underlying voice room is disconnected, reconnecting, or absent.
|
||||
* @param {import("../src/Player.mjs").default} player
|
||||
* @returns {boolean}
|
||||
* Check if a player has a ghost connection (appears in voice but WebSocket is dead).
|
||||
* @private
|
||||
* @param {object} player - The player instance.
|
||||
* @returns {boolean} True if the player has a ghost connection.
|
||||
*/
|
||||
function isGhostConnection(player) {
|
||||
const conn = player.connection;
|
||||
@@ -58,10 +59,11 @@ function isGhostConnection(player) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the bot's voice state from the gateway cache for a given guild.
|
||||
* @param {object} client - The Fluxer client instance
|
||||
* @param {string} guildId - The guild ID to look up
|
||||
* @returns {{ userId: string, channelId: string } | null}
|
||||
* Get the bot's voice channel state from the Discord gateway cache.
|
||||
* @private
|
||||
* @param {object} client - The Discord client instance.
|
||||
* @param {string} guildId - The guild ID to check.
|
||||
* @returns {{ userId: string, channelId: string }|null} Bot's voice state or null.
|
||||
*/
|
||||
function getBotGatewayVoiceState(client, guildId) {
|
||||
const botId = client.user?.id;
|
||||
@@ -108,10 +110,11 @@ function getBotGatewayVoiceState(client, guildId) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the gateway voice state is stale compared to the player's expected channel.
|
||||
* @param {object} client - The Fluxer client instance
|
||||
* @param {import("../src/Player.mjs").default} player
|
||||
* @returns {boolean}
|
||||
* Check if the gateway voice state is stale (mismatches the player's channel).
|
||||
* @private
|
||||
* @param {object} client - The Discord client instance.
|
||||
* @param {object} player - The player instance.
|
||||
* @returns {boolean} True if the gateway presence is stale.
|
||||
*/
|
||||
function isStaleGatewayPresence(client, player) {
|
||||
const guildId = player._guildId ?? player._resolveGuildId?.();
|
||||
@@ -127,11 +130,12 @@ function isStaleGatewayPresence(client, player) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a human-readable label for a player's guild/channel.
|
||||
* @param {object} client - The Fluxer client
|
||||
* @param {string} channelId - The channel ID
|
||||
* @param {import("../src/Player.mjs").default} player
|
||||
* @returns {string}
|
||||
* Build a human-readable label for a player (guild name / #channel name).
|
||||
* @private
|
||||
* @param {object} client - The Discord client instance.
|
||||
* @param {string} channelId - The voice channel ID.
|
||||
* @param {object} player - The player instance.
|
||||
* @returns {string} Formatted label string.
|
||||
*/
|
||||
function buildPlayerLabel(client, channelId, player) {
|
||||
const channel = client.channels.get(channelId);
|
||||
@@ -141,10 +145,12 @@ function buildPlayerLabel(client, channelId, player) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy a player's stale connection and respawn a fresh player, restoring queue, loop, filters, and playback.
|
||||
* @param {object} ctx - The bot context (this)
|
||||
* @param {import("../src/Player.mjs").default} player
|
||||
* @returns {Promise<{ success: boolean, reason?: string, channelId?: string, roomConnected?: boolean, roomState?: string, resumedPlayback?: boolean }>}
|
||||
* Force a player to leave and rejoin, restoring queue and playback state.
|
||||
* @private
|
||||
* @async
|
||||
* @param {object} ctx - The bot (Remix) instance context.
|
||||
* @param {object} player - The player to rejoin.
|
||||
* @returns {Promise<object>} Result object with success status, room state, and details.
|
||||
*/
|
||||
async function forceRejoinPlayer(ctx, player) {
|
||||
const channelId = player._channelId ?? player._home247Channel;
|
||||
@@ -166,7 +172,6 @@ async function forceRejoinPlayer(ctx, player) {
|
||||
|
||||
try {
|
||||
ctx.markIntentionalLeave?.(cleanChannelId, INTENTIONAL_LEAVE_TTL);
|
||||
ctx.revoice?.markIntentionalDisconnect(cleanChannelId);
|
||||
|
||||
ctx.players.playerMap.delete(cleanChannelId);
|
||||
ctx.players._unindexPlayer?.(cleanGuildId, cleanChannelId);
|
||||
@@ -188,13 +193,8 @@ async function forceRejoinPlayer(ctx, player) {
|
||||
|
||||
ctx.players._pendingJoins?.delete?.(cleanChannelId);
|
||||
|
||||
const revoiceConn = ctx.revoice?.connections?.get(cleanChannelId);
|
||||
if (revoiceConn) {
|
||||
try { await ctx.revoice._destroyStaleConnection(cleanChannelId, revoiceConn); } catch (e) { logger.warn("[Debug] revoice stale destroy:", e?.message); }
|
||||
} else if (player.connection) {
|
||||
if (player.connection) {
|
||||
try { player.connection.removeAllListeners(); } catch (e) { logger.warn("[Debug] connection listener removal:", e?.message); }
|
||||
try { ctx.revoice?._leaveGateway?.(cleanChannelId, cleanGuildId); } catch (e) { logger.warn("[Debug] gateway leave:", e?.message); }
|
||||
try { ctx.revoice?.deleteConnection?.(cleanChannelId); } catch (e) { logger.warn("[Debug] revoice delete:", e?.message); }
|
||||
try { await player.connection.disconnect(); } catch (e) { logger.warn("[Debug] connection disconnect:", e?.message); }
|
||||
}
|
||||
|
||||
@@ -247,12 +247,14 @@ async function forceRejoinPlayer(ctx, player) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a batch of players for rejoin, with progress updates.
|
||||
* @param {object} ctx - The bot context (this)
|
||||
* @param {Array<[string, import("../src/Player.mjs").default]>} entries - [channelId, player] pairs
|
||||
* @param {import("../src/MessageHandler.mjs").Message} statusMsg - The status message to edit with progress
|
||||
* @param {string} title - The embed title
|
||||
* @returns {Promise<Array>} Results array
|
||||
* Process a batch of players for force-rejoin, updating a status message with progress.
|
||||
* @private
|
||||
* @async
|
||||
* @param {object} ctx - The bot (Remix) instance context.
|
||||
* @param {Array} entries - Array of [channelId, player] tuples.
|
||||
* @param {object} statusMsg - The message to update with progress.
|
||||
* @param {string} title - The title for the progress display.
|
||||
* @returns {Promise<object[]>} Array of rejoin results.
|
||||
*/
|
||||
async function processRejoinBatch(ctx, entries, statusMsg, title) {
|
||||
const results = [];
|
||||
@@ -286,11 +288,12 @@ async function processRejoinBatch(ctx, entries, statusMsg, title) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the final results embed after a batch rejoin.
|
||||
* @param {Array} results - Results from processRejoinBatch
|
||||
* @param {string} title - The embed title
|
||||
* @param {string} noun - "ghost connection(s)" or "24/7 channel(s)"
|
||||
* @returns {{embeds: [EmbedBuilder]}}
|
||||
* Build the final embed summarizing rejoin results.
|
||||
* @private
|
||||
* @param {object[]} results - Array of rejoin result objects.
|
||||
* @param {string} title - The title for the embed.
|
||||
* @param {string} noun - The noun describing the rejoin targets.
|
||||
* @returns {object} Message payload with embed.
|
||||
*/
|
||||
function buildRejoinResultEmbed(results, title, noun) {
|
||||
const resultLines = [
|
||||
@@ -324,6 +327,10 @@ function buildRejoinResultEmbed(results, title, noun) {
|
||||
return { embeds: [new EmbedBuilder().setColor(finalColor).setTitle(`Debug — ${title}`).setDescription(resultLines.join("\n").slice(0, MAX_DESC))] };
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the debug command (owner-only).
|
||||
*/
|
||||
export const command = new CommandBuilder()
|
||||
.setName("debug")
|
||||
.setDescription("A debug command for various purposes.")
|
||||
@@ -336,9 +343,11 @@ export const command = new CommandBuilder()
|
||||
.setRequired(true));
|
||||
|
||||
/**
|
||||
* Execute the debug command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* Run handler for the debug command.
|
||||
* Routes to the appropriate debug subcommand based on the target option.
|
||||
*
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing the target option.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg, data) {
|
||||
@@ -369,13 +378,15 @@ export async function run(msg, data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a batch rejoin for players matching a filter.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {string} key - The debug key for log labels
|
||||
* @param {string} title - The display title
|
||||
* @param {string} noun - What we're rejoining (for result text)
|
||||
* @param {(player: import("../src/Player.mjs").default) => boolean} filter - Player filter
|
||||
* @param {boolean} showHintIfEmpty - Show a hint when no matches found
|
||||
* Run a batch rejoin operation on matching players.
|
||||
* @private
|
||||
* @async
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {string} key - Identifier key for the rejoin type.
|
||||
* @param {string} title - Display title for the operation.
|
||||
* @param {string} noun - Noun describing the targets.
|
||||
* @param {Function} filter - Function to filter which players to rejoin.
|
||||
* @param {boolean} [showHintIfEmpty=false] - Whether to show a hint if no matches found.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function runBatchRejoin(msg, key, title, noun, filter, showHintIfEmpty = false) {
|
||||
@@ -426,8 +437,10 @@ async function runBatchRejoin(msg, key, title, noun, filter, showHintIfEmpty = f
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the full voice diagnostic with paginated output.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* Run a full voice diagnostic, displaying player states and ghost connections.
|
||||
* @private
|
||||
* @async
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function runVoiceDiagnostic(msg) {
|
||||
|
||||
+57
-27
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file eval command — Owner-only JavaScript code evaluation with sensitive-data redaction
|
||||
* @module commands/eval
|
||||
* @description Owner-only command to evaluate arbitrary JavaScript code and display the result.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -10,10 +10,7 @@ import { logger } from "../src/constants/Logger.mjs";
|
||||
import { inspect } from "node:util";
|
||||
import { ERROR_COLOR, EMOJI_REMOVE_TIMEOUT } from "../src/constants/UI.mjs";
|
||||
|
||||
|
||||
/**
|
||||
* Matches any key that *contains* one of these strings (case-insensitive).
|
||||
*/
|
||||
/** @private @type {string[]} Property name substrings that indicate sensitive/secret data. */
|
||||
const RESTRICTED = [
|
||||
"token",
|
||||
"config",
|
||||
@@ -24,21 +21,23 @@ const RESTRICTED = [
|
||||
"secret",
|
||||
"authorization",
|
||||
"mysql",
|
||||
"nodelink",
|
||||
"lavalink",
|
||||
"_nl",
|
||||
"credential",
|
||||
"apikey",
|
||||
"webhook",
|
||||
];
|
||||
|
||||
/** @private @type {number} Maximum recursion depth when scanning for sensitive keys. */
|
||||
const SCAN_DEPTH = 6;
|
||||
|
||||
/**
|
||||
* Check whether an object contains sensitive keys at any nesting level.
|
||||
* @param {object} obj - The object to scan
|
||||
* @param {number} [level=0] - Current recursion depth
|
||||
* @param {WeakSet} [visited=new WeakSet()] - Visited object tracker
|
||||
* @returns {boolean}
|
||||
* @private
|
||||
* Recursively check whether an object contains keys matching RESTRICTED substrings.
|
||||
* @param {*} obj - The object to scan.
|
||||
* @param {number} [level=0] - Current recursion depth.
|
||||
* @param {WeakSet} [visited=new WeakSet()] - Already-visited objects to prevent cycles.
|
||||
* @returns {boolean} True if any sensitive key is found.
|
||||
*/
|
||||
function hasSensitive(obj, level = 0, visited = new WeakSet()) {
|
||||
if (level >= SCAN_DEPTH || typeof obj !== "object" || obj === null) return false;
|
||||
@@ -52,11 +51,12 @@ function hasSensitive(obj, level = 0, visited = new WeakSet()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively redact sensitive keys from an object, replacing values with "[REDACTED]".
|
||||
* @param {object} obj - The object to scrub
|
||||
* @param {number} [level=0] - Current recursion depth
|
||||
* @param {WeakSet} [visited=new WeakSet()] - Visited object tracker
|
||||
* @returns {object} The scrubbed object (or the original if no changes were needed)
|
||||
* @private
|
||||
* Recursively redact sensitive keys in an object, replacing values with "[REDACTED]".
|
||||
* @param {*} obj - The object to clean.
|
||||
* @param {number} [level=0] - Current recursion depth.
|
||||
* @param {WeakSet} [visited=new WeakSet()] - Already-visited objects to prevent cycles.
|
||||
* @returns {*} The cleaned object (original reference if no modifications, new object otherwise).
|
||||
*/
|
||||
function removeSensitive(obj, level = 0, visited = new WeakSet()) {
|
||||
if (level >= SCAN_DEPTH || typeof obj !== "object" || obj === null) return obj;
|
||||
@@ -85,9 +85,12 @@ function removeSensitive(obj, level = 0, visited = new WeakSet()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Await a value if it is a Promise, then redact sensitive data and format for display.
|
||||
* @param {*} value - The value to clean and format
|
||||
* @returns {Promise<string>} Formatted, safe string representation
|
||||
* @private
|
||||
* @async
|
||||
* Sanitize a value for safe display: await promises, redact sensitive keys,
|
||||
* inspect with node:util, and escape Discord markup characters.
|
||||
* @param {*} value - The raw eval result.
|
||||
* @returns {Promise<string>} The sanitized output string.
|
||||
*/
|
||||
async function clean(value) {
|
||||
if (value instanceof Promise) value = await value;
|
||||
@@ -111,9 +114,11 @@ async function clean(value) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a code string is a single expression (no semicolons, blocks, or declarations).
|
||||
* @param {string} code - The code to inspect
|
||||
* @returns {boolean}
|
||||
* @private
|
||||
* Determine whether a code string is a single expression (vs. statements).
|
||||
* Used to decide whether to wrap in a return statement.
|
||||
* @param {string} code - The code to analyze.
|
||||
* @returns {boolean} True if the code appears to be a single expression.
|
||||
*/
|
||||
function isSingleExpression(code) {
|
||||
const trimmed = code.trim();
|
||||
@@ -137,8 +142,12 @@ function isSingleExpression(code) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the code and returns the raw data instead of a formatted string,
|
||||
* so we can paginate it inside Embeds later.
|
||||
* @private
|
||||
* @async
|
||||
* Execute a JavaScript expression/statement in a sandboxed async context.
|
||||
* @param {string} expression - The code to evaluate.
|
||||
* @param {object} context - The `this` context for the eval.
|
||||
* @returns {Promise<{output: string, isError: boolean, type: string, elapsed: number}>} Eval result.
|
||||
*/
|
||||
async function runEval(expression, context) {
|
||||
const start = Date.now();
|
||||
@@ -163,6 +172,7 @@ async function runEval(expression, context) {
|
||||
return { output, isError, type, elapsed };
|
||||
}
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the eval command (owner-only). */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("eval")
|
||||
.setDescription("Evaluates JavaScript code (Owner Only).")
|
||||
@@ -175,9 +185,12 @@ export const command = new CommandBuilder()
|
||||
);
|
||||
|
||||
/**
|
||||
* Execute the eval command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* @async
|
||||
* Run handler for the eval command.
|
||||
* Evaluates the provided JavaScript expression, sanitizes the output,
|
||||
* and displays it in a paginated embed with reaction navigation.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing the expression option.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg, data) {
|
||||
@@ -204,6 +217,13 @@ export async function run(msg, data) {
|
||||
const totalPages = chunks.length;
|
||||
let currentPage = 0;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Build the embed payload for a specific page of the eval output.
|
||||
* @param {number} pageIdx - Zero-based page index.
|
||||
* @param {boolean} [expired=false] - Whether the reaction controls have expired.
|
||||
* @returns {object} Embed payload for message reply/edit.
|
||||
*/
|
||||
const buildPageContent = (pageIdx, expired = false) => {
|
||||
const title = isError
|
||||
? this.t(msg, "responses.eval.resultTitleError")
|
||||
@@ -239,6 +259,11 @@ export async function run(msg, data) {
|
||||
await replyMsg.message.react(emoji).catch(() => {});
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Remove all navigation reactions from the eval reply message.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const clearReactions = async () => {
|
||||
try {
|
||||
await replyMsg.message.removeAllReactions();
|
||||
@@ -251,6 +276,11 @@ export async function run(msg, data) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Reset the emoji removal timeout timer for the eval session.
|
||||
* @returns {void}
|
||||
*/
|
||||
const resetTimer = () => {
|
||||
clearTimeout(emojiTimeout);
|
||||
emojiTimeout = setTimeout(async () => {
|
||||
|
||||
+21
-15
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file filter command — Interactive audio filter picker with emoji-based toggling
|
||||
* @module commands/filter
|
||||
* @description Interactive audio filter picker with emoji-based selection and pagination.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -173,10 +173,10 @@ const PAGE_SIZE = 9;
|
||||
const SESSION_MS = 60_000;
|
||||
|
||||
/**
|
||||
* Merge multiple active filter payloads into a single Lavalink filters object.
|
||||
* Categories that overlap are overwritten by the last filter in the list.
|
||||
* The special "off" key is skipped — it carries an empty payload and is handled
|
||||
* by clearing activeKeys before this function is called.
|
||||
* Merge filter payloads for multiple active filter keys into one combined payload.
|
||||
* @private
|
||||
* @param {string[]} keys - Array of active filter keys.
|
||||
* @returns {object} Merged Lavalink filter payload.
|
||||
*/
|
||||
function mergeFilterPayloads(keys) {
|
||||
const merged = {};
|
||||
@@ -191,6 +191,10 @@ function mergeFilterPayloads(keys) {
|
||||
return merged;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the filter command.
|
||||
*/
|
||||
export const command = new CommandBuilder()
|
||||
.setName("filter")
|
||||
.setDescription(
|
||||
@@ -201,13 +205,14 @@ export const command = new CommandBuilder()
|
||||
.addAliases("filters", "fx", "effect");
|
||||
|
||||
/**
|
||||
* Build the embed for a single page of the filter picker.
|
||||
* @param {Function} t - Translation function
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {number} page - Current page index (0-based)
|
||||
* @param {string[]} activeKeys - Currently active filter keys
|
||||
* @param {object} [current] - The currently playing track
|
||||
* @returns {import("@fluxerjs/core").EmbedBuilder}
|
||||
* Build an embed for a page of the filter picker.
|
||||
* @private
|
||||
* @param {Function} t - Translation function.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {number} page - Current page index (0-based).
|
||||
* @param {string[]} activeKeys - Array of currently active filter keys.
|
||||
* @param {object|null} current - The currently playing track, or null.
|
||||
* @returns {EmbedBuilder} The constructed embed.
|
||||
*/
|
||||
function buildPageEmbed(t, msg, page, activeKeys, current) {
|
||||
const totalPages = Math.ceil(FILTERS.length / PAGE_SIZE);
|
||||
@@ -253,9 +258,10 @@ function buildPageEmbed(t, msg, page, activeKeys, current) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the filter command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* Run handler for the filter command.
|
||||
* Opens an interactive filter picker with emoji reactions.
|
||||
*
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg) {
|
||||
|
||||
+10
-4
@@ -1,11 +1,15 @@
|
||||
/**
|
||||
* @file forceleave command — Force the bot to leave a voice channel (requires ManageChannels)
|
||||
* @module commands/forceleave
|
||||
* @description Force the bot to leave a voice channel (requires ManageChannels permission).
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
import { cleanId } from "../src/MessageHandler.mjs";
|
||||
|
||||
/**
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the forceleave command.
|
||||
*/
|
||||
export const command = new CommandBuilder()
|
||||
.setName("forceleave")
|
||||
.addAliases("fl")
|
||||
@@ -20,9 +24,11 @@ export const command = new CommandBuilder()
|
||||
|
||||
|
||||
/**
|
||||
* Execute the forceleave command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* Run handler for the forceleave command.
|
||||
* Validates the target channel and forces the bot to leave.
|
||||
*
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing the channelId option.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg, data) {
|
||||
|
||||
+9
-4
@@ -1,12 +1,16 @@
|
||||
/**
|
||||
* @file invite command — Get the bot invite link and support server invite
|
||||
* @module commands/invite
|
||||
* @description Display the bot invite link and support server information.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
|
||||
/**
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the invite command.
|
||||
*/
|
||||
export const command = new CommandBuilder()
|
||||
.setName("invite")
|
||||
.setDescription("Get the invite link for Remix and the support server.", "commands.invite")
|
||||
@@ -14,9 +18,10 @@ export const command = new CommandBuilder()
|
||||
.setCategory("util");
|
||||
|
||||
/**
|
||||
* Execute the invite command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* Run handler for the invite command.
|
||||
* Sends an embed with the bot invite link and support server info.
|
||||
*
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message) {
|
||||
|
||||
+42
-161
@@ -1,141 +1,19 @@
|
||||
/**
|
||||
* @file join command — Make the bot join a voice channel and initialise a player
|
||||
* @module commands/join
|
||||
* @description Makes the bot join a voice channel. Supports explicit channel argument
|
||||
* (mention, ID, or name) or auto-detects the user’s current voice channel.
|
||||
* All player spawning goes through PlayerManager.initPlayer() for consistent
|
||||
* 24/7 handling, event binding, and permission checks.
|
||||
*/
|
||||
|
||||
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 Player from "../src/Player.mjs";
|
||||
|
||||
|
||||
/**
|
||||
* 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>}
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the join command.
|
||||
*/
|
||||
export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
|
||||
const cleanChannelId = cleanId(cid);
|
||||
if (!this.client.channels.has(cleanChannelId)) {
|
||||
ecb();
|
||||
const embed = new EmbedBuilder().setColor(getGlobalColor())
|
||||
.setDescription(this.t(message, "responses.join.channelNotFound", { channel: cid }));
|
||||
return message.reply({ embeds: [embed] });
|
||||
}
|
||||
const existing = this.players.playerMap.get(cleanChannelId)
|
||||
?? [...this.players.playerMap.values()].find((player) => cleanId(player?._channelId) === cleanChannelId);
|
||||
if (existing) {
|
||||
cb(existing);
|
||||
const embed = new EmbedBuilder().setColor(getGlobalColor())
|
||||
.setDescription(this.t(message, "responses.join.alreadyJoined", { channel: cid }));
|
||||
return message.reply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
if (!this.moonlink) {
|
||||
const embed = new EmbedBuilder().setColor(getGlobalColor())
|
||||
.setDescription(this.t(message, "responses.join.audioNodeConnecting"));
|
||||
ecb();
|
||||
return message.reply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
const p = new Player(this.config.token, {
|
||||
client: this.client,
|
||||
config: this.config,
|
||||
nodelink: this.config.nodelink,
|
||||
moonlink: this.moonlink ?? null,
|
||||
revoice: this.revoice ?? null,
|
||||
messageChannel: message.channel,
|
||||
settingsMgr: this.settingsMgr ?? this.settings ?? null,
|
||||
observedVoiceUsers: this.observedVoiceUsers ?? null,
|
||||
});
|
||||
|
||||
p.on("autoleave", () => {
|
||||
const activeChannelId = cleanId(p._channelId ?? cid) || cid;
|
||||
const homeChannelId = cleanId(p._home247Channel ?? activeChannelId) || activeChannelId;
|
||||
const guildId = getMessageGuildId(message);
|
||||
|
||||
const is247 = (() => {
|
||||
try {
|
||||
const raw = this.settingsMgr?.getServer?.(guildId)?.get?.("stay_247");
|
||||
return raw && raw !== "none";
|
||||
} catch (_) { return false; }
|
||||
})();
|
||||
|
||||
const mode247 = (() => {
|
||||
if (!is247) return "off";
|
||||
try {
|
||||
const set = this.settingsMgr?.getServer?.(guildId);
|
||||
const modes = set?.get?.("stay_247_modes");
|
||||
const matchCh = homeChannelId || activeChannelId;
|
||||
if (modes && typeof modes === "object" && !Array.isArray(modes) && modes[matchCh]) {
|
||||
return modes[matchCh];
|
||||
}
|
||||
return set?.get?.("stay_247_mode") ?? "off";
|
||||
} catch (_) { return "off"; }
|
||||
})();
|
||||
|
||||
this.players.playerMap.delete(activeChannelId);
|
||||
if (activeChannelId !== cid) this.players.playerMap.delete(cid);
|
||||
if (homeChannelId !== activeChannelId) this.players.playerMap.delete(homeChannelId);
|
||||
p.destroy();
|
||||
|
||||
if (is247 && (mode247 === "on" || mode247 === "auto")) {
|
||||
const rejoinDelay = this.config?.timers?.rejoin247Delay ?? 3_000;
|
||||
const prefix = this.handler.getPrefix(guildId);
|
||||
const embed = new EmbedBuilder().setColor(getGlobalColor())
|
||||
.setDescription(this.t(message, "responses.join.autoLeaveInactive247", { channel: activeChannelId, prefix }));
|
||||
message.channel.send({ embeds: [embed] }).catch(() => {});
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
if (typeof this._spawnPlayer === "function") {
|
||||
await this._spawnPlayer(guildId, homeChannelId);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.warn(`[join/autoleave] 24/7 auto-rejoin failed for ${homeChannelId}: ${e.message}`);
|
||||
}
|
||||
}, rejoinDelay);
|
||||
} else {
|
||||
const embed2 = new EmbedBuilder().setColor(getGlobalColor())
|
||||
.setDescription(this.t(message, "responses.join.autoLeaveInactive", { channel: activeChannelId }));
|
||||
message.channel.send({ embeds: [embed2] }).catch(() => {});
|
||||
}
|
||||
});
|
||||
|
||||
p.on("message", m => {
|
||||
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] }).catch(() => {});
|
||||
});
|
||||
|
||||
this.players._pendingJoins.add(cleanChannelId);
|
||||
|
||||
const joiningEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(message, "responses.join.joining"));
|
||||
const statusMsg = await message.reply({ embeds: [joiningEmbed] });
|
||||
try {
|
||||
await p.join(cleanChannelId);
|
||||
this.players.playerMap.set(cleanChannelId, p);
|
||||
this.players._pendingJoins.delete(cleanChannelId);
|
||||
const okEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(message, "responses.join.joined", { channel: cid }));
|
||||
await statusMsg.edit({ embeds: [okEmbed] });
|
||||
cb(p);
|
||||
} catch (e) {
|
||||
this.players._pendingJoins.delete(cleanChannelId);
|
||||
this.players.playerMap.delete(cleanChannelId);
|
||||
p.destroy();
|
||||
const errEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(message, "responses.join.joinFailed", { error: e.message }));
|
||||
await statusMsg.edit({ embeds: [errEmbed] });
|
||||
ecb(e);
|
||||
}
|
||||
}
|
||||
|
||||
export const command = new CommandBuilder()
|
||||
.setName("join")
|
||||
.setDescription("Make the bot join your voice channel, or specify one.", "commands.join")
|
||||
@@ -148,48 +26,56 @@ export const command = new CommandBuilder()
|
||||
);
|
||||
|
||||
/**
|
||||
* 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>}
|
||||
* Resolve a user-provided channel string to a channel ID.
|
||||
* Supports <#ID> mentions, raw numeric IDs, and channel name matching.
|
||||
*
|
||||
* @param {string} rawArg - The raw argument string from the command.
|
||||
* @param {object} ctx - The bot context (Remix instance).
|
||||
* @returns {string|null} The resolved channel ID, or null if not found.
|
||||
*/
|
||||
function resolveChannelId(rawArg, ctx) {
|
||||
if (!rawArg) return null;
|
||||
const mentionMatch = rawArg.match(/^<(#|&)?(\d+)>$/);
|
||||
const idMatch = rawArg.match(/^(\d{15,})$/);
|
||||
|
||||
if (mentionMatch) return mentionMatch[2];
|
||||
if (idMatch) return idMatch[1];
|
||||
|
||||
// Try name-based lookup
|
||||
const guildId = cleanId(getMessageGuildId(ctx._currentMessage));
|
||||
if (!guildId) return null;
|
||||
|
||||
const allChannels = [...(ctx.client?.channels?.values?.() ?? [])];
|
||||
const match = allChannels.find(c => {
|
||||
const cServerId = cleanId(c.guildId ?? c.guild?.id ?? c.server_id ?? c.serverId);
|
||||
return c.type === 2 && cServerId === guildId && c.name?.toLowerCase() === rawArg.toLowerCase();
|
||||
});
|
||||
return match?.id ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run handler for the join command.
|
||||
* Resolves the target voice channel and delegates to PlayerManager.initPlayer().
|
||||
*
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing option values.
|
||||
* @returns {Promise<Player|null>} The spawned player, or null on failure.
|
||||
*/
|
||||
export async function run(message, data) {
|
||||
const rawArg = data?.get?.("channel")?.value?.trim?.() ?? null;
|
||||
|
||||
if (rawArg) {
|
||||
const mentionMatch = rawArg.match(/^<#(\d+)>$/);
|
||||
const idMatch = rawArg.match(/^(\d{15,})$/);
|
||||
let resolvedId = null;
|
||||
|
||||
if (mentionMatch) {
|
||||
resolvedId = mentionMatch[1];
|
||||
} else if (idMatch) {
|
||||
resolvedId = idMatch[1];
|
||||
} else {
|
||||
const guildId = cleanId(getMessageGuildId(message));
|
||||
const allChannels = [
|
||||
...(this.client?.channels?.values?.() ?? [])
|
||||
];
|
||||
const match = allChannels.find(c => {
|
||||
const cServerId = cleanId(c.guildId ?? c.guild?.id ?? c.server_id ?? c.serverId);
|
||||
const isVoice = c.type === 2;
|
||||
return isVoice && cServerId === guildId &&
|
||||
(c.name?.toLowerCase() === rawArg.toLowerCase());
|
||||
});
|
||||
if (match) resolvedId = match.id;
|
||||
}
|
||||
|
||||
const resolvedId = resolveChannelId(rawArg, this);
|
||||
if (!resolvedId) {
|
||||
const embed = new EmbedBuilder().setColor(getGlobalColor())
|
||||
.setDescription(this.t(message, "responses.join.voiceChannelNotFound"));
|
||||
return message.reply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
return this.players.initPlayer(message, resolvedId);
|
||||
}
|
||||
|
||||
// No argument — auto-detect the user’s current voice channel
|
||||
const { channelId: cid } = await this.players.checkVoiceChannels(message);
|
||||
|
||||
if (!cid) {
|
||||
const prefix = this.handler.getPrefix(getMessageGuildId(message));
|
||||
const embed = new EmbedBuilder().setColor(getGlobalColor())
|
||||
@@ -199,8 +85,3 @@ export async function run(message, data) {
|
||||
|
||||
return this.players.initPlayer(message, cid);
|
||||
}
|
||||
|
||||
export const exportDef = {
|
||||
name: "joinChannel",
|
||||
object: joinChannel
|
||||
};
|
||||
+91
-31
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* @file lastfm command — Link Last.fm accounts, scrobble, view profiles, leaderboards, and more
|
||||
* @module commands/lastfm
|
||||
* @description Last.fm integration command supporting account linking, scrobbling,
|
||||
* profile viewing, leaderboards, whoknows, and playlist playback.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -14,6 +15,10 @@ import { ERROR_COLOR, EMOJI_REMOVE_TIMEOUT } from "../src/constants/UI.mjs";
|
||||
|
||||
const VALID_PERIODS = ["7day", "1month", "3month", "6month", "12month", "overall"];
|
||||
|
||||
/**
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the lastfm command.
|
||||
*/
|
||||
export const command = new CommandBuilder()
|
||||
.setName("lastfm")
|
||||
.setDescription("Link your Last.fm account, toggle scrobbling, or view your profile.", "commands.lastfm")
|
||||
@@ -49,6 +54,13 @@ export const command = new CommandBuilder()
|
||||
.setRequired(false)
|
||||
);
|
||||
|
||||
/**
|
||||
* Return an embed indicating Last.fm is not configured.
|
||||
* @private
|
||||
* @param {object} ctx - The bot (Remix) instance context.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @returns {{ embeds: EmbedBuilder[] }} Error embed payload.
|
||||
*/
|
||||
function notConfigured(ctx, msg) {
|
||||
return {
|
||||
embeds: [new EmbedBuilder()
|
||||
@@ -57,6 +69,14 @@ function notConfigured(ctx, msg) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an embed indicating the user has not linked their Last.fm account.
|
||||
* @private
|
||||
* @param {object} ctx - The bot (Remix) instance context.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {string} prefix - The guild's command prefix.
|
||||
* @returns {{ embeds: EmbedBuilder[] }} Error embed payload.
|
||||
*/
|
||||
function notLinked(ctx, msg, prefix) {
|
||||
return {
|
||||
embeds: [new EmbedBuilder()
|
||||
@@ -67,6 +87,12 @@ function notLinked(ctx, msg, prefix) {
|
||||
|
||||
const SIMPLE_CATEGORIES = ["loved", "top", "recent", "albums", "artists"];
|
||||
|
||||
/**
|
||||
* Build a Last.fm track metadata object from a track.
|
||||
* @private
|
||||
* @param {object} track - The track object with artist, name, and url.
|
||||
* @returns {{ source: string, artist: string, name: string, url: string }} Track metadata.
|
||||
*/
|
||||
function buildLastFmTrackMeta(track) {
|
||||
return {
|
||||
source: "lastfm",
|
||||
@@ -76,6 +102,15 @@ function buildLastFmTrackMeta(track) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a Last.fm track to playable audio via a search provider.
|
||||
* @private
|
||||
* @async
|
||||
* @param {object} player - The player instance.
|
||||
* @param {object} track - The Last.fm track with query and metadata.
|
||||
* @param {string} [resolveProvider="yt"] - The provider to resolve with.
|
||||
* @returns {Promise<object[]|null>} Array of resolved track data, or null on failure.
|
||||
*/
|
||||
async function resolveLastFmTrack(player, track, resolveProvider = "yt") {
|
||||
const data = await player.workerJob("generalQuery", {
|
||||
query: track.query,
|
||||
@@ -90,9 +125,10 @@ async function resolveLastFmTrack(player, track, resolveProvider = "yt") {
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract current track info from the player for Last.fm lookups.
|
||||
* @param {object} player
|
||||
* @returns {{ artist: string|null, name: string|null, album: string|null, track: object|null } | null}
|
||||
* Extract Last.fm-relevant info from the player's current track.
|
||||
* @private
|
||||
* @param {object} player - The player instance.
|
||||
* @returns {{ artist: string|null, name: string|null, album: string|null, track: object|null }} Extracted track info.
|
||||
*/
|
||||
function extractCurrentTrack(player) {
|
||||
const track = player?.queue?.getCurrent();
|
||||
@@ -104,9 +140,11 @@ function extractCurrentTrack(player) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all human member IDs from a guild for whoknows lookups.
|
||||
* @param {object} guild
|
||||
* @returns {Promise<Array<string>>}
|
||||
* Get all non-bot user IDs in a guild.
|
||||
* @private
|
||||
* @async
|
||||
* @param {object} guild - The Discord guild object.
|
||||
* @returns {Promise<string[]>} Array of user ID strings.
|
||||
*/
|
||||
async function getGuildLinkedUsers(guild) {
|
||||
const memberIds = [];
|
||||
@@ -124,10 +162,11 @@ async function getGuildLinkedUsers(guild) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a period string from token option or message content.
|
||||
* @param {object} data
|
||||
* @param {object} msg
|
||||
* @returns {string} A valid period string
|
||||
* Extract a valid time period from command data or message content.
|
||||
* @private
|
||||
* @param {object} data - Parsed command data.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @returns {string} The period string, defaults to "overall".
|
||||
*/
|
||||
function extractPeriod(data, msg) {
|
||||
let raw = data.get("token")?.value;
|
||||
@@ -144,18 +183,15 @@ function extractPeriod(data, msg) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a Last.fm category (loved/top/recent/playlist) into playable tracks.
|
||||
* Shared between `%lastfm play <cat>` and `%play lastfm:<cat>`.
|
||||
*
|
||||
* @param {object} ctx - The command `this` context (has .lastfm, .getPlayer, .handler, .t)
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The message object
|
||||
* @param {string} userId - The Discord user ID
|
||||
* @param {string} category - "loved", "top", "recent", or "playlist"
|
||||
* @param {object} [options]
|
||||
* @param {string} [options.period] - Period for top tracks
|
||||
* @param {number} [options.limit] - Max tracks
|
||||
* @param {string|number} [options.playlistId] - Playlist number or URL (for category="playlist")
|
||||
* @param {string} [options.resolveProvider] - Provider to search on when resolving tracks (e.g. "td" for Tidal, "sp" for Spotify). Default: "yt"
|
||||
* Fetch and play tracks from a Last.fm category (loved, top, recent, albums, artists, playlist).
|
||||
* @async
|
||||
* @param {object} ctx - The bot (Remix) instance context.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {string} userId - The Discord user ID.
|
||||
* @param {string} category - The Last.fm category to play.
|
||||
* @param {object} [options={}] - Additional options.
|
||||
* @param {string} [options.resolveProvider="yt"] - Provider to resolve tracks with.
|
||||
* @param {string} [options.playlistId] - Playlist number for playlist category.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function playLastFmCategory(ctx, msg, userId, category, options = {}) {
|
||||
@@ -267,8 +303,11 @@ export async function playLastFmCategory(ctx, msg, userId, category, options = {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse "playlist N" from message text after "play" keyword.
|
||||
* @returns {{ category: string, playlistId?: string|number }}
|
||||
* Parse play subcommand arguments for category and provider.
|
||||
* @private
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} data - Parsed command data.
|
||||
* @returns {{ category: string, resolveProvider?: string, playlistId?: string, showAllCategories?: boolean, invalidCategory?: string }} Parsed args.
|
||||
*/
|
||||
function parsePlayArgs(msg, data) {
|
||||
let raw = data.get("token")?.value;
|
||||
@@ -337,9 +376,11 @@ function parsePlayArgs(msg, data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the lastfm command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* Run handler for the lastfm command.
|
||||
* Routes to the appropriate subcommand based on the action option.
|
||||
*
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing action, user, and token options.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg, data) {
|
||||
@@ -2458,6 +2499,16 @@ export async function run(msg, data) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an embed listing tracks with optional playcount.
|
||||
* @private
|
||||
* @param {string} username - The Last.fm username.
|
||||
* @param {string} title - The list title.
|
||||
* @param {object[]} tracks - Array of track objects with name, artist, url, and optional playcount.
|
||||
* @param {boolean} [showPlaycount=false] - Whether to show play counts.
|
||||
* @param {string} [prefix="%"] - The command prefix for the footer hint.
|
||||
* @returns {EmbedBuilder} The constructed embed.
|
||||
*/
|
||||
function buildTrackList(username, title, tracks, showPlaycount = false, prefix = "%") {
|
||||
const lines = tracks.map((t, i) => {
|
||||
const num = String(i + 1).padStart(2, " ");
|
||||
@@ -2477,6 +2528,14 @@ function buildTrackList(username, title, tracks, showPlaycount = false, prefix =
|
||||
.setFooter({ text: `💡 Use ${prefix}lastfm play loved to play these!` });
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a scrobble leaderboard embed for a given page.
|
||||
* @private
|
||||
* @param {object} lb - Leaderboard data with entries and perPage.
|
||||
* @param {number} pageIdx - The page index (0-based).
|
||||
* @param {string} prefix - The command prefix for the footer hint.
|
||||
* @returns {EmbedBuilder} The constructed embed.
|
||||
*/
|
||||
function buildLeaderboardEmbed(lb, pageIdx, prefix) {
|
||||
const MEDALS = ["🥇", "🥈", "🥉"];
|
||||
const startRank = pageIdx * lb.perPage;
|
||||
@@ -2499,9 +2558,10 @@ function buildLeaderboardEmbed(lb, pageIdx, prefix) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Format seconds into mm:ss or h:mm:ss.
|
||||
* @param {number} seconds
|
||||
* @returns {string}
|
||||
* Format seconds into a human-readable duration string (h:mm:ss or m:ss).
|
||||
* @private
|
||||
* @param {number} seconds - Duration in seconds.
|
||||
* @returns {string} Formatted duration, or empty string if invalid.
|
||||
*/
|
||||
function formatDuration(seconds) {
|
||||
if (!seconds || seconds <= 0) return "";
|
||||
|
||||
+44
-46
@@ -1,13 +1,14 @@
|
||||
/**
|
||||
* @file leave.mjs — Leave the current voice channel and stop playback
|
||||
* @module commands.leave
|
||||
* @module commands/leave
|
||||
* @description Make the bot leave a voice channel, with 24/7 cleanup and player destruction.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { logger } from "../src/constants/Logger.mjs";
|
||||
import { getGlobalColor, cleanId } from "../src/MessageHandler.mjs";
|
||||
import { get247ChannelMode } from "../src/constants/Helpers247.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the leave/stop command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("leave")
|
||||
.setDescription("Make the bot leave a voice channel", "commands.leave")
|
||||
@@ -20,6 +21,13 @@ export const command = new CommandBuilder()
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Resolve the guild ID from a player, its map key, or the channel object.
|
||||
* @param {Player} player - The player instance.
|
||||
* @param {string} mapKey - The key under which the player is stored in playerMap.
|
||||
* @param {import('@fluxerjs/core').Client} client - The Discord/Fluxer client.
|
||||
* @returns {string} Cleaned guild ID, or empty string if unresolvable.
|
||||
*/
|
||||
function resolvePlayerGuildId(player, mapKey, client) {
|
||||
const direct = cleanId(player?._guildId);
|
||||
if (direct) return direct;
|
||||
@@ -30,9 +38,11 @@ function resolvePlayerGuildId(player, mapKey, client) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the leave command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* Run handler for the leave/stop command.
|
||||
* Finds the target player, removes 24/7 if enabled, destroys the player,
|
||||
* and sends a confirmation message.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing option values.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg, data) {
|
||||
@@ -67,7 +77,7 @@ export async function run(msg, data) {
|
||||
}
|
||||
const channelList = guildPlayers.map(([mapKey, p]) => {
|
||||
const id = cleanId(p._channelId ?? mapKey);
|
||||
return id ? `<#${id}>` : "`unknown`";
|
||||
return id ? `<#${id}>` : "\`unknown\`";
|
||||
});
|
||||
return msg.reply(
|
||||
this.t(msg, "responses.leave.specifyChannel", {
|
||||
@@ -89,7 +99,7 @@ export async function run(msg, data) {
|
||||
}
|
||||
const channelList = guildPlayers.map(([mapKey, p]) => {
|
||||
const id = cleanId(p._channelId ?? mapKey);
|
||||
return id ? `<#${id}>` : "`unknown`";
|
||||
return id ? `<#${id}>` : "\`unknown\`";
|
||||
});
|
||||
return msg.reply(
|
||||
this.t(msg, "responses.leave.noPlayerInChannel", {
|
||||
@@ -104,6 +114,8 @@ export async function run(msg, data) {
|
||||
const activeChannelId = cleanId(player._channelId) || targetChannelId;
|
||||
const homeChannelId = cleanId(player._home247Channel) || activeChannelId;
|
||||
|
||||
// If this channel has 24/7 enabled, remove it from the saved list first.
|
||||
// This prevents the disconnect handler from scheduling an auto-rejoin loop.
|
||||
const set = this.getSettings(msg);
|
||||
const raw = set?.get("stay_247");
|
||||
const ch247 = (!raw || raw === "none")
|
||||
@@ -112,44 +124,30 @@ export async function run(msg, data) {
|
||||
? new Set(raw.map(id => cleanId(id)).filter(Boolean))
|
||||
: new Set([cleanId(raw)]);
|
||||
|
||||
const is247 = ch247.has(activeChannelId) || ch247.has(homeChannelId);
|
||||
const was247 = ch247.has(activeChannelId) || ch247.has(homeChannelId);
|
||||
|
||||
if (is247) {
|
||||
const matchChannel = ch247.has(homeChannelId) ? homeChannelId
|
||||
: ch247.has(activeChannelId) ? activeChannelId
|
||||
: null;
|
||||
const mode = matchChannel ? get247ChannelMode(set, matchChannel) : "off";
|
||||
const prefix = this.handler.getPrefix(msg.message?.guildId ?? msg.channel?.guild?.id);
|
||||
|
||||
this.markIntentionalLeave(activeChannelId);
|
||||
this.players.playerMap.delete(activeChannelId);
|
||||
this.players._unindexPlayer(player._guildId, activeChannelId);
|
||||
if (activeChannelId !== targetChannelId) this.players.playerMap.delete(targetChannelId);
|
||||
if (homeChannelId !== activeChannelId) this.players.playerMap.delete(homeChannelId);
|
||||
|
||||
const pendingScrobble = this.players._pendingScrobbleTimers?.get(activeChannelId);
|
||||
if (pendingScrobble) {
|
||||
clearTimeout(pendingScrobble.timer);
|
||||
this.players._pendingScrobbleTimers.delete(activeChannelId);
|
||||
}
|
||||
|
||||
await player.leave().catch(() => {});
|
||||
player.destroy();
|
||||
|
||||
if (mode === "auto") {
|
||||
msg.reply(this.t(msg, "responses.leave.leftRejoin247", { channel: targetChannelId, prefix }));
|
||||
const rejoinDelay = this.config?.timers?.leave247RejoinDelay ?? 5000;
|
||||
setTimeout(() => {
|
||||
if (this._spawnPlayer) {
|
||||
this._spawnPlayer(guildId, homeChannelId).catch(e =>
|
||||
logger.warn("[leave] 247 rejoin failed for", homeChannelId, e.message)
|
||||
);
|
||||
}
|
||||
}, rejoinDelay);
|
||||
} else {
|
||||
msg.reply(this.t(msg, "responses.leave.left247On", { prefix }));
|
||||
}
|
||||
} else {
|
||||
await this.leaveChannel(activeChannelId, guildId, msg);
|
||||
if (was247) {
|
||||
const target = ch247.has(activeChannelId) ? activeChannelId : homeChannelId;
|
||||
ch247.delete(target);
|
||||
set.set("stay_247", ch247.size > 0 ? [...ch247] : "none");
|
||||
}
|
||||
|
||||
// Mark as intentional leave so the disconnect handler doesn't also try to rejoin
|
||||
this.markIntentionalLeave(activeChannelId);
|
||||
this.players.playerMap.delete(activeChannelId);
|
||||
this.players._unindexPlayer(player._guildId, activeChannelId);
|
||||
if (activeChannelId !== targetChannelId) this.players.playerMap.delete(targetChannelId);
|
||||
if (homeChannelId !== activeChannelId) this.players.playerMap.delete(homeChannelId);
|
||||
|
||||
const pendingScrobble = this.players._pendingScrobbleTimers?.get(activeChannelId);
|
||||
if (pendingScrobble) {
|
||||
clearTimeout(pendingScrobble.timer);
|
||||
this.players._pendingScrobbleTimers.delete(activeChannelId);
|
||||
}
|
||||
|
||||
await player.leave().catch(() => {});
|
||||
player.destroy();
|
||||
|
||||
const label247 = was247 ? " 24/7 disabled." : "";
|
||||
msg.reply(this.t(msg, "responses.leave.left") + label247);
|
||||
}
|
||||
+11
-5
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file list.mjs — Display the current song queue with pagination
|
||||
* @module commands.list
|
||||
* @module commands/list
|
||||
* @description List the songs in the queue of the current voice channel with pagination.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -10,6 +10,10 @@ import { EmbedBuilder } from "@fluxerjs/core";
|
||||
const PAGE_SIZE = 10;
|
||||
const SESSION_MS = 30 * 1000;
|
||||
|
||||
/**
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the list (queue) command.
|
||||
*/
|
||||
export const command = new CommandBuilder()
|
||||
.setName("list")
|
||||
.setDescription("List the songs in the queue of your current voice channel.", "commands.list")
|
||||
@@ -22,9 +26,11 @@ export const command = new CommandBuilder()
|
||||
);
|
||||
|
||||
/**
|
||||
* Execute the list command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* Run handler for the list command.
|
||||
* Displays the current queue with pagination, showing now-playing info and track list.
|
||||
*
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing the page option.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message, data) {
|
||||
|
||||
+8
-5
@@ -1,12 +1,13 @@
|
||||
/**
|
||||
* @file loop.mjs — Toggle loop mode for the queue or current track
|
||||
* @module commands.loop
|
||||
* @module commands/loop
|
||||
* @description Toggle looping of the current song or the entire queue.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the loop command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("loop")
|
||||
.setDescription("Toggle the looping of your queue/song.", "commands.loop")
|
||||
@@ -18,9 +19,11 @@ export const command = new CommandBuilder()
|
||||
.setRequired(true));
|
||||
|
||||
/**
|
||||
* Execute the loop command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* @async
|
||||
* Run handler for the loop command.
|
||||
* Toggles loop mode for the queue or the current song.
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing the loop type option.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message, data) {
|
||||
|
||||
+27
-4
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file lyrics.mjs — Fetch and display lyrics for the current or specified song
|
||||
* @module commands.lyrics
|
||||
* @module commands/lyrics
|
||||
* @description Display synced or unsynced lyrics for the currently playing track from NodeLink.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -10,18 +10,24 @@ import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
import { Utils } from "../src/Utils.mjs";
|
||||
import { EMOJI_REMOVE_TIMEOUT } from "../src/constants/UI.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the lyrics command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("lyrics")
|
||||
.setDescription("Display synced lyrics from NodeLink", "commands.lyrics")
|
||||
.addAliases("lyric", "ly")
|
||||
.setCategory("music");
|
||||
|
||||
/** @private @type {string[]} Loading animation frames. */
|
||||
const LOADING_FRAMES = ["◐", "◓", "◑", "◒"];
|
||||
/** @private @type {number} Session timeout in milliseconds (3 minutes). */
|
||||
const SESSION_MS = 180_000;
|
||||
|
||||
/**
|
||||
* Execute the lyrics command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* @async
|
||||
* Run handler for the lyrics command.
|
||||
* Fetches lyrics for the currently playing track and displays them with
|
||||
* paginated embeds and reaction-based navigation.
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message) {
|
||||
@@ -126,6 +132,13 @@ export async function run(message) {
|
||||
let currentPage = 0;
|
||||
let emojiRemoveTimeout;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Build the embed payload for a specific lyrics page.
|
||||
* @param {number} pageIdx - Zero-based page index.
|
||||
* @param {boolean} [expired=false] - Whether navigation controls have expired.
|
||||
* @returns {object} Embed payload for message reply/edit.
|
||||
*/
|
||||
const buildContent = (pageIdx, expired = false) => {
|
||||
const headerLine = `by *${artist}*${syncIndicator} • Page ${pageIdx + 1}/${totalPages}`;
|
||||
const descBody = pages[pageIdx];
|
||||
@@ -150,6 +163,11 @@ export async function run(message) {
|
||||
await msg.message.react(emoji).catch(() => {});
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Remove all navigation reactions from the lyrics message.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const clearReactions = async () => {
|
||||
try {
|
||||
await msg.message.removeAllReactions();
|
||||
@@ -160,6 +178,11 @@ export async function run(message) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Reset the emoji removal timeout timer for the lyrics session.
|
||||
* @returns {void}
|
||||
*/
|
||||
const resetEmojiTimer = () => {
|
||||
clearTimeout(emojiRemoveTimeout);
|
||||
emojiRemoveTimeout = setTimeout(async () => {
|
||||
|
||||
+8
-5
@@ -1,10 +1,11 @@
|
||||
/**
|
||||
* @file move.mjs — Move a track from one position to another in the queue
|
||||
* @module commands.move
|
||||
* @module commands/move
|
||||
* @description Move a track from one position to another in the queue.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the move command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("move")
|
||||
.setDescription("Move a track from one position to another in the queue.", "commands.move")
|
||||
@@ -22,9 +23,11 @@ export const command = new CommandBuilder()
|
||||
);
|
||||
|
||||
/**
|
||||
* Execute the move command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* @async
|
||||
* Run handler for the move command.
|
||||
* Moves a track in the queue from one position to another.
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing from/to positions.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message, data) {
|
||||
|
||||
+9
-5
@@ -1,20 +1,24 @@
|
||||
/**
|
||||
* @file np.mjs — Show now-playing information for the current track
|
||||
* @module commands.np
|
||||
* @module commands/np
|
||||
* @description Display the currently playing track name and URL.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the np (now playing) command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("np")
|
||||
.setDescription("Request the name and url of the currently playing song.", "commands.np")
|
||||
.addAliases("current", "nowplaying");
|
||||
.addAliases("current", "nowplaying")
|
||||
.setCategory("music");
|
||||
|
||||
/**
|
||||
* Execute the np command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @async
|
||||
* Run handler for the np command.
|
||||
* Fetches and displays the now-playing status with track title and thumbnail.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg) {
|
||||
|
||||
+7
-4
@@ -1,20 +1,23 @@
|
||||
/**
|
||||
* @file pause.mjs — Pause the current playback
|
||||
* @module commands.pause
|
||||
* @module commands/pause
|
||||
* @description Pause the currently playing track.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the pause command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("pause")
|
||||
.setDescription("Pause the playback in your voice channel", "commands.pause")
|
||||
.setCategory("music");
|
||||
|
||||
/**
|
||||
* Execute the pause command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* @async
|
||||
* Run handler for the pause command.
|
||||
* Pauses playback in the user's voice channel.
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message) {
|
||||
|
||||
+23
-8
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* @file play.mjs — Play a song, playlist, or Last.fm URL — the main music command with provider selection
|
||||
* @module commands.play
|
||||
* @module commands/play
|
||||
* @description Play a song or playlist from a URL or search query.
|
||||
* Supports YouTube, Spotify, SoundCloud, Deezer, Apple Music, Tidal, and Last.fm integration.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -15,9 +16,10 @@ import { ERROR_COLOR } from "../src/constants/UI.mjs";
|
||||
const LASTFM_PLAY_CATEGORIES = ["loved", "top", "recent", "albums"];
|
||||
|
||||
/**
|
||||
* Parse a lastfm query like "td:top", "sp:loved", "playlist 1", or just "top".
|
||||
* Returns { category, resolveProvider } where resolveProvider is the
|
||||
* search provider to use for resolving tracks (e.g. "td" for Tidal).
|
||||
* Parse a Last.fm sub-provider string (e.g. "lf:loved", "sp:top").
|
||||
* @private
|
||||
* @param {string} query - The raw query string to parse.
|
||||
* @returns {{ category: string, resolveProvider: string|null, invalidCategory?: string }} Parsed components.
|
||||
*/
|
||||
function parseLastFmSubProvider(query) {
|
||||
const value = query.trim();
|
||||
@@ -61,6 +63,13 @@ function parseLastFmSubProvider(query) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse a Last.fm track query into artist and name components.
|
||||
* Supports "title by artist" and "artist - title" formats.
|
||||
* @private
|
||||
* @param {string} raw - The raw query string.
|
||||
* @returns {{ artist: string, name: string, source: string }|null} Parsed track info or null.
|
||||
*/
|
||||
function parseLastFmTrackQuery(raw) {
|
||||
const value = String(raw ?? "").trim();
|
||||
if (!value) return null;
|
||||
@@ -86,6 +95,10 @@ function parseLastFmTrackQuery(raw) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the play command.
|
||||
*/
|
||||
export const command = new CommandBuilder()
|
||||
.setName("play")
|
||||
.setId("play")
|
||||
@@ -125,9 +138,11 @@ export const command = new CommandBuilder()
|
||||
.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
|
||||
* Run handler for the play command.
|
||||
* Handles URL detection, Last.fm integration, provider selection, and track searching.
|
||||
*
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing query and provider options.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message, data) {
|
||||
|
||||
+53
-5
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* @file player.mjs — Interactive player control panel with playback buttons and now-playing display
|
||||
* @module commands.player
|
||||
* @module commands/player
|
||||
* @description Create an interactive player control panel with live progress, reaction controls,
|
||||
* and embedded lyrics viewer.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -10,11 +11,13 @@ import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
import { EMOJI_REMOVE_TIMEOUT } from "../src/constants/UI.mjs";
|
||||
import { logger } from "../src/constants/Logger.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the player command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("player")
|
||||
.setDescription("Create an interactive player control panel with live progress", "commands.player")
|
||||
.setCategory("music");
|
||||
|
||||
/** @private @type {Object.<string, string>} Emoji indicators for player states. */
|
||||
const STATES = {
|
||||
playing: "🎵",
|
||||
paused: "⏸️",
|
||||
@@ -22,6 +25,7 @@ const STATES = {
|
||||
loading: "⏳"
|
||||
};
|
||||
|
||||
/** @private @type {Object.<string, {emoji: string, action: string, desc: string}>} Available control button definitions. */
|
||||
const CONTROLS = {
|
||||
prev: { emoji: "⏮️", action: "previous", desc: "Previous" },
|
||||
play: { emoji: "▶️", action: "resume", desc: "Play" },
|
||||
@@ -37,6 +41,7 @@ const CONTROLS = {
|
||||
close: { emoji: "❌", action: "close", desc: "Close" }
|
||||
};
|
||||
|
||||
/** @private @type {Object.<string, string>} Progress bar character set. */
|
||||
const PROGRESS = {
|
||||
filled: "▰",
|
||||
empty: "▱",
|
||||
@@ -47,8 +52,11 @@ const PROGRESS = {
|
||||
|
||||
|
||||
/**
|
||||
* Execute the player command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @async
|
||||
* Run handler for the player command.
|
||||
* Creates an interactive embed panel with playback controls, progress bar,
|
||||
* volume display, and an embedded lyrics viewer.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg) {
|
||||
@@ -65,6 +73,12 @@ export async function run(msg) {
|
||||
const allControls = controlsLayout.flat();
|
||||
const controlEmojis = allControls.map(c => c.emoji);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Build the player panel embed with current state, progress, volume, and loop info.
|
||||
* @param {object} [state={}] - Optional state override with a message field.
|
||||
* @returns {EmbedBuilder} The constructed embed builder.
|
||||
*/
|
||||
const buildEmbed = (state = {}) => {
|
||||
const current = player.queue.getCurrent();
|
||||
const isPlaying = !player.paused && current;
|
||||
@@ -162,6 +176,11 @@ export async function run(msg) {
|
||||
let lyricsUnobserve = null;
|
||||
let lyricsEmojiTimeout = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Remove all control reactions from the player panel message.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const clearReactions = async () => {
|
||||
try {
|
||||
await message.message.removeAllReactions();
|
||||
@@ -174,6 +193,11 @@ export async function run(msg) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Reset the emoji removal timeout for the player panel controls.
|
||||
* @returns {void}
|
||||
*/
|
||||
const resetEmojiTimer = () => {
|
||||
clearTimeout(emojiRemoveTimeout);
|
||||
emojiRemoveTimeout = setTimeout(async () => {
|
||||
@@ -184,6 +208,12 @@ export async function run(msg) {
|
||||
}, EMOJI_REMOVE_TIMEOUT);
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Remove navigation reactions from a lyrics message.
|
||||
* @param {object} lyricsMsg - The wrapped lyrics message with a .message property.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const clearLyricsReactions = async (lyricsMsg) => {
|
||||
if (!lyricsMsg?.message) return;
|
||||
try {
|
||||
@@ -197,6 +227,12 @@ export async function run(msg) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Rebuild and edit the player panel embed with updated state.
|
||||
* @param {object} [extra={}] - Additional state data to merge (e.g. status message).
|
||||
* @returns {void}
|
||||
*/
|
||||
const refresh = (extra = {}) => {
|
||||
const embed = buildEmbed(extra);
|
||||
message.edit({ embeds: [embed] }).catch(() => {});
|
||||
@@ -205,6 +241,14 @@ export async function run(msg) {
|
||||
|
||||
let _sessionClosed = false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @async
|
||||
* Tear down the entire player session: clear timers, remove listeners,
|
||||
* clean up reactions, and edit the embed to show the closed state.
|
||||
* @param {string} [reason="timeout"] - The reason for closing ("timeout", "user", "disconnected").
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const closeSession = async (reason = "timeout") => {
|
||||
if (_sessionClosed) return;
|
||||
_sessionClosed = true;
|
||||
@@ -245,6 +289,11 @@ export async function run(msg) {
|
||||
}).catch(() => {});
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Reset the session inactivity timeout timer.
|
||||
* @returns {void}
|
||||
*/
|
||||
const resetTimeout = () => {
|
||||
clearTimeout(sessionTimeout);
|
||||
sessionTimeout = setTimeout(() => closeSession("timeout"), timeout);
|
||||
@@ -315,7 +364,6 @@ export async function run(msg) {
|
||||
break;
|
||||
|
||||
case "stop":
|
||||
await player._stopMediaPlayer();
|
||||
player.queue.reset();
|
||||
reply = this.t(msg, "responses.player.stoppedCleared");
|
||||
break;
|
||||
|
||||
+12
-5
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* @file playnext.mjs — Add a song to the top of the queue (play next)
|
||||
* @module commands.playnext
|
||||
* @module commands/playnext
|
||||
* @description Play a song and insert it at the top of the queue instead of the end.
|
||||
* Supports inline provider prefixes and flag-based provider selection.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -9,6 +10,10 @@ import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
import { PROVIDER_CHOICES, parseInlineProvider } from "../src/constants/providers.mjs";
|
||||
|
||||
|
||||
/**
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the playnext command.
|
||||
*/
|
||||
export const command = new CommandBuilder()
|
||||
.setName("playnext")
|
||||
.setId("playnext")
|
||||
@@ -34,9 +39,11 @@ export const command = new CommandBuilder()
|
||||
.addAlias("pn");
|
||||
|
||||
/**
|
||||
* Execute the playnext command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* Run handler for the playnext command.
|
||||
* Searches for a track and adds the result to the top of the queue.
|
||||
*
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing query and provider options.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message, data) {
|
||||
|
||||
+21
-5
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file radio.mjs — Play a radio stream or search for radio stations
|
||||
* @module commands.radio
|
||||
* @module commands/radio
|
||||
* @description Play internet radio stations with interactive station selection via reactions.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -10,6 +10,10 @@ import { logger } from "../src/constants/Logger.mjs";
|
||||
import { NUMBER_EMOJIS, CANCEL_EMOJI, PREV_EMOJI, NEXT_EMOJI } from "../src/constants/UI.mjs";
|
||||
|
||||
|
||||
/**
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the radio command. Returns null if no stations configured.
|
||||
*/
|
||||
export const command = function() {
|
||||
if (!this.config.radio?.length) return null;
|
||||
return new CommandBuilder()
|
||||
@@ -25,9 +29,11 @@ export const command = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Execute the radio command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* Run handler for the radio command.
|
||||
* Lists stations, plays a named station, or starts the default station.
|
||||
*
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing the station option.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg, data) {
|
||||
@@ -131,6 +137,16 @@ export async function run(msg, data) {
|
||||
return playStation(this, msg, radios[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Play a radio station on the player, switching if one is already playing.
|
||||
* @private
|
||||
* @async
|
||||
* @param {object} ctx - The bot (Remix) instance context.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} radio - The radio station config object.
|
||||
* @param {object|null} [editTarget=null] - Optional message to edit instead of sending a new reply.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function playStation(ctx, msg, radio, editTarget = null) {
|
||||
const p = await ctx.getPlayer(msg, true, true, true);
|
||||
if (!p) return;
|
||||
|
||||
+55
-5
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file reload.mjs — Hot-reload commands without restarting the bot (owner-only)
|
||||
* @module commands.reload
|
||||
* @module commands/reload
|
||||
* @description Owner-only command to hot-reload commands, source modules, or audio modules at runtime.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -10,6 +10,10 @@ import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
/**
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the reload command (owner-only).
|
||||
*/
|
||||
export const command = new CommandBuilder()
|
||||
.setName("reload")
|
||||
.setDescription("Reload commands, src modules, or audio modules. Leave blank to see all targets.")
|
||||
@@ -25,6 +29,15 @@ export const command = new CommandBuilder()
|
||||
const __dirname = path.dirname(new URL(import.meta.url).pathname);
|
||||
const ROOT = path.resolve(__dirname, "..");
|
||||
|
||||
/**
|
||||
* Reload a single command by name, removing the old one and re-importing its file.
|
||||
* @private
|
||||
* @async
|
||||
* @param {object} ctx - The bot (Remix) instance context.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {string} name - The command name to reload.
|
||||
* @returns {Promise<{ ok: boolean, msg: string }>} Result with success status and message.
|
||||
*/
|
||||
async function reloadCommand(ctx, msg, name) {
|
||||
if (name === "index")
|
||||
return { ok: false, msg: ctx.t(msg, "responses.reload.indexNoReload") };
|
||||
@@ -61,6 +74,16 @@ async function reloadCommand(ctx, msg, name) {
|
||||
return { ok: true, msg: ctx.t(msg, "responses.reload.reloaded", { name }) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload a single source module by re-importing its file.
|
||||
* @private
|
||||
* @async
|
||||
* @param {object} ctx - The bot (Remix) instance context.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {string} filePath - Absolute path to the module file.
|
||||
* @param {string} label - Human-readable label for error messages.
|
||||
* @returns {Promise<{ ok: boolean, msg: string }>} Result with success status and message.
|
||||
*/
|
||||
async function reloadModule(ctx, msg, filePath, label) {
|
||||
if (!fs.existsSync(filePath))
|
||||
return { ok: false, msg: ctx.t(msg, "responses.reload.fileNotFound", { label }) };
|
||||
@@ -72,6 +95,12 @@ async function reloadModule(ctx, msg, filePath, label) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List all JS/MJS module files in a subdirectory.
|
||||
* @private
|
||||
* @param {string} subdir - The subdirectory name relative to project root.
|
||||
* @returns {Array<{ file: string, label: string }>} Array of file info objects.
|
||||
*/
|
||||
function allModuleFiles(subdir) {
|
||||
const dir = path.join(ROOT, subdir);
|
||||
if (!fs.existsSync(dir)) return [];
|
||||
@@ -80,6 +109,16 @@ function allModuleFiles(subdir) {
|
||||
.map(f => ({ file: path.join(dir, f), label: `${subdir}/${f}` }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display lines in a paginated embed with arrow navigation.
|
||||
* @private
|
||||
* @async
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {string} title - The embed title.
|
||||
* @param {string[]} lines - The lines of text to paginate.
|
||||
* @param {number} [pageSize=14] - Number of lines per page.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function showPaged(msg, title, lines, pageSize = 14) {
|
||||
const pages = [];
|
||||
for (let i = 0; i < lines.length; i += pageSize)
|
||||
@@ -115,6 +154,15 @@ async function showPaged(msg, title, lines, pageSize = 14) {
|
||||
setTimeout(() => { unsub?.(); }, 5 * 60_000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display reload results in a paginated embed.
|
||||
* @private
|
||||
* @async
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object[]} results - Array of { ok, msg } result objects.
|
||||
* @param {string} label - Category label for the title.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function showResults(msg, results, label) {
|
||||
const ok = results.filter(r => r.ok).length;
|
||||
const bad = results.filter(r => !r.ok).length;
|
||||
@@ -123,9 +171,11 @@ async function showResults(msg, results, label) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the reload command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* Run handler for the reload command.
|
||||
* Reloads commands, src modules, or audio modules based on the target option.
|
||||
*
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing the target option.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg, data) {
|
||||
|
||||
+8
-5
@@ -1,10 +1,11 @@
|
||||
/**
|
||||
* @file remove.mjs — Remove a specific song from the queue by position
|
||||
* @module commands.remove
|
||||
* @module commands/remove
|
||||
* @description Remove a specific track from the queue by its position.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the remove command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("remove")
|
||||
.setDescription("Remove a specific song from the queue.", "commands.remove")
|
||||
@@ -15,9 +16,11 @@ export const command = new CommandBuilder()
|
||||
.setRequired(true));
|
||||
|
||||
/**
|
||||
* Execute the remove command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* @async
|
||||
* Run handler for the remove command.
|
||||
* Removes a track at the specified 1-based index from the queue.
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing the index option.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message, data) {
|
||||
|
||||
+10
-4
@@ -1,20 +1,26 @@
|
||||
/**
|
||||
* @file resume.mjs — Resume paused playback
|
||||
* @module commands.resume
|
||||
* @module commands/resume
|
||||
* @description Resume paused playback in the current voice channel.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
|
||||
/**
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the resume command.
|
||||
*/
|
||||
export const command = new CommandBuilder()
|
||||
.setName("resume")
|
||||
.setDescription("Resume the playback in your voice channel", "commands.resume")
|
||||
.setCategory("music");
|
||||
|
||||
/**
|
||||
* Execute the resume command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* Run handler for the resume command.
|
||||
* Resumes playback and sends a confirmation embed.
|
||||
*
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message) {
|
||||
|
||||
+20
-9
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file search.mjs — Search for songs with interactive selection menu
|
||||
* @module commands.search
|
||||
* @module commands/search
|
||||
* @description Search for tracks across providers and pick one to play via reaction selection.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -10,6 +10,7 @@ import { PROVIDER_CHOICES, PROVIDER_NAMES, parseInlineProvider } from "../src/co
|
||||
import { NUMBER_EMOJIS, CANCEL_EMOJI } from "../src/constants/UI.mjs";
|
||||
import { logger } from "../src/constants/Logger.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the search command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("search")
|
||||
.setDescription(
|
||||
@@ -37,9 +38,12 @@ export const command = new CommandBuilder()
|
||||
);
|
||||
|
||||
/**
|
||||
* Execute the search command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* @async
|
||||
* Run handler for the search command.
|
||||
* Searches for tracks, displays results as an embed with number reactions,
|
||||
* and adds the selected track to the queue.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing provider and query options.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg, data) {
|
||||
@@ -57,10 +61,12 @@ export async function run(msg, data) {
|
||||
if (!channel?.send) return;
|
||||
|
||||
/**
|
||||
* Build a search-result embed using EmbedBuilder.
|
||||
* @param {string} description
|
||||
* @param {string} [footerText]
|
||||
* @param {string} [authorLabel] - defaults to `name` (provider name)
|
||||
* @private
|
||||
* Build a search result embed.
|
||||
* @param {string} description - The embed description text.
|
||||
* @param {string|null} footerText - Optional footer text.
|
||||
* @param {string} [authorLabel=name] - The author field label (provider name).
|
||||
* @returns {EmbedBuilder} The constructed embed.
|
||||
*/
|
||||
const makeEmbed = (description, footerText, authorLabel = name) => {
|
||||
const b = new EmbedBuilder()
|
||||
@@ -113,6 +119,11 @@ export async function run(msg, data) {
|
||||
const channelId = rawMsg.channelId ?? rawMsg.channel_id ?? rawMsg.channel?.id;
|
||||
const msgId = rawMsg.id;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Remove all reactions from the search result message.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const clearReactions = async () => {
|
||||
try {
|
||||
await rawMsg.removeAllReactions();
|
||||
|
||||
+8
-5
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file seek.mjs — Seek to a specific position in the current track
|
||||
* @module commands.seek
|
||||
* @module commands/seek
|
||||
* @description Seek to a specific position in the currently playing track.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -9,6 +9,7 @@ import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
import { Utils } from "../src/Utils.mjs";
|
||||
import { ERROR_COLOR } from "../src/constants/UI.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the seek command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("seek")
|
||||
.setDescription("Seek to a specific position in the current track.", "commands.seek")
|
||||
@@ -20,9 +21,11 @@ export const command = new CommandBuilder()
|
||||
);
|
||||
|
||||
/**
|
||||
* Execute the seek command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* @async
|
||||
* Run handler for the seek command.
|
||||
* Parses a duration string and seeks the player to that position.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing the position option.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg, data) {
|
||||
|
||||
+24
-4
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file servers.mjs — List servers the bot is currently in (owner-only)
|
||||
* @module commands.servers
|
||||
* @module commands/servers
|
||||
* @description Owner-only command to list all servers the bot is in with pagination.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -9,6 +9,7 @@ import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
import { EMOJI_REMOVE_TIMEOUT } from "../src/constants/UI.mjs";
|
||||
import { logger } from "../src/constants/Logger.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the servers command (owner-only). */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("servers")
|
||||
.setDescription("Fetch a list of servers the bot is in")
|
||||
@@ -17,8 +18,10 @@ export const command = new CommandBuilder()
|
||||
|
||||
|
||||
/**
|
||||
* Execute the servers command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @async
|
||||
* Run handler for the servers command.
|
||||
* Lists all guilds the bot is a member of, with paginated embed and reaction navigation.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg) {
|
||||
@@ -60,6 +63,13 @@ export async function run(msg) {
|
||||
|
||||
let currentPage = 0;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Build the embed payload for a specific page of the server list.
|
||||
* @param {number} pageIdx - Zero-based page index.
|
||||
* @param {boolean} [expired=false] - Whether the reaction controls have expired.
|
||||
* @returns {object} Embed payload for message reply/edit.
|
||||
*/
|
||||
const buildPageContent = (pageIdx, expired = false) => {
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(getGlobalColor())
|
||||
@@ -90,6 +100,11 @@ export async function run(msg) {
|
||||
await replyMsg.message.react(emoji).catch(() => {});
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Remove all navigation reactions from the reply message.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const clearReactions = async () => {
|
||||
try {
|
||||
await replyMsg.message.removeAllReactions();
|
||||
@@ -102,6 +117,11 @@ export async function run(msg) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Reset the emoji removal timeout timer.
|
||||
* @returns {void}
|
||||
*/
|
||||
const resetTimer = () => {
|
||||
clearTimeout(emojiTimeout);
|
||||
emojiTimeout = setTimeout(async () => {
|
||||
|
||||
+346
-428
File diff suppressed because it is too large.
Load diff
+10
-4
@@ -1,20 +1,26 @@
|
||||
/**
|
||||
* @file shuffle.mjs — Shuffle the current queue
|
||||
* @module commands.shuffle
|
||||
* @module commands/shuffle
|
||||
* @description Randomly re-order the tracks in the playback queue.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
|
||||
/**
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the shuffle command.
|
||||
*/
|
||||
export const command = new CommandBuilder()
|
||||
.setName("shuffle")
|
||||
.setDescription("Re-orders the queue randomly.", "commands.shuffle")
|
||||
.setCategory("music");
|
||||
|
||||
/**
|
||||
* Execute the shuffle command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* Run handler for the shuffle command.
|
||||
* Shuffles the queue and sends a confirmation embed.
|
||||
*
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message) {
|
||||
|
||||
+7
-4
@@ -1,12 +1,13 @@
|
||||
/**
|
||||
* @file skip.mjs — Skip the currently playing song
|
||||
* @module commands.skip
|
||||
* @module commands/skip
|
||||
* @description Skip the currently playing track.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the skip command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("skip")
|
||||
.setDescription("Skip the current playing song.", "commands.skip")
|
||||
@@ -14,8 +15,10 @@ export const command = new CommandBuilder()
|
||||
.setCategory("music");
|
||||
|
||||
/**
|
||||
* Execute the skip command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* @async
|
||||
* Run handler for the skip command.
|
||||
* Skips the current track and shows which track was skipped.
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message) {
|
||||
|
||||
+72
-4
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file stats.mjs — Display bot statistics — uptime, servers, users, and memory usage
|
||||
* @module commands.stats
|
||||
* @module commands/stats
|
||||
* @description Display bot statistics including guild count, user count, uptime, and ping.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -9,6 +9,10 @@ import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
import { logger } from "../src/constants/Logger.mjs";
|
||||
|
||||
/**
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the stats command.
|
||||
*/
|
||||
export const command = new CommandBuilder()
|
||||
.setName("stats")
|
||||
.setDescription("Display stats about the bot like the uptime.", "commands.stats")
|
||||
@@ -21,6 +25,13 @@ let cachedUserCount = null;
|
||||
let cacheExpiresAt = 0;
|
||||
let inflightPromise = null;
|
||||
|
||||
/**
|
||||
* Run tasks with a concurrency limit.
|
||||
* @private
|
||||
* @param {number} limit - Maximum number of concurrent tasks.
|
||||
* @param {Function[]} tasks - Array of task functions to execute.
|
||||
* @returns {Promise<unknown[]>} Array of task results.
|
||||
*/
|
||||
async function pool(limit, tasks) {
|
||||
const results = [];
|
||||
const executing = new Set();
|
||||
@@ -33,6 +44,13 @@ async function pool(limit, tasks) {
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the total member count for a guild by paginating through members.
|
||||
* @private
|
||||
* @async
|
||||
* @param {object} guild - The Discord guild object.
|
||||
* @returns {Promise<number>} Total member count.
|
||||
*/
|
||||
async function fetchGuildMemberCount(guild) {
|
||||
try {
|
||||
let after = undefined;
|
||||
@@ -58,6 +76,13 @@ async function fetchGuildMemberCount(guild) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the cached total user count across all guilds.
|
||||
* @private
|
||||
* @async
|
||||
* @param {object} client - The Discord client instance.
|
||||
* @returns {Promise<number>} Total user count.
|
||||
*/
|
||||
async function refreshUserCount(client) {
|
||||
const guilds = [...client.guilds.values()];
|
||||
const counts = await pool(10, guilds.map(g => () => fetchGuildMemberCount(g)));
|
||||
@@ -67,12 +92,24 @@ async function refreshUserCount(client) {
|
||||
return cachedUserCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total user count, using cache if still valid or refreshing if expired.
|
||||
* @private
|
||||
* @param {object} client - The Discord client instance.
|
||||
* @returns {Promise<number>} Total user count.
|
||||
*/
|
||||
function getUserCount(client) {
|
||||
if (cachedUserCount !== null && Date.now() < cacheExpiresAt) return Promise.resolve(cachedUserCount);
|
||||
if (!inflightPromise) inflightPromise = refreshUserCount(client);
|
||||
return inflightPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count players with active voice connections.
|
||||
* @private
|
||||
* @param {Map} playerMap - The player map from PlayerManager.
|
||||
* @returns {number} Number of live connected players.
|
||||
*/
|
||||
function getLivePlayerCount(playerMap) {
|
||||
let live = 0;
|
||||
|
||||
@@ -101,6 +138,13 @@ function getLivePlayerCount(playerMap) {
|
||||
let cachedGuildCount = null;
|
||||
let guildCacheExpiresAt = 0;
|
||||
|
||||
/**
|
||||
* Get the total guild count via REST API with caching.
|
||||
* @private
|
||||
* @async
|
||||
* @param {object} client - The Discord client instance.
|
||||
* @returns {Promise<number>} Total guild count.
|
||||
*/
|
||||
async function getGuildCount(client) {
|
||||
if (cachedGuildCount !== null && Date.now() < guildCacheExpiresAt) {
|
||||
return cachedGuildCount;
|
||||
@@ -133,6 +177,27 @@ async function getGuildCount(client) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the stats embed with all bot information.
|
||||
* @private
|
||||
* @param {Function} t - Translation function.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} stats - Statistics data object.
|
||||
* @param {number} stats.guildCount - Number of guilds.
|
||||
* @param {number} stats.userCount - Number of users.
|
||||
* @param {number} stats.playerCount - Number of active players.
|
||||
* @param {number} stats.scrobbleCount - Total Last.fm scrobbles.
|
||||
* @param {number} stats.linkedUsers - Number of Last.fm linked users.
|
||||
* @param {number} stats.ping - Bot response ping in ms.
|
||||
* @param {string} stats.uptime - Formatted uptime string.
|
||||
* @param {string} stats.comHash - Git commit hash.
|
||||
* @param {string} stats.comLink - Git commit link URL.
|
||||
* @param {string} [stats.reason] - Last restart reason.
|
||||
* @param {string} [stats.footer] - Custom footer text.
|
||||
* @param {boolean} stats.loading - Whether data is still loading.
|
||||
* @param {boolean} stats.lastfmEnabled - Whether Last.fm integration is enabled.
|
||||
* @returns {EmbedBuilder} The constructed embed.
|
||||
*/
|
||||
function buildEmbed(t, msg, { guildCount, userCount, playerCount, scrobbleCount, linkedUsers, ping, uptime, comHash, comLink, reason, footer, loading, lastfmEnabled }) {
|
||||
const num = (v) => Utils.formatNumber(v);
|
||||
const ld = (v) => loading ? "..." : v;
|
||||
@@ -171,8 +236,11 @@ function buildEmbed(t, msg, { guildCount, userCount, playerCount, scrobbleCount,
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the stats command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* Run handler for the stats command.
|
||||
* Collects bot statistics and displays them in an embed, initially with loading
|
||||
* state then edited with the real data.
|
||||
*
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message) {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
/**
|
||||
* @file support.mjs — Show support server invite link
|
||||
* @module commands.support
|
||||
* @module commands/support
|
||||
* @description Displays a link and invitation to the bot's support server.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the support command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("support")
|
||||
.setDescription("The support server for Remix. Feel free to ask help, report bugs or just chat :)", "commands.support")
|
||||
@@ -14,8 +15,9 @@ export const command = new CommandBuilder()
|
||||
.setCategory("util");
|
||||
|
||||
/**
|
||||
* run function.
|
||||
* @param {object} msg
|
||||
* Run handler for the support command.
|
||||
* Sends an embed with the support server link.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @returns {void}
|
||||
*/
|
||||
export function run(msg) {
|
||||
|
||||
+16
-5
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file test.mjs — Test/debug command for voice channel user detection
|
||||
* @module commands.test
|
||||
* @module commands/test
|
||||
* @description Owner-only diagnostic command to display voice channel user counts.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -8,15 +8,19 @@ import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
import { logger } from "../src/constants/Logger.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the test command (owner-only). */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("test")
|
||||
.setDescription("Shows how many people are in each voice channel.")
|
||||
.setCategory("util")
|
||||
.setRequirement(r => r.setOwnerOnly(true));
|
||||
|
||||
/**
|
||||
* Execute the test command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* @async
|
||||
* Run handler for the test command.
|
||||
* Iterates the voice state cache and reports user counts per voice channel.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} data - Parsed command data (unused).
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg, data) {
|
||||
@@ -54,6 +58,13 @@ export async function run(msg, data) {
|
||||
return msg.reply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Resolve a channel ID to a human-readable channel name.
|
||||
* Tries cache, guild cache, then REST fetch as fallback.
|
||||
* @param {string} channelId - The voice channel ID.
|
||||
* @returns {Promise<string>} The channel name or a fallback string.
|
||||
*/
|
||||
const getChannelName = async (channelId) => {
|
||||
const cached = this.client.channels.get(channelId);
|
||||
if (cached?.name) return cached.name;
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
/**
|
||||
* @file thumbnail.mjs — Get the thumbnail image for the current or specified track
|
||||
* @module commands.thumbnail
|
||||
* @module commands/thumbnail
|
||||
* @description Display the thumbnail artwork of the currently playing track.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the thumbnail command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("thumbnail")
|
||||
.setDescription("Request the thumbnail of the currently playing song.", "commands.thumbnail")
|
||||
@@ -14,8 +15,10 @@ export const command = new CommandBuilder()
|
||||
.setCategory("music");
|
||||
|
||||
/**
|
||||
* Execute the thumbnail command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @async
|
||||
* Run handler for the thumbnail command.
|
||||
* Fetches and displays the thumbnail of the currently playing track.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg) {
|
||||
|
||||
+15
-5
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file trackopt.mjs — Manage per-track options — auto-seek start position and end-time timer
|
||||
* @module commands.trackopt
|
||||
* @module commands/trackopt
|
||||
* @description Set custom start/end times for tracks with named alias support.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -10,8 +10,10 @@ import { Utils } from "../src/Utils.mjs";
|
||||
import { logger } from "../src/constants/Logger.mjs";
|
||||
import { ERROR_COLOR } from "../src/constants/UI.mjs";
|
||||
|
||||
/** @private @type {string} The default alias name for non-named track options. */
|
||||
const DEFAULT_ALIAS = "default";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the trackopt command with subcommands. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("trackopt")
|
||||
.setDescription("Set custom start/end times for tracks. Supports named aliases — save multiple trims per track for different sections.", "commands.trackopt")
|
||||
@@ -58,6 +60,12 @@ export const command = new CommandBuilder()
|
||||
)
|
||||
.addAlias("to");
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Extract an alias:name token from a parts array, mutating the array in place.
|
||||
* @param {string[]} parts - Mutable array of token strings.
|
||||
* @returns {string} The extracted alias value, or DEFAULT_ALIAS if not found.
|
||||
*/
|
||||
function extractAlias(parts) {
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
if (parts[i].toLowerCase().startsWith("alias:")) {
|
||||
@@ -70,9 +78,11 @@ function extractAlias(parts) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the trackopt command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* @async
|
||||
* Run handler for the trackopt command.
|
||||
* Dispatches to set/get/play/remove/list subcommands for custom track trim options.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing subcommand and its options.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg, data) {
|
||||
|
||||
+11
-5
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file volume.mjs — Set or view the playback volume
|
||||
* @module commands.volume
|
||||
* @module commands/volume
|
||||
* @description Get or change the playback volume for the current voice channel.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -9,6 +9,10 @@ import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
import { MAX_VOLUME } from "../src/constants/UI.mjs";
|
||||
|
||||
|
||||
/**
|
||||
* @type {CommandBuilder}
|
||||
* @description Command definition for the volume command.
|
||||
*/
|
||||
export const command = new CommandBuilder()
|
||||
.setName("volume")
|
||||
.setDescription("Get or change the current volume.", "commands.volume")
|
||||
@@ -21,9 +25,11 @@ export const command = new CommandBuilder()
|
||||
.addAliases("v", "vol");
|
||||
|
||||
/**
|
||||
* Execute the volume command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* Run handler for the volume command.
|
||||
* Displays the current volume or sets it to a new value.
|
||||
*
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing the volume option.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message, data) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file volumedefault.mjs — Set the default volume for the server
|
||||
* @module commands.volumedefault
|
||||
* @module commands/volumedefault
|
||||
* @description View or set the server default volume. Requires Manage Server permission to set.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -9,7 +9,7 @@ import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||
import { PermissionFlags } from "@fluxerjs/core";
|
||||
import { MAX_VOLUME } from "../src/constants/UI.mjs";
|
||||
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the volumedefault command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("volumedefault")
|
||||
.setDescription("View or set the server default volume. (Requires Manage Server to set)", "commands.volumedefault")
|
||||
@@ -22,9 +22,11 @@ export const command = new CommandBuilder()
|
||||
.addAliases("vd");
|
||||
|
||||
/**
|
||||
* Execute the volumedefault command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* @async
|
||||
* Run handler for the volumedefault command.
|
||||
* Displays or persists the server's default volume setting.
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing the optional volume option.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message, data) {
|
||||
|
||||
+54
-15
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file vote.mjs — Skip-vote system — start a vote to skip the current track
|
||||
* @module commands.vote
|
||||
* @module commands/vote
|
||||
* @description View voting info, check voters, or browse voter lists for a server/bot on FluxerList.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
@@ -11,7 +11,7 @@ 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";
|
||||
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the vote command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("vote")
|
||||
.setDescription("View voting info or check voters for your server/bot on FluxerList", "commands.vote")
|
||||
@@ -40,6 +40,13 @@ export const command = new CommandBuilder()
|
||||
.setRequired(false)
|
||||
);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Build an error embed when FluxerList is not configured.
|
||||
* @param {Function} t - Translation function.
|
||||
* @param {string} guildId - The guild ID for localization.
|
||||
* @returns {object} Embed payload.
|
||||
*/
|
||||
function notConfigured(t, guildId) {
|
||||
return {
|
||||
embeds: [new EmbedBuilder()
|
||||
@@ -48,6 +55,15 @@ function notConfigured(t, guildId) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Build an error embed when no resource ID is available for the vote lookup.
|
||||
* @param {string} type - The resource type ("server" or "bot").
|
||||
* @param {string} prefix - The guild command prefix.
|
||||
* @param {Function} t - Translation function.
|
||||
* @param {string} guildId - The guild ID for localization.
|
||||
* @returns {object} Embed payload.
|
||||
*/
|
||||
function noResourceId(type, prefix, t, guildId) {
|
||||
return {
|
||||
embeds: [new EmbedBuilder()
|
||||
@@ -57,15 +73,18 @@ function noResourceId(type, prefix, t, guildId) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a paginated voter list embed.
|
||||
* @param {Array<{ username: string, fluxerId: number, votedAt: string }>} voters
|
||||
* @param {number} total
|
||||
* @param {number} page
|
||||
* @param {number} limit
|
||||
* @param {"server"|"bot"} type
|
||||
* @param {string} resourceId
|
||||
* @param {boolean} expired - Whether the navigation controls have expired
|
||||
* @returns {object} Embed payload
|
||||
* @private
|
||||
* Build a paginated voters embed with ranked voter list.
|
||||
* @param {Array<object>} voters - Array of voter objects.
|
||||
* @param {number} total - Total number of voters across all pages.
|
||||
* @param {number} page - Current page number (1-based).
|
||||
* @param {number} limit - Voters per page.
|
||||
* @param {string} type - Resource type ("server" or "bot").
|
||||
* @param {string} resourceId - The server or bot ID.
|
||||
* @param {boolean} [expired=false] - Whether navigation controls have expired.
|
||||
* @param {Function} t - Translation function.
|
||||
* @param {string} guildId - The guild ID for localization.
|
||||
* @returns {object} Embed payload.
|
||||
*/
|
||||
function buildVotersEmbed(voters, total, page, limit, type, resourceId, expired = false, t, guildId) {
|
||||
const totalPages = Math.max(1, Math.ceil(total / limit));
|
||||
@@ -101,9 +120,11 @@ 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<string, {value: *}>} data - Slash-command options map
|
||||
* @async
|
||||
* Run handler for the vote command.
|
||||
* Handles info, check, and voters subcommands with optional pagination.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing action, type, id, and page options.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg, data) {
|
||||
@@ -191,6 +212,14 @@ export async function run(msg, data) {
|
||||
|
||||
let currentPage = voterData.page;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Build a voter page embed from fetched voter data.
|
||||
* @param {number} pageIdx - Page number (1-based).
|
||||
* @param {object} data - Voter data from FluxerList API.
|
||||
* @param {boolean} [expired=false] - Whether controls have expired.
|
||||
* @returns {object} Embed payload.
|
||||
*/
|
||||
const buildPage = (pageIdx, data, expired = false) => {
|
||||
return buildVotersEmbed(data.voters, data.total, pageIdx, 20, resolvedType, id, expired, t, guildId);
|
||||
};
|
||||
@@ -203,6 +232,11 @@ export async function run(msg, data) {
|
||||
await replyMsg.message.react(emoji).catch(() => {});
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Remove all navigation reactions from the voter list message.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const clearReactions = async () => {
|
||||
try {
|
||||
await replyMsg.message.removeAllReactions();
|
||||
@@ -214,6 +248,11 @@ export async function run(msg, data) {
|
||||
};
|
||||
|
||||
let emojiTimeout = null;
|
||||
/**
|
||||
* @private
|
||||
* Reset the emoji removal timeout timer for the voter pagination session.
|
||||
* @returns {void}
|
||||
*/
|
||||
const resetTimer = () => {
|
||||
clearTimeout(emojiTimeout);
|
||||
emojiTimeout = setTimeout(async () => {
|
||||
|
||||
Reference in new issue
Block a user