Refine audio playback some more

This commit is contained in:
Essem 2022-01-08 15:54:34 -06:00
parent d3c452f79a
commit 382a7b0298
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
2 changed files with 42 additions and 13 deletions

View file

@ -21,9 +21,13 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
} catch {
// no-op
}
try {
await connection.player.stop(connection.originalChannel.guild.id);
await manager.leave(connection.originalChannel.guild.id);
await connection.player.destroy();
} catch {
// no-op
}
players.delete(connection.originalChannel.guild.id);
queues.delete(connection.originalChannel.guild.id);
skipVotes.delete(connection.originalChannel.guild.id);
@ -48,9 +52,13 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
} catch {
// no-op
}
try {
await connection.player.stop(connection.originalChannel.guild.id);
await manager.leave(connection.originalChannel.guild.id);
await connection.player.destroy();
} catch {
// no-op
}
players.delete(connection.originalChannel.guild.id);
queues.delete(connection.originalChannel.guild.id);
skipVotes.delete(connection.originalChannel.guild.id);
@ -63,9 +71,13 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
}
});
} else if (member.id === client.user.id) {
try {
await connection.player.stop(connection.originalChannel.guild.id);
await manager.leave(connection.originalChannel.guild.id);
await connection.player.destroy();
} catch {
// no-op
}
players.delete(connection.originalChannel.guild.id);
queues.delete(connection.originalChannel.guild.id);
skipVotes.delete(connection.originalChannel.guild.id);

View file

@ -59,11 +59,23 @@ export async function play(client, sound, message, music = false) {
if (!voiceChannel.permissionsOf(client.user.id).has("voiceConnect")) return "I don't have permission to join this voice channel!";
const player = players.get(message.channel.guild.id);
if (!music && manager.voiceStates.has(message.channel.guild.id) && (player && player.type === "music")) return "I can't play a sound effect while playing music!";
const node = manager.idealNodes[0];
let node = manager.idealNodes[0];
if (!node) {
const status = await checkStatus();
if (!status) {
await connect(client);
node = manager.idealNodes[0];
}
}
if (!music && !nodes.filter(obj => obj.host === node.host)[0].local) {
sound = sound.replace(/\.\//, "https://raw.githubusercontent.com/esmBot/esmBot/master/");
}
const { tracks, playlistInfo } = await Rest.load(node, sound);
let tracks, playlistInfo;
try {
({ tracks, playlistInfo } = await Rest.load(node, sound));
} catch {
return "🔊 Hmmm, seems that all of the audio servers are down. Try again in a bit.";
}
const oldQueue = queues.get(voiceChannel.guild.id);
if (!tracks || tracks.length === 0) return "I couldn't find that song!";
if (music) {
@ -144,12 +156,17 @@ export async function nextSong(client, message, connection, track, info, music,
} catch {
// no-op
}
try {
await manager.leave(voiceChannel.guild.id);
connection.removeAllListeners("end");
await connection.destroy();
} catch {
// no-op
}
connection.removeAllListeners("end");
players.delete(voiceChannel.guild.id);
queues.delete(voiceChannel.guild.id);
logger.error(error);
await client.createMessage(message.channel.id, `🔊 Looks like there was an error regarding sound playback:\n\`\`\`${error.type}: ${error.error}\`\`\``);
});
connection.on("end", async (data) => {
if (data.reason === "REPLACED") return;