diff --git a/classes/musicCommand.js b/classes/musicCommand.js index 6253acf..fce63c9 100644 --- a/classes/musicCommand.js +++ b/classes/musicCommand.js @@ -1,10 +1,11 @@ import Command from "./command.js"; -import { players } from "../utils/soundplayer.js"; +import { players, queues } from "../utils/soundplayer.js"; class MusicCommand extends Command { constructor(client, cluster, worker, ipc, message, args, content, specialArgs) { super(client, cluster, worker, ipc, message, args, content, specialArgs); this.connection = players.get(message.channel.guild.id); + this.queue = queues.get(message.channel.guild.id); } static requires = ["sound"]; diff --git a/commands/general/reload.js b/commands/general/reload.js index e5c7f25..c1ee3a2 100644 --- a/commands/general/reload.js +++ b/commands/general/reload.js @@ -16,7 +16,7 @@ class ReloadCommand extends Command { this.ipc.register("reloadFail", (message) => { this.ipc.unregister("reloadSuccess"); this.ipc.unregister("reloadFail"); - resolve(message.msg.result); + resolve(message.result); }); }); } diff --git a/commands/music/queue.js b/commands/music/queue.js index a112e42..385c792 100644 --- a/commands/music/queue.js +++ b/commands/music/queue.js @@ -1,4 +1,3 @@ -import { queues } from "../../utils/soundplayer.js"; //import { Rest } from "lavacord"; import fetch from "node-fetch"; import format from "format-duration"; @@ -11,10 +10,9 @@ class QueueCommand extends MusicCommand { if (!this.message.member.voiceState.channelID) return "You need to be in a voice channel first!"; 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.permissionsOf(this.client.user.id).has("embedLinks")) return "I don't have the `Embed Links` permission!"; - const queue = queues.get(this.message.channel.guild.id); const player = this.connection; //const tracks = await Rest.decode(player.player.node, queue); - const tracks = await fetch(`http://${player.player.node.host}:${player.player.node.port}/decodetracks`, { method: "POST", body: JSON.stringify(queue), headers: { Authorization: player.player.node.password, "Content-Type": "application/json" } }).then(res => res.json()); + const tracks = await fetch(`http://${player.player.node.host}:${player.player.node.port}/decodetracks`, { method: "POST", body: JSON.stringify(this.queue), headers: { Authorization: player.player.node.password, "Content-Type": "application/json" } }).then(res => res.json()); const trackList = []; const firstTrack = tracks.shift(); for (const [i, track] of tracks.entries()) { diff --git a/commands/music/remove.js b/commands/music/remove.js new file mode 100644 index 0000000..7983675 --- /dev/null +++ b/commands/music/remove.js @@ -0,0 +1,23 @@ +import { Rest } from "lavacord"; +import { queues } from "../../utils/soundplayer.js"; +import MusicCommand from "../../classes/musicCommand.js"; + +class RemoveCommand extends MusicCommand { + async run() { + if (!this.message.channel.guild) return "This command only works in servers!"; + if (!this.message.member.voiceState.channelID) return "You need to be in a voice channel first!"; + if (!this.message.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!"; + if (this.connection.host !== this.message.author.id) return "Only the current voice session host can remove songs from the queue!"; + const pos = parseInt(this.args[0]); + if (isNaN(pos) || pos > this.queue.length || pos < 1) return "That's not a valid position!"; + const removed = this.queue.splice(pos, 1); + const track = await Rest.decode(this.connection.player.node, removed[0]); + queues.set(this.message.channel.guild.id, this.queue); + return `🔊 The song \`${track.title !== "" ? track.title : "(blank)"}\` has been removed from the queue.`; + } + + static description = "Removes a song from the queue"; + static aliases = ["rm"]; +} + +export default RemoveCommand; \ No newline at end of file diff --git a/shard.js b/shard.js index e3fd894..3ed48f7 100644 --- a/shard.js +++ b/shard.js @@ -64,7 +64,7 @@ class Shard extends BaseClusterWorker { } this.ipc.register("reload", async (message) => { - const path = paths.get(message.msg); + const path = paths.get(message); if (!path) return this.ipc.broadcast("reloadFail", { result: "I couldn't find that command!" }); const result = await load(path, await checkStatus()); if (result) return this.ipc.broadcast("reloadFail", { result }); @@ -85,7 +85,7 @@ class Shard extends BaseClusterWorker { this.ipc.register("playbroadcast", (message) => { this.bot.editStatus("dnd", { - name: `${message.msg} | @${this.bot.user.username} help`, + name: `${message} | @${this.bot.user.username} help`, }); broadcast = true; return this.ipc.broadcast("broadcastSuccess");