Pause music when everyone leaves the voice channel, try a slightly different approach to voice events
This commit is contained in:
parent
95dc02aed5
commit
c59a0bf0c4
5 changed files with 366 additions and 363 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -38,3 +38,4 @@ todo.txt
|
|||
.vscode/
|
||||
migratedb.js
|
||||
processed.txt
|
||||
data.sqlite
|
|
@ -7,10 +7,12 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
|
|||
const connection = players.get(oldChannel.guild.id);
|
||||
if (connection && connection.type === "music" && oldChannel.id === connection.voiceChannel.id) {
|
||||
if (oldChannel.voiceMembers.filter((i) => i.id !== client.user.id).length === 0) {
|
||||
connection.player.pause(true);
|
||||
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) {
|
||||
connection.player.pause(false);
|
||||
players.set(connection.voiceChannel.guild.id, { player: connection.player, type: connection.type, host: member.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel });
|
||||
waitMessage.edit(`🔊 ${member.mention} is the new voice channel host.`);
|
||||
} else {
|
||||
|
|
637
package-lock.json
generated
637
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -29,7 +29,7 @@
|
|||
"cowsay2": "^2.0.4",
|
||||
"dotenv": "^9.0.2",
|
||||
"emoji-regex": "^9.2.2",
|
||||
"eris": "github:abalabahaha/eris#dev",
|
||||
"eris": "^0.15.1",
|
||||
"eris-fleet": "github:esmBot/eris-fleet",
|
||||
"file-type": "^16.1.0",
|
||||
"format-duration": "^1.4.0",
|
||||
|
|
|
@ -125,21 +125,21 @@ export async function nextSong(client, message, connection, track, info, music,
|
|||
}
|
||||
});
|
||||
}
|
||||
connection.removeAllListeners("error");
|
||||
connection.removeAllListeners("end");
|
||||
await connection.play(track);
|
||||
players.set(voiceChannel.guild.id, { player: connection, type: music ? "music" : "sound", host: message.author.id, voiceChannel: voiceChannel, originalChannel: message.channel, loop: loop, playMessage: playingMessage });
|
||||
if (connection.listeners("error").length === 0) {
|
||||
connection.on("error", (error) => {
|
||||
connection.once("error", (error) => {
|
||||
if (playingMessage.channel.messages.get(playingMessage.id)) playingMessage.delete();
|
||||
const playMessage = players.get(voiceChannel.guild.id).playMessage;
|
||||
if (playMessage.channel.messages.get(playMessage.id)) playMessage.delete();
|
||||
manager.leave(voiceChannel.guild.id);
|
||||
connection.removeAllListeners("end");
|
||||
connection.destroy();
|
||||
players.delete(voiceChannel.guild.id);
|
||||
queues.delete(voiceChannel.guild.id);
|
||||
logger.error(error);
|
||||
});
|
||||
}
|
||||
if (connection.listeners("end").length === 0) {
|
||||
connection.on("end", async (data) => {
|
||||
if (data.reason === "REPLACED") return;
|
||||
const queue = queues.get(voiceChannel.guild.id);
|
||||
|
@ -175,5 +175,4 @@ export async function nextSong(client, message, connection, track, info, music,
|
|||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue