mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
rollback
This commit is contained in:
1 parent
4bc2a98bab
commit
500b0de4c8
15 files changed
+134
-714
No files matched your search
+3
-56
@@ -2,8 +2,6 @@
|
||||
* @module commands/play
|
||||
* @description Play a song or playlist from a URL or search query.
|
||||
* Supports YouTube, Spotify, SoundCloud, Deezer, Apple Music, Tidal, Bilibili, and Last.fm integration.
|
||||
* Audio files attached to the command message (Opus, OGG, WebM, MP3, M4A, AAC, FLAC, WAV)
|
||||
* are played directly when no text query is given.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/commands/index.mjs";
|
||||
@@ -11,7 +9,6 @@ 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 { playLastFmCategory } from "./lastfm.mjs";
|
||||
import { parseLastFmUrl, isLastFmUrl } from "../src/services/lastfm/LastFmManager.mjs";
|
||||
import { ERROR_COLOR } from "../src/utils/UI.mjs";
|
||||
@@ -164,7 +161,6 @@ export const command = new CommandBuilder()
|
||||
"Play a song or playlist from a URL or search query.\n" +
|
||||
"Supports YouTube, Spotify, SoundCloud, Deezer, Apple Music, Tidal, Bilibili, and more.\n" +
|
||||
"Also accepts direct audio URLs (MP3, OGG, AAC, radio streams) and Bilibili video links (incl. b23.tv and ?p= parts).\n" +
|
||||
"Attach an audio file (Opus, OGG, WebM, MP3, M4A, AAC, FLAC, WAV) to this command with no text to play it directly.\n" +
|
||||
"Default search: YouTube Music. Use `-p <provider>` or inline prefix e.g. `sp: blinding lights`.",
|
||||
"commands.play"
|
||||
)
|
||||
@@ -178,7 +174,6 @@ export const command = new CommandBuilder()
|
||||
"$prefixplay https://www.bilibili.com/video/BV1y7bg6kEhY",
|
||||
"$prefixplay https://example.com/stream.mp3",
|
||||
"$prefixplay https://radio.example.com:8000/live",
|
||||
"$prefixplay (attach an Opus/MP3 audio file, no text needed)",
|
||||
"$prefixplay https://www.last.fm/music/Drake/_/Make+Them+Cry",
|
||||
"$prefixplay lastfm:loved",
|
||||
"$prefixplay lastfm:soda pop",
|
||||
@@ -189,8 +184,8 @@ export const command = new CommandBuilder()
|
||||
)
|
||||
.addTextOption(option =>
|
||||
option.setName("query")
|
||||
.setDescription("A search query, music genre (for example `pop`), URL, or provider-prefixed query like `sp: song name`. Leave empty when attaching an audio file.", "options.play.query")
|
||||
.setRequired(false)
|
||||
.setDescription("A search query, music genre (for example `pop`), URL, or provider-prefixed query like `sp: song name`.", "options.play.query")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addChoiceOption(o =>
|
||||
o.setName("provider")
|
||||
@@ -210,59 +205,11 @@ export const command = new CommandBuilder()
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message, data) {
|
||||
const rawQuery = data.get("query")?.value ?? "";
|
||||
const rawQuery = data.get("query").value;
|
||||
const flagProvider = data.get("provider")?.value;
|
||||
const { provider: inlineProvider, query } = parseInlineProvider(rawQuery);
|
||||
const provider = inlineProvider ?? flagProvider ?? "ytm";
|
||||
|
||||
/* Audio file attachments — `%p` with an attached Opus/OGG/WebM/MP3/etc.
|
||||
file and no text query queues the file(s) directly through the audio
|
||||
bridge (Ogg/Opus and WebM play natively, others resolve via Lavalink). */
|
||||
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("[Play] 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(() => {}); }
|
||||
};
|
||||
|
||||
if (attachments.length === 1) {
|
||||
const att = attachments[0];
|
||||
const url = attachmentUrl(att);
|
||||
const messages = p.playExternal(url, attachmentTitle(att), null, false, "external", attachmentTrackMeta(att));
|
||||
messages.on("message", post);
|
||||
return;
|
||||
}
|
||||
|
||||
attachments.forEach(att => {
|
||||
p.playExternal(attachmentUrl(att), attachmentTitle(att), null, false, "external", attachmentTrackMeta(att))
|
||||
.on("message", () => {});
|
||||
});
|
||||
post(this.t(message, "responses.play.addedPlaylist", { count: attachments.length }));
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNativeAudioUrl(rawQuery)) {
|
||||
const p = await this.getPlayer(message, true, true, true);
|
||||
if (!p) return;
|
||||
|
||||
+5
-52
@@ -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";
|
||||
|
||||
Reference in new issue
Block a user