This commit is contained in:
NoLogicAlan committed 2026-10-17 03:40:20 +03:00
1 parent 4bc2a98bab
commit 500b0de4c8
15 files changed
+134 -714

No files matched your search

+5 -52
View File
@@ -2,17 +2,12 @@
* @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.
* Audio files attached to the command message (Opus, OGG, WebM, MP3, ...) are
* queued at the top directly when no text query is given.
*/
import { CommandBuilder } from "../src/commands/index.mjs";
import { EmbedBuilder } from "@fluxerjs/core";
import { getGlobalColor } from "../src/ui/index.mjs";
import { logger } from "../src/core/Logger.mjs";
import { PROVIDER_CHOICES, parseInlineProvider } from "../src/music/providers.mjs";
import { getAudioAttachments, attachmentTitle, attachmentTrackMeta, attachmentUrl } from "../src/music/attachments.mjs";
import { ERROR_COLOR } from "../src/utils/UI.mjs";
/**
@@ -22,18 +17,17 @@ import { ERROR_COLOR } from "../src/utils/UI.mjs";
export const command = new CommandBuilder()
.setName("playnext")
.setId("playnext")
.setDescription("Same as $prefixplay but adds the result to the top of the queue. Attach an audio file to play it next.", "commands.playnext")
.setDescription("Same as $prefixplay but adds the result to the top of the queue.", "commands.playnext")
.setCategory("music")
.addExamples(
"$prefixplaynext blinding lights",
"$prefixplaynext sp: blinding lights",
"$prefixplaynext -p dz get lucky",
"$prefixplaynext (attach an Opus/MP3 audio file, no text needed)"
"$prefixplaynext -p dz get lucky"
)
.addTextOption(option =>
option.setName("query")
.setDescription("A search query, URL, or provider-prefixed query like `sp: song name`. Leave empty when attaching an audio file.", "options.playnext.query")
.setRequired(false)
.setDescription("A search query, URL, or provider-prefixed query like `sp: song name`.", "options.playnext.query")
.setRequired(true)
)
.addChoiceOption(o =>
o.setName("provider")
@@ -53,51 +47,10 @@ export const command = new CommandBuilder()
* @returns {Promise<void>}
*/
export async function run(message, data) {
const rawQuery = data.get("query")?.value ?? "";
/* Audio file attachments — `%playnext` with an attached audio file and no
text queues it at the top of the queue through the audio bridge. */
if (!rawQuery.trim()) {
const attachments = getAudioAttachments(message);
if (attachments.length === 0) {
const hasAnyAttachment = (message.message?.attachments?.size ?? 0) > 0;
return message.reply({
embeds: [new EmbedBuilder().setColor(ERROR_COLOR).setDescription(
this.t(message, hasAnyAttachment ? "responses.play.attachmentNotAudio" : "responses.play.noQuery")
)]
});
}
const p = await this.getPlayer(message, true, true, true);
if (!p) return;
const statusEmbed = new EmbedBuilder()
.setColor(getGlobalColor())
.setDescription(attachments.length === 1
? this.t(message, "responses.play.loadingAttachment", { filename: attachmentTitle(attachments[0]) })
: this.t(message, "responses.play.loadingAttachments", { count: attachments.length }));
let statusMsg = null;
try { statusMsg = await message.reply({ embeds: [statusEmbed] }); } catch(e) { logger.warn("[PlayNext] Error:", e?.message); }
const post = (desc) => {
const embed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(desc);
if (statusMsg) { statusMsg.edit({ embeds: [embed] }).catch(() => {}); }
else { message.reply({ embeds: [embed] }).catch(() => {}); }
};
attachments.forEach((att, i) => {
/* First file jumps to the top; the rest queue behind it in order. */
const top = i === 0;
p.playExternal(attachmentUrl(att), attachmentTitle(att), null, top, "external", attachmentTrackMeta(att))
.on("message", post);
});
return;
}
const p = await this.getPlayer(message, true, true, true);
if (!p) return;
const rawQuery = data.get("query").value;
const flagProvider = data.get("provider")?.value;
const { provider: inlineProvider, query } = parseInlineProvider(rawQuery);
const provider = inlineProvider ?? flagProvider ?? "ytm";