mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
feat(player): add %skipto command, empty voice auto-pause, and server mute guard
This commit is contained in:
1 parent
dfe77d86b9
commit
c0c95610ac
12 files changed
+287
-12
No files matched your search
@@ -42,6 +42,8 @@ export async function run(message) {
|
||||
}
|
||||
|
||||
p.pause();
|
||||
p._autoPausedEmpty = false;
|
||||
p._serverMutedAutoPaused = false;
|
||||
const elapsed = p.getCurrentElapsedDuration();
|
||||
const trackUrl = current.spotifyUrl || current.url || null;
|
||||
const rawAuthor = current.artist || (typeof current.author === "object" ? current.author?.name : current.author);
|
||||
|
||||
@@ -45,6 +45,8 @@ export async function run(message) {
|
||||
}
|
||||
|
||||
p.resume();
|
||||
p._autoPausedEmpty = false;
|
||||
p._serverMutedAutoPaused = false;
|
||||
const elapsed = p.getCurrentElapsedDuration();
|
||||
const trackUrl = current.spotifyUrl || current.url || null;
|
||||
const rawAuthor = current.artist || (typeof current.author === "object" ? current.author?.name : current.author);
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* @module commands/skipto
|
||||
* @description Skip directly to a specific track position in the queue.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/commands/index.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { Utils } from "../src/utils/Utils.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the skipto command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("skipto")
|
||||
.setDescription("Skip directly to a specific track in the queue.", "commands.skipto")
|
||||
.addAliases("jump", "jumpto")
|
||||
.setCategory("music")
|
||||
.addNumberOption(opt =>
|
||||
opt.setName("position")
|
||||
.setDescription("The track number in the queue to jump to.", "options.skipto.position")
|
||||
.setRequired(true)
|
||||
);
|
||||
|
||||
/**
|
||||
* @async
|
||||
* Run handler for the skipto command.
|
||||
* Skips all tracks prior to the target position and advances playback immediately.
|
||||
* @param {object} message - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing the position option.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message, data) {
|
||||
const p = await this.getPlayer(message, true, true, false);
|
||||
if (!p) return;
|
||||
|
||||
const queueSize = p.queue?.size() ?? 0;
|
||||
if (queueSize === 0) {
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0xe9196c)
|
||||
.setDescription(this.t(message, "responses.skipto.emptyQueue"));
|
||||
return message.reply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
const rawPosition = data.get("position")?.value;
|
||||
const position = parseInt(rawPosition, 10);
|
||||
|
||||
if (isNaN(position) || position < 1 || position > queueSize) {
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0xe9196c)
|
||||
.setDescription(this.t(message, "responses.skipto.invalidPosition", { max: queueSize }));
|
||||
return message.reply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
/* Preview targeted track before splicing */
|
||||
const targetTrack = p.queue.data[position - 1];
|
||||
const skippedCount = position;
|
||||
|
||||
p.skipTo(position);
|
||||
|
||||
const titleDisplay = targetTrack?.title ? Utils.truncate(targetTrack.title, 50) : this.t(message, "responses.play.unknownTrack");
|
||||
const trackLink = targetTrack?.spotifyUrl || targetTrack?.url || "";
|
||||
const rawAuthor = targetTrack?.artist || (typeof targetTrack?.author === "object" ? targetTrack.author?.name : targetTrack?.author);
|
||||
const remainingInQueue = Math.max(0, queueSize - position);
|
||||
|
||||
let desc = trackLink ? `**[${titleDisplay}](${trackLink})**` : `**${titleDisplay}**`;
|
||||
if (rawAuthor) {
|
||||
desc += `\n${this.t(message, "responses.play.byAuthor", { author: rawAuthor })}`;
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0xe9196c)
|
||||
.setAuthor({ name: `⏭️ ${this.t(message, "responses.skipto.author")}` })
|
||||
.setTitle(this.t(message, "responses.skipto.title", { position, count: skippedCount }))
|
||||
.setDescription(desc)
|
||||
.setFooter({ text: this.t(message, "responses.skipto.footer", { remaining: remainingInQueue }) });
|
||||
|
||||
if (targetTrack?.thumbnail) {
|
||||
embed.setThumbnail(targetTrack.thumbnail);
|
||||
}
|
||||
|
||||
return message.reply({ embeds: [embed] });
|
||||
}
|
||||
Reference in new issue
Block a user