Added remove, fixed reload and broadcast

This commit is contained in:
Essem 2021-11-21 14:23:25 -06:00
parent e179b923f0
commit 514166c79f
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
5 changed files with 29 additions and 7 deletions

View file

@ -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"];

View file

@ -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);
});
});
}

View file

@ -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()) {

23
commands/music/remove.js Normal file
View file

@ -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;

View file

@ -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");