Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent members outside music channel from modifying the queue
- Loading branch information
1 parent
2dccd98
commit 9700cff
Showing
9 changed files
with
87 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
const { canModifyQueue } = require("../util/EvobotUtil"); | ||
|
||
module.exports = { | ||
name: "loop", | ||
aliases: ['l'], | ||
description: "Toggle music loop", | ||
execute(message) { | ||
const serverQueue = message.client.queue.get(message.guild.id); | ||
if (!serverQueue) return message.reply("There is nothing playing.").catch(console.error); | ||
if (!canModifyQueue(message.member)) return; | ||
|
||
const queue = message.client.queue.get(message.guild.id); | ||
if (!queue) return message.reply("There is nothing playing.").catch(console.error); | ||
|
||
// toggle from false to true and reverse | ||
serverQueue.loop = !serverQueue.loop; | ||
return serverQueue.textChannel | ||
.send(`Loop is now ${serverQueue.loop ? "**on**" : "**off**"}`) | ||
queue.loop = !queue.loop; | ||
return queue.textChannel | ||
.send(`Loop is now ${queue.loop ? "**on**" : "**off**"}`) | ||
.catch(console.error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
const { canModifyQueue } = require("../util/EvobotUtil"); | ||
|
||
module.exports = { | ||
name: "pause", | ||
description: "Pause the currently playing music", | ||
execute(message) { | ||
if (!message.member.voice.channel) | ||
return message.reply("You need to join a voice channel first!").catch(console.error); | ||
if (!canModifyQueue(message.member)) return | ||
|
||
const serverQueue = message.client.queue.get(message.guild.id); | ||
if (serverQueue && serverQueue.playing) { | ||
serverQueue.playing = false; | ||
serverQueue.connection.dispatcher.pause(true); | ||
return serverQueue.textChannel.send(`${message.author} ⏸ paused the music.`).catch(console.error); | ||
const queue = message.client.queue.get(message.guild.id); | ||
if (queue && queue.playing) { | ||
queue.playing = false; | ||
queue.connection.dispatcher.pause(true); | ||
return queue.textChannel.send(`${message.author} ⏸ paused the music.`).catch(console.error); | ||
} | ||
|
||
return message.reply("There is nothing playing.").catch(console.error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
const { canModifyQueue } = require("../util/EvobotUtil"); | ||
|
||
module.exports = { | ||
name: "remove", | ||
description: "Remove song from the queue", | ||
execute(message, args) { | ||
if (!canModifyQueue(message.member)) return; | ||
|
||
if (!args.length) return message.reply(`Usage: ${message.client.prefix}remove <Queue Number>`); | ||
const serverQueue = message.client.queue.get(message.guild.id); | ||
if (!serverQueue) return message.channel.send("There is no queue.").catch(console.error); | ||
if (isNaN(args[0])) return message.reply(`Usage: ${message.client.prefix}remove <Queue Number>`); | ||
|
||
const queue = message.client.queue.get(message.guild.id); | ||
if (!queue) return message.channel.send("There is no queue.").catch(console.error); | ||
|
||
const song = serverQueue.songs.splice(args[0] - 1, 1); | ||
serverQueue.textChannel.send(`${message.author} ❌ removed **${song[0].title}** from the queue.`); | ||
const song = queue.songs.splice(args[0] - 1, 1); | ||
queue.textChannel.send(`${message.author} ❌ removed **${song[0].title}** from the queue.`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
const { canModifyQueue } = require("../util/EvobotUtil"); | ||
|
||
module.exports = { | ||
name: "shuffle", | ||
description: "Shuffle queue", | ||
execute(message) { | ||
const serverQueue = message.client.queue.get(message.guild.id); | ||
if (!canModifyQueue(message.member)) return; | ||
|
||
const queue = message.client.queue.get(message.guild.id); | ||
|
||
if (!message.member.voice.channel) | ||
return message.reply("You need to join a voice channel first!").catch(console.error); | ||
if (!serverQueue) | ||
if (!queue) | ||
return message.channel.send("Playlist is empty.").catch(console.error); | ||
|
||
let songs = serverQueue.songs; | ||
let songs = queue.songs; | ||
for (let i = songs.length - 1; i > 1; i--) { | ||
let j = 1 + Math.floor(Math.random() * (i)); | ||
[songs[i], songs[j]] = [songs[j], songs[i]]; | ||
} | ||
serverQueue.songs = songs; | ||
message.client.queue.set(message.guild.id, serverQueue); | ||
serverQueue.textChannel.send(`${message.author} 🔀 shuffled the queue`).catch(console.error); | ||
queue.songs = songs; | ||
message.client.queue.set(message.guild.id, queue); | ||
queue.textChannel.send(`${message.author} 🔀 shuffled the queue`).catch(console.error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
const { canModifyQueue } = require("../util/EvobotUtil"); | ||
|
||
module.exports = { | ||
name: "skip", | ||
aliases: ['s'], | ||
description: "Skip the currently playing song", | ||
execute(message) { | ||
const serverQueue = message.client.queue.get(message.guild.id); | ||
if (!canModifyQueue(message.member)) return; | ||
|
||
if (!message.member.voice.channel) | ||
return message.reply("You need to join a voice channel first!").catch(console.error); | ||
if (!serverQueue) | ||
const queue = message.client.queue.get(message.guild.id); | ||
if (!queue) | ||
return message.channel.send("There is nothing playing that I could skip for you.").catch(console.error); | ||
|
||
serverQueue.connection.dispatcher.end(); | ||
serverQueue.textChannel.send(`${message.author} ⏭ skipped the song`).catch(console.error); | ||
queue.connection.dispatcher.end(); | ||
queue.textChannel.send(`${message.author} ⏭ skipped the song`).catch(console.error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
const { canModifyQueue } = require("../util/EvobotUtil"); | ||
|
||
|
||
module.exports = { | ||
name: "stop", | ||
description: "Stops the music", | ||
execute(message) { | ||
const serverQueue = message.client.queue.get(message.guild.id); | ||
if (!canModifyQueue(message.member)) return; | ||
|
||
if (!message.member.voice.channel) | ||
return message.reply("You need to join a voice channel first!").catch(console.error); | ||
if (!serverQueue) return message.reply("There is nothing playing.").catch(console.error); | ||
const queue = message.client.queue.get(message.guild.id); | ||
if (!queue) return message.reply("There is nothing playing.").catch(console.error); | ||
|
||
serverQueue.songs = []; | ||
serverQueue.connection.dispatcher.end(); | ||
serverQueue.textChannel.send(`${message.author} ⏹ stopped the music!`).catch(console.error); | ||
queue.songs = []; | ||
queue.connection.dispatcher.end(); | ||
queue.textChannel.send(`${message.author} ⏹ stopped the music!`).catch(console.error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
canModifyQueue(member) { | ||
const { channel } = member.voice; | ||
const botChannel = member.guild.me.voice.channel; | ||
|
||
if (channel !== botChannel) { | ||
member.send("You need to join the voice channel first!").catch(console.error); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
}; |