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