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!";
const player = this.connection;
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!";
const newObject = {
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);
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 {
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 {
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 { random } from "../utils/misc.js";
@ -22,6 +22,7 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
connection.player.destroy();
players.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.");
}
});
@ -40,6 +41,7 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
connection.player.destroy();
players.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.");
} else {
const randomMember = random(members);
@ -54,6 +56,7 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
connection.player.destroy();
players.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.");
}
}

View file

@ -110,11 +110,11 @@ export async function nextSong(client, message, connection, track, info, music,
},
"fields": [{
"name": " Title:",
"value": info.title
"value": info.title !== "" ? info.title : "(blank)"
},
{
"name": "🎤 Artist:",
"value": info.author
"value": info.author !== "" ? info.author : "(blank)"
},
{
"name": "💬 Channel:",
@ -130,6 +130,7 @@ export async function nextSong(client, message, connection, track, info, music,
connection.removeAllListeners("error");
connection.removeAllListeners("end");
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 });
connection.once("error", (error) => {
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();
players.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.");
try {
if (playingMessage.channel.messages.get(playingMessage.id)) await playingMessage.delete();