2021-09-19 22:49:02 +00:00
|
|
|
import { players, manager, queues, skipVotes } from "../utils/soundplayer.js";
|
2021-08-19 14:19:14 +00:00
|
|
|
import AwaitRejoin from "../utils/awaitrejoin.js";
|
|
|
|
import { random } from "../utils/misc.js";
|
2020-07-06 20:19:30 +00:00
|
|
|
|
2021-08-19 14:19:14 +00:00
|
|
|
export default async (client, cluster, worker, ipc, member, oldChannel) => {
|
2021-07-09 02:03:19 +00:00
|
|
|
if (!oldChannel) return;
|
2021-08-19 14:19:14 +00:00
|
|
|
const connection = players.get(oldChannel.guild.id);
|
2021-12-12 05:44:49 +00:00
|
|
|
if (connection && oldChannel.id === connection.voiceChannel.id) {
|
2021-10-08 04:58:24 +00:00
|
|
|
if (oldChannel.voiceMembers.filter((i) => i.id !== client.user.id && !i.bot).length === 0) {
|
2021-12-13 22:09:12 +00:00
|
|
|
await connection.player.pause(true);
|
2020-07-06 20:19:30 +00:00
|
|
|
const waitMessage = await client.createMessage(connection.originalChannel.id, "🔊 Waiting 10 seconds for someone to return...");
|
|
|
|
const awaitRejoin = new AwaitRejoin(oldChannel, true);
|
2021-12-13 21:46:08 +00:00
|
|
|
awaitRejoin.on("end", async (rejoined, member) => {
|
2020-07-06 20:19:30 +00:00
|
|
|
if (rejoined) {
|
2021-12-13 22:09:12 +00:00
|
|
|
await connection.player.pause(false);
|
2021-09-20 17:26:40 +00:00
|
|
|
players.set(connection.voiceChannel.guild.id, { player: connection.player, type: connection.type, host: member.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel, loop: connection.loop, shuffle: connection.shuffle, playMessage: connection.playMessage });
|
2020-07-06 20:19:30 +00:00
|
|
|
waitMessage.edit(`🔊 ${member.mention} is the new voice channel host.`);
|
|
|
|
} else {
|
2021-09-22 00:15:19 +00:00
|
|
|
try {
|
2021-12-13 21:46:08 +00:00
|
|
|
if (waitMessage.channel.messages.get(waitMessage.id)) await waitMessage.delete();
|
2021-09-22 00:15:19 +00:00
|
|
|
} catch {
|
|
|
|
// no-op
|
|
|
|
}
|
2022-01-08 21:54:34 +00:00
|
|
|
try {
|
|
|
|
await connection.player.stop(connection.originalChannel.guild.id);
|
|
|
|
await manager.leave(connection.originalChannel.guild.id);
|
|
|
|
await connection.player.destroy();
|
|
|
|
} catch {
|
|
|
|
// no-op
|
|
|
|
}
|
2021-08-19 14:19:14 +00:00
|
|
|
players.delete(connection.originalChannel.guild.id);
|
|
|
|
queues.delete(connection.originalChannel.guild.id);
|
2021-09-19 22:49:02 +00:00
|
|
|
skipVotes.delete(connection.originalChannel.guild.id);
|
2020-09-02 02:52:12 +00:00
|
|
|
client.createMessage(connection.originalChannel.id, "🔊 The current voice channel session has ended.");
|
2020-07-06 20:19:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (member.id === connection.host) {
|
|
|
|
const waitMessage = await client.createMessage(connection.originalChannel.id, "🔊 Waiting 10 seconds for the host to return...");
|
|
|
|
const awaitRejoin = new AwaitRejoin(oldChannel, false, member.id);
|
2021-12-13 21:46:08 +00:00
|
|
|
awaitRejoin.on("end", async (rejoined) => {
|
2020-07-06 20:19:30 +00:00
|
|
|
if (rejoined) {
|
2021-09-22 00:15:19 +00:00
|
|
|
try {
|
2021-12-13 21:46:08 +00:00
|
|
|
if (waitMessage.channel.messages.get(waitMessage.id)) await waitMessage.delete();
|
2021-09-22 00:15:19 +00:00
|
|
|
} catch {
|
|
|
|
// no-op
|
|
|
|
}
|
2020-07-06 20:19:30 +00:00
|
|
|
} else {
|
2021-10-08 04:58:24 +00:00
|
|
|
const members = oldChannel.voiceMembers.filter((i) => i.id !== client.user.id && !i.bot);
|
2020-07-06 20:19:30 +00:00
|
|
|
if (members.length === 0) {
|
2021-09-22 00:15:19 +00:00
|
|
|
try {
|
2021-12-13 21:46:08 +00:00
|
|
|
if (waitMessage.channel.messages.get(waitMessage.id)) await waitMessage.delete();
|
2021-09-22 00:15:19 +00:00
|
|
|
} catch {
|
|
|
|
// no-op
|
|
|
|
}
|
2022-01-08 21:54:34 +00:00
|
|
|
try {
|
|
|
|
await connection.player.stop(connection.originalChannel.guild.id);
|
|
|
|
await manager.leave(connection.originalChannel.guild.id);
|
|
|
|
await connection.player.destroy();
|
|
|
|
} catch {
|
|
|
|
// no-op
|
|
|
|
}
|
2021-08-19 14:19:14 +00:00
|
|
|
players.delete(connection.originalChannel.guild.id);
|
|
|
|
queues.delete(connection.originalChannel.guild.id);
|
2021-09-19 22:49:02 +00:00
|
|
|
skipVotes.delete(connection.originalChannel.guild.id);
|
2020-09-02 02:52:12 +00:00
|
|
|
client.createMessage(connection.originalChannel.id, "🔊 The current voice channel session has ended.");
|
2020-07-06 20:19:30 +00:00
|
|
|
} else {
|
2020-08-16 16:48:37 +00:00
|
|
|
const randomMember = random(members);
|
2021-09-20 17:26:40 +00:00
|
|
|
players.set(connection.voiceChannel.guild.id, { player: connection.player, type: connection.type, host: randomMember.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel, loop: connection.loop, shuffle: connection.shuffle, playMessage: connection.playMessage });
|
2020-07-06 20:19:30 +00:00
|
|
|
waitMessage.edit(`🔊 ${randomMember.mention} is the new voice channel host.`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-09-02 02:52:12 +00:00
|
|
|
} else if (member.id === client.user.id) {
|
2022-01-08 21:54:34 +00:00
|
|
|
try {
|
|
|
|
await connection.player.stop(connection.originalChannel.guild.id);
|
|
|
|
await manager.leave(connection.originalChannel.guild.id);
|
|
|
|
await connection.player.destroy();
|
|
|
|
} catch {
|
|
|
|
// no-op
|
|
|
|
}
|
2021-08-19 14:19:14 +00:00
|
|
|
players.delete(connection.originalChannel.guild.id);
|
|
|
|
queues.delete(connection.originalChannel.guild.id);
|
2021-09-19 22:49:02 +00:00
|
|
|
skipVotes.delete(connection.originalChannel.guild.id);
|
2020-09-02 02:52:12 +00:00
|
|
|
await client.createMessage(connection.originalChannel.id, "🔊 The current voice channel session has ended.");
|
2020-07-06 20:19:30 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-12 05:44:49 +00:00
|
|
|
};
|