Set max skip vote amount based on number of users in voice chat, remove skip votes when session ends

This commit is contained in:
Essem 2021-09-19 17:49:02 -05:00
parent abfbfe14fe
commit 3517826f46
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
3 changed files with 14 additions and 8 deletions

View file

@ -8,18 +8,19 @@ class SkipCommand extends MusicCommand {
if (!this.message.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!"; if (!this.message.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!";
const player = this.connection; const player = this.connection;
if (player.host !== this.message.author.id) { if (player.host !== this.message.author.id) {
const votes = skipVotes.has(this.message.channel.guild.id) ? skipVotes.get(this.message.channel.guild.id) : { count: 0, ids: [] }; const votes = skipVotes.has(this.message.channel.guild.id) ? skipVotes.get(this.message.channel.guild.id) : { count: 0, ids: [], max: Math.min(3, player.voiceChannel.voiceMembers.size - 1) };
if (votes.ids.includes(this.message.author.id)) return "You've already voted to skip!"; if (votes.ids.includes(this.message.author.id)) return "You've already voted to skip!";
const newObject = { const newObject = {
count: votes.count + 1, count: votes.count + 1,
ids: [...votes.ids, this.message.author.id].filter(item => !!item) ids: [...votes.ids, this.message.author.id].filter(item => !!item),
max: votes.max
}; };
if (votes.count + 1 === 3) { if (votes.count + 1 === votes.max) {
player.player.stop(this.message.channel.guild.id); player.player.stop(this.message.channel.guild.id);
skipVotes.set(this.message.channel.guild.id, { count: 0, ids: [] }); skipVotes.set(this.message.channel.guild.id, { count: 0, ids: [], max: Math.min(3, player.voiceChannel.voiceMembers.size - 1) });
} else { } else {
skipVotes.set(this.message.channel.guild.id, newObject); skipVotes.set(this.message.channel.guild.id, newObject);
return `🔊 Voted to skip song (${votes.count + 1}/3 people have voted).`; return `🔊 Voted to skip song (${votes.count + 1}/${votes.max} people have voted).`;
} }
} else { } else {
player.player.stop(this.message.channel.guild.id); player.player.stop(this.message.channel.guild.id);

View file

@ -1,4 +1,4 @@
import { players, manager, queues } from "../utils/soundplayer.js"; import { players, manager, queues, skipVotes } from "../utils/soundplayer.js";
import AwaitRejoin from "../utils/awaitrejoin.js"; import AwaitRejoin from "../utils/awaitrejoin.js";
import { random } from "../utils/misc.js"; import { random } from "../utils/misc.js";
@ -22,6 +22,7 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
connection.player.destroy(); connection.player.destroy();
players.delete(connection.originalChannel.guild.id); players.delete(connection.originalChannel.guild.id);
queues.delete(connection.originalChannel.guild.id); queues.delete(connection.originalChannel.guild.id);
skipVotes.delete(connection.originalChannel.guild.id);
client.createMessage(connection.originalChannel.id, "🔊 The current voice channel session has ended."); client.createMessage(connection.originalChannel.id, "🔊 The current voice channel session has ended.");
} }
}); });
@ -40,6 +41,7 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
connection.player.destroy(); connection.player.destroy();
players.delete(connection.originalChannel.guild.id); players.delete(connection.originalChannel.guild.id);
queues.delete(connection.originalChannel.guild.id); queues.delete(connection.originalChannel.guild.id);
skipVotes.delete(connection.originalChannel.guild.id);
client.createMessage(connection.originalChannel.id, "🔊 The current voice channel session has ended."); client.createMessage(connection.originalChannel.id, "🔊 The current voice channel session has ended.");
} else { } else {
const randomMember = random(members); const randomMember = random(members);
@ -54,6 +56,7 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
connection.player.destroy(); connection.player.destroy();
players.delete(connection.originalChannel.guild.id); players.delete(connection.originalChannel.guild.id);
queues.delete(connection.originalChannel.guild.id); queues.delete(connection.originalChannel.guild.id);
skipVotes.delete(connection.originalChannel.guild.id);
await client.createMessage(connection.originalChannel.id, "🔊 The current voice channel session has ended."); await client.createMessage(connection.originalChannel.id, "🔊 The current voice channel session has ended.");
} }
} }

View file

@ -110,11 +110,11 @@ export async function nextSong(client, message, connection, track, info, music,
}, },
"fields": [{ "fields": [{
"name": " Title:", "name": " Title:",
"value": info.title "value": info.title !== "" ? info.title : "(blank)"
}, },
{ {
"name": "🎤 Artist:", "name": "🎤 Artist:",
"value": info.author "value": info.author !== "" ? info.author : "(blank)"
}, },
{ {
"name": "💬 Channel:", "name": "💬 Channel:",
@ -130,6 +130,7 @@ export async function nextSong(client, message, connection, track, info, music,
connection.removeAllListeners("error"); connection.removeAllListeners("error");
connection.removeAllListeners("end"); connection.removeAllListeners("end");
await connection.play(track); await connection.play(track);
await connection.volume(75);
players.set(voiceChannel.guild.id, { player: connection, type: music ? "music" : "sound", host: message.author.id, voiceChannel: voiceChannel, originalChannel: message.channel, loop: loop, playMessage: playingMessage }); players.set(voiceChannel.guild.id, { player: connection, type: music ? "music" : "sound", host: message.author.id, voiceChannel: voiceChannel, originalChannel: message.channel, loop: loop, playMessage: playingMessage });
connection.once("error", (error) => { connection.once("error", (error) => {
if (playingMessage.channel.messages.get(playingMessage.id)) playingMessage.delete(); if (playingMessage.channel.messages.get(playingMessage.id)) playingMessage.delete();
@ -159,6 +160,7 @@ export async function nextSong(client, message, connection, track, info, music,
connection.destroy(); connection.destroy();
players.delete(voiceChannel.guild.id); players.delete(voiceChannel.guild.id);
queues.delete(voiceChannel.guild.id); queues.delete(voiceChannel.guild.id);
skipVotes.delete(voiceChannel.guild.id);
if (music) await client.createMessage(message.channel.id, "🔊 The current voice channel session has ended."); if (music) await client.createMessage(message.channel.id, "🔊 The current voice channel session has ended.");
try { try {
if (playingMessage.channel.messages.get(playingMessage.id)) await playingMessage.delete(); if (playingMessage.channel.messages.get(playingMessage.id)) await playingMessage.delete();