mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
- Core & Telemetry: * Overhaul ErrorChannel (config.errorLogChannel) to rich Pro Embeds with severity color coding (Error, Warn, Info). * Add structured crash reports featuring syntax-highlighted stack traces, uptime, and RSS memory telemetry. * Add log flood drop notifications and startup connection status announcement. * Support dynamic self-hosted Fluxer API base resolution (config.apiBase / config['fluxer.js'].api). * Wire ErrorChannel into the localization system with dynamic _t() translation and safe fallback. - Localization & i18n: * Expand all 6 locale files (en, ar-SA, ckb, tr, de-DE, pt-BR) to 1,112 keys each. * Achieve 100% key parity and 0 variable mismatches across all supported languages. * Localize all embed titles, author badges, footers, and system responses. - Commands & Modern UI: * Upgrade all commands (playback, queue, audio DSP, utility, lastfm, settings, owner) to the modern Pro UI embed design. * Add previous, replay, and skipto queue navigation commands with history tracking. * Replace raw unicode escapes with literal UTF-8 emojis. * Maintain clean codebase standards (zero single-line comments introduced, commands/stats.mjs strictly untouched). - Architecture & Voice: * Enhance FluxerAudioBridge, VoiceStateRouting, and VoiceStateCache for reliable voice reconnects. * Refactor centralized database pooling and player lifecycle mixins.
138 lines
5.3 KiB
JavaScript
138 lines
5.3 KiB
JavaScript
/**
|
|
* @module commands/skip
|
|
* @description Skip the currently playing track. Solo or duo listeners skip
|
|
* instantly; once 3+ (configurable) people are in the voice channel, a
|
|
* majority vote is required — unless the server has disabled vote-skip.
|
|
*/
|
|
|
|
import { CommandBuilder } from "../src/commands/index.mjs";
|
|
import { EmbedBuilder } from "@fluxerjs/core";
|
|
import { cleanId } from "../src/ui/index.mjs";
|
|
import { countHumansInChannel } from "../src/voice/VoiceStateResolver.mjs";
|
|
import { Utils } from "../src/utils/Utils.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")
|
|
.addAliases("s")
|
|
.setCategory("music");
|
|
|
|
/** @private Perform the actual skip and reply with what was skipped. @param {object} ctx @param {object} message @param {Player} p @returns {Promise<void>} */
|
|
async function doSkip(ctx, message, p) {
|
|
const current = p.queue.getCurrent();
|
|
const skippedTitle = current?.title ?? null;
|
|
const skippedLink = current ? (current.spotifyUrl || current.url || "") : "";
|
|
const rawAuthor = current ? (current.artist || (typeof current.author === "object" ? current.author?.name : current.author)) : null;
|
|
const skippedThumb = current?.thumbnail || null;
|
|
const elapsed = p.getCurrentElapsedDuration();
|
|
|
|
const err = p.skip();
|
|
if (!p.connection || !current) {
|
|
const embed = new EmbedBuilder()
|
|
.setColor(0xe9196c)
|
|
.setAuthor({ name: `⏭️ ${ctx.t(message, "responses.skip.skippedTitle")}` })
|
|
.setDescription(err);
|
|
return message.reply({ embeds: [embed] });
|
|
}
|
|
|
|
const nextTrack = p.queue.data?.[0];
|
|
const nextTitle = nextTrack?.title ? Utils.truncate(nextTrack.title, 40) : null;
|
|
const queueCount = p.queue.size();
|
|
const pluralStr = queueCount === 1 ? ctx.t(message, "responses.play.trackSingle") : ctx.t(message, "responses.play.trackPlural");
|
|
|
|
const authorLabel = `⏭️ ${ctx.t(message, "responses.skip.skippedTitle")}`;
|
|
const titleDisplay = skippedTitle ? Utils.truncate(skippedTitle, 50) : ctx.t(message, "responses.play.unknownTrack");
|
|
|
|
let desc = skippedLink ? `**[${titleDisplay}](${skippedLink})**` : `**${titleDisplay}**`;
|
|
if (rawAuthor) {
|
|
desc += `\n${ctx.t(message, "responses.play.byAuthor", { author: rawAuthor })}`;
|
|
}
|
|
|
|
const footerParts = [];
|
|
if (nextTitle) {
|
|
footerParts.push(`▶️ ${ctx.t(message, "responses.skip.upNext")}: ${nextTitle}`);
|
|
}
|
|
footerParts.push(ctx.t(message, "responses.skip.queueRemaining", { count: queueCount, plural: pluralStr }));
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setColor(0xe9196c)
|
|
.setAuthor({ name: authorLabel })
|
|
.setTitle(ctx.t(message, "responses.skip.skippedAt", { time: elapsed }))
|
|
.setDescription(desc)
|
|
.setFooter({ text: footerParts.join(" • ") });
|
|
|
|
if (skippedThumb) {
|
|
embed.setThumbnail(skippedThumb);
|
|
}
|
|
|
|
message.reply({ embeds: [embed] }).catch(() => {});
|
|
}
|
|
|
|
/**
|
|
* @async
|
|
* Run handler for the skip command.
|
|
* Skips instantly for 1-2 listeners; requires a majority vote for 3+
|
|
* (threshold configurable per server via `voteSkipThreshold`, and the whole
|
|
* system can be turned off via `voteSkip`).
|
|
* @param {object} message - The command message wrapper.
|
|
* @returns {Promise<void>}
|
|
*/
|
|
export async function run(message) {
|
|
const p = await this.getPlayer(message);
|
|
if (!p) return;
|
|
|
|
const current = p.queue.getCurrent();
|
|
if (!p.connection || !current) {
|
|
const embed = new EmbedBuilder()
|
|
.setColor(0xe9196c)
|
|
.setAuthor({ name: `⏭️ ${this.t(message, "responses.skip.skippedTitle")}` })
|
|
.setDescription(this.t(message, "responses._common.nothingPlaying"));
|
|
return message.reply({ embeds: [embed] });
|
|
}
|
|
|
|
const guildId = cleanId(p._guildId) || cleanId(message?.channel?.guildId ?? message?.message?.guildId);
|
|
const channelId = cleanId(p._channelId ?? p._home247Channel);
|
|
|
|
const set = this.getSettings(message);
|
|
const voteSkipEnabled = set?.get("voteSkip") ?? true;
|
|
const threshold = Number(set?.get("voteSkipThreshold")) || 3;
|
|
|
|
const humanCount = countHumansInChannel({
|
|
guildId,
|
|
channelId,
|
|
client: this.client,
|
|
botId: this.client?.user?.id,
|
|
voiceCache: this.voiceCache,
|
|
observedVoiceUsers: this.observedVoiceUsers,
|
|
});
|
|
|
|
if (!voteSkipEnabled || humanCount < threshold) {
|
|
return doSkip(this, message, p);
|
|
}
|
|
|
|
const userId = message?.author?.id ?? message?.member?.user?.id;
|
|
if (!userId) return doSkip(this, message, p);
|
|
|
|
const needed = Math.floor(humanCount / 2) + 1;
|
|
|
|
if (p._skipVotes.has(userId)) {
|
|
const embed = new EmbedBuilder().setColor(0xe9196c)
|
|
.setAuthor({ name: `🗳️ ${this.t(message, "responses.skip.skippedTitle")}` })
|
|
.setDescription(this.t(message, "responses.skip.alreadyVoted", { votes: p._skipVotes.size, needed }));
|
|
return message.reply({ embeds: [embed] }).catch(() => {});
|
|
}
|
|
|
|
p._skipVotes.add(userId);
|
|
|
|
if (p._skipVotes.size >= needed) {
|
|
p._skipVotes.clear();
|
|
return doSkip(this, message, p);
|
|
}
|
|
|
|
const embed = new EmbedBuilder().setColor(0xe9196c)
|
|
.setAuthor({ name: `🗳️ ${this.t(message, "responses.skip.skippedTitle")}` })
|
|
.setDescription(this.t(message, "responses.skip.voteAdded", { votes: p._skipVotes.size, needed }));
|
|
message.reply({ embeds: [embed] }).catch(() => {});
|
|
}
|