music: funny low quality mode

This commit is contained in:
Cynthia Foxwell 2022-08-02 22:00:10 -06:00
parent 850b65b19f
commit d1c7903541

View file

@ -140,14 +140,15 @@ async function createVoiceConnection(guild_id, voice_id, text_id) {
connection._music_eventEnd = async function () { connection._music_eventEnd = async function () {
if (connection._music_queue.length > 0) { if (connection._music_queue.length > 0) {
const next = connection._music_queue.splice(0, 1)[0]; const next = connection._music_queue.splice(0, 1)[0];
await enqueue( await enqueue({
guild_id, guild_id,
voice_id, voice_id,
text_id, text_id,
next.url, url: next.url,
next.type, type: next.type,
next.addedBy addedBy: next.addedBy,
); speex: next.speex,
});
} else { } else {
await connection.disconnect(); await connection.disconnect();
if (!connection._music_leave) { if (!connection._music_leave) {
@ -169,7 +170,7 @@ async function createVoiceConnection(guild_id, voice_id, text_id) {
return connection; return connection;
} }
async function enqueue( async function enqueue({
guild_id, guild_id,
voice_id, voice_id,
text_id, text_id,
@ -177,8 +178,9 @@ async function enqueue(
type, type,
addedBy, addedBy,
suppress = false, suppress = false,
queueNext = false queueNext = false,
) { speex = false,
}) {
if (!url) return; if (!url) return;
const connection = const connection =
@ -270,6 +272,7 @@ async function enqueue(
length, length,
addedBy, addedBy,
stream, stream,
speex,
id: Math.random().toString(16).substring(2), id: Math.random().toString(16).substring(2),
}; };
@ -323,7 +326,11 @@ async function enqueue(
return; return;
} }
await connection.play(media, {inlineVolume: true, voiceDataTimeout: -1}); await connection.play(media, {
inlineVolume: true,
voiceDataTimeout: -1,
encoderArgs: speex ? ["-acodec speex", "-b:a 8000", "-ar 8000"] : null,
});
textChannel.createMessage({ textChannel.createMessage({
embeds: [ embeds: [
@ -443,6 +450,12 @@ command.callback = async function (msg, line) {
argStr = argStr.replace(/--next/, "").trim(); argStr = argStr.replace(/--next/, "").trim();
} }
let speex = false;
if (argStr.match(/--speex/)) {
speex = true;
argStr = argStr.replace(/--speex/, "").trim();
}
let type; let type;
let playlist = false; let playlist = false;
@ -510,15 +523,16 @@ command.callback = async function (msg, line) {
: track.permalink_url; : track.permalink_url;
} }
await enqueue( await enqueue({
msg.guildID, guild_id: msg.guildID,
msg.member.voiceState.channelID, voice_id: msg.member.voiceState.channelID,
msg.channel.id, text_id: msg.channel.id,
url, url,
type, type,
msg.author.id, addedBy: msg.author.id,
true supress: true,
); speex,
});
} }
await statusMessage.edit({ await statusMessage.edit({
embeds: [ embeds: [
@ -530,16 +544,16 @@ command.callback = async function (msg, line) {
], ],
}); });
} else { } else {
await enqueue( await enqueue({
msg.guildID, guild_id: msg.guildID,
msg.member.voiceState.channelID, voice_id: msg.member.voiceState.channelID,
msg.channel.id, text_id: msg.channel.id,
argStr, url: argStr,
type, type,
msg.author.id, addedBy: msg.author.id,
false, queueNext,
queueNext speex,
); });
} }
} else { } else {
if (argStr.match(/https?:\/\//)) { if (argStr.match(/https?:\/\//)) {
@ -550,32 +564,32 @@ command.callback = async function (msg, line) {
contentType.startsWith("audio/") || contentType.startsWith("audio/") ||
contentType.startsWith("video/") contentType.startsWith("video/")
) { ) {
await enqueue( await enqueue({
msg.guildID, guild_id: msg.guildID,
msg.member.voiceState.channelID, voice_id: msg.member.voiceState.channelID,
msg.channel.id, text_id: msg.channel.id,
argStr, url: argStr,
"file", type: "file",
msg.author.id, addedBy: msg.author.id,
false, queueNext,
queueNext speex,
); });
} else { } else {
return "Unsupported content type."; return "Unsupported content type.";
} }
} else { } else {
const url = await youtubeSearch(msg, argStr); const url = await youtubeSearch(msg, argStr);
if (url?.startsWith("https://youtu.be/")) { if (url?.startsWith("https://youtu.be/")) {
await enqueue( await enqueue({
msg.guildID, guild_id: msg.guildID,
msg.member.voiceState.channelID, voice_id: msg.member.voiceState.channelID,
msg.channel.id, text_id: msg.channel.id,
url, url,
"yt", type: "yt",
msg.author.id, addedBy: msg.author.id,
false, queueNext,
queueNext speex,
); });
} else { } else {
return url; return url;
} }
@ -744,9 +758,9 @@ command.callback = async function (msg, line) {
return { return {
key: item.id, key: item.id,
display: (item.title ?? item.url).substr(0, 100), display: (item.title ?? item.url).substr(0, 100),
description: description: hasManageMessages
hasManageMessages && ? `Added by: ${user.username}#${user.discriminator}`
`Added by: ${user.username}#${user.discriminator}`, : "",
}; };
}), }),
30000, 30000,
@ -754,7 +768,6 @@ command.callback = async function (msg, line) {
); );
if (Array.isArray(toRemove)) { if (Array.isArray(toRemove)) {
console.log(toRemove);
connection._music_queue = connection._music_queue.filter( connection._music_queue = connection._music_queue.filter(
(item) => !toRemove.includes(item.id) (item) => !toRemove.includes(item.id)
); );