From d1c7903541703f9847afd8046b51360c26be39a9 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Tue, 2 Aug 2022 22:00:10 -0600 Subject: [PATCH] music: funny low quality mode --- src/modules/music.js | 109 ++++++++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 48 deletions(-) diff --git a/src/modules/music.js b/src/modules/music.js index 592bb26..889298c 100644 --- a/src/modules/music.js +++ b/src/modules/music.js @@ -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) );