1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-11-14 22:10:18 +00:00
musix-oss/src/commands/skip.js
2020-04-20 19:56:23 +03:00

63 lines
2.0 KiB
JavaScript

module.exports = {
name: "skip",
alias: "s",
usage: "",
description: "Skip the currently playing song.",
onlyDev: false,
permission: "MANAGE_MESSAGES",
category: "music",
execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id);
const permissions = msg.channel.permissionsFor(msg.author);
if (!queue || !queue.playing)
return msg.channel.send(client.messages.noServerQueue);
if (msg.author.id !== client.config.devId) {
if (msg.member.voice.channel !== queue.voiceChannel)
return msg.channel.send(client.messages.wrongVoiceChannel);
if (client.global.db.guilds[msg.guild.id].permissions) {
if (
!msg.member.roles.cache.has(
client.global.db.guilds[msg.guild.id].djrole
) ||
!permissions.has(command.permission)
) {
return vote(queue, msg, client);
} else {
return skipSong(queue, msg, client);
}
} else {
return skipSong(queue, msg, client);
}
} else {
return skipSong(queue, msg, client);
}
},
};
function skipSong(queue, msg, client) {
msg.channel.send(client.messages.skipped);
queue.endReason = "skip";
queue.time = 0;
queue.connection.dispatcher.end();
}
function vote(queue, msg, client) {
queue.votesNeeded = Math.floor(queue.voiceChannel.members.size / 2);
queue.votesNeeded.toFixed();
if (queue.voiceChannel.members.size > 2) {
if (queue.voters.includes(msg.member.id))
return msg.channel.send(client.messages.alreadyVoted);
queue.votes++;
queue.voters.push(msg.member.id);
if (queue.votes >= queue.votesNeeded) {
queue.voters = [];
queue.votes = 0;
queue.votesNeeded = null;
return skipSong(queue, msg, client);
} else
return msg.channel.send(
`${client.messages.notEnoughVotes} ${queue.votes} / ${queue.votesNeeded}!`
);
} else {
return skipSong(queue, msg, client);
}
}