2021-08-19 14:19:14 +00:00
|
|
|
import { players, manager, queues } from "../utils/soundplayer.js";
|
|
|
|
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-04-19 14:31:39 +00:00
|
|
|
if (connection && connection.type === "music" && oldChannel.id === connection.voiceChannel.id) {
|
2020-07-06 20:19:30 +00:00
|
|
|
if (oldChannel.voiceMembers.filter((i) => i.id !== client.user.id).length === 0) {
|
|
|
|
const waitMessage = await client.createMessage(connection.originalChannel.id, "🔊 Waiting 10 seconds for someone to return...");
|
|
|
|
const awaitRejoin = new AwaitRejoin(oldChannel, true);
|
|
|
|
awaitRejoin.on("end", (rejoined, member) => {
|
|
|
|
if (rejoined) {
|
2021-08-19 14:19:14 +00:00
|
|
|
players.set(connection.voiceChannel.guild.id, { player: connection.player, type: connection.type, host: member.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel });
|
2020-07-06 20:19:30 +00:00
|
|
|
waitMessage.edit(`🔊 ${member.mention} is the new voice channel host.`);
|
|
|
|
} else {
|
2020-09-23 19:12:39 +00:00
|
|
|
if (waitMessage.channel.messages.get(waitMessage.id)) waitMessage.delete();
|
2020-07-06 20:19:30 +00:00
|
|
|
connection.player.stop(connection.originalChannel.guild.id);
|
2021-08-19 14:19:14 +00:00
|
|
|
manager.leave(connection.originalChannel.guild.id);
|
2020-09-02 02:52:12 +00:00
|
|
|
connection.player.destroy();
|
2021-08-19 14:19:14 +00:00
|
|
|
players.delete(connection.originalChannel.guild.id);
|
|
|
|
queues.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);
|
|
|
|
awaitRejoin.on("end", (rejoined) => {
|
|
|
|
if (rejoined) {
|
2020-09-23 19:12:39 +00:00
|
|
|
if (waitMessage.channel.messages.get(waitMessage.id)) waitMessage.delete();
|
2020-07-06 20:19:30 +00:00
|
|
|
} else {
|
|
|
|
const members = oldChannel.voiceMembers.filter((i) => i.id !== client.user.id);
|
|
|
|
if (members.length === 0) {
|
2020-09-23 19:12:39 +00:00
|
|
|
if (waitMessage.channel.messages.get(waitMessage.id)) waitMessage.delete();
|
2020-07-06 20:19:30 +00:00
|
|
|
connection.player.stop(connection.originalChannel.guild.id);
|
2021-08-19 14:19:14 +00:00
|
|
|
manager.leave(connection.originalChannel.guild.id);
|
2020-09-02 02:52:12 +00:00
|
|
|
connection.player.destroy();
|
2021-08-19 14:19:14 +00:00
|
|
|
players.delete(connection.originalChannel.guild.id);
|
|
|
|
queues.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-08-19 14:19:14 +00:00
|
|
|
players.set(connection.voiceChannel.guild.id, { player: connection.player, type: connection.type, host: randomMember.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel });
|
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) {
|
|
|
|
connection.player.stop(connection.originalChannel.guild.id);
|
2021-08-19 14:19:14 +00:00
|
|
|
manager.leave(connection.originalChannel.guild.id);
|
2020-09-02 02:52:12 +00:00
|
|
|
connection.player.destroy();
|
2021-08-19 14:19:14 +00:00
|
|
|
players.delete(connection.originalChannel.guild.id);
|
|
|
|
queues.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
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|