Replace Lavalink wrapper, migrate to pnpm, add ko-fi sponsor link

This commit is contained in:
Essem 2022-06-14 00:38:01 -05:00
parent cefafba8fb
commit 10becff3a0
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
19 changed files with 2768 additions and 8025 deletions

View file

@ -20,10 +20,8 @@ class AvatarCommand extends Command {
return self.dynamicAvatarURL(null, 512);
}
} else if (this.args.join(" ") !== "" && this.channel.guild) {
console.log(member);
const searched = await this.channel.guild.searchMembers(this.args.join(" "));
if (searched.length === 0) return self.dynamicAvatarURL(null, 512);
console.log(searched);
const user = await this.client.getRESTUser(searched[0].user.id);
return user ? user.dynamicAvatarURL(null, 512) : self.dynamicAvatarURL(null, 512);
} else {

View file

@ -6,7 +6,7 @@ class CaptionTwoCommand extends ImageCommand {
params(url) {
const newArgs = this.options.text ?? this.args.filter(item => !item.includes(url)).join(" ");
return {
caption: newArgs && newArgs.trim() ? newArgs.replaceAll("&", "&amp;").replaceAll(">", "&gt;").replaceAll("<", "&lt;").replaceAll("\"", "&quot;").replaceAll("'", "&apos;").replaceAll("%", "%").replaceAll("\\n", "\n") : words.sort(() => 0.5 - Math.random()).slice(0, Math.floor(Math.random() * words.length + 1)).join(" "),
caption: newArgs && newArgs.trim() ? newArgs.replaceAll("&", "&amp;").replaceAll(">", "&gt;").replaceAll("<", "&lt;").replaceAll("\"", "&quot;").replaceAll("'", "&apos;").replaceAll("\\n", "\n") : words.sort(() => 0.5 - Math.random()).slice(0, Math.floor(Math.random() * words.length + 1)).join(" "),
top: !!this.specialArgs.top,
font: this.specialArgs.font && allowedFonts.includes(this.specialArgs.font.toLowerCase()) ? this.specialArgs.font.toLowerCase() : "helvetica"
};

View file

@ -1,4 +1,3 @@
import { Rest } from "lavacord";
import format from "format-duration";
import MusicCommand from "../../classes/musicCommand.js";
@ -9,8 +8,8 @@ class NowPlayingCommand extends MusicCommand {
if (!this.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!";
const player = this.connection.player;
if (!player) return "I'm not playing anything!";
const track = await Rest.decode(player.node, player.track);
const parts = Math.floor((player.state.position / track.length) * 10);
const track = await player.node.rest.decode(player.track);
const parts = Math.floor((player.position / track.length) * 10);
return {
embeds: [{
color: 16711680,
@ -32,7 +31,7 @@ class NowPlayingCommand extends MusicCommand {
},
{
name: `${"▬".repeat(parts)}🔘${"▬".repeat(10 - parts)}`,
value: `${format(player.state.position)}/${track.isStream ? "∞" : format(track.length)}`
value: `${format(player.position)}/${track.isStream ? "∞" : format(track.length)}`
}]
}]
};

View file

@ -1,6 +1,6 @@
//import { Rest } from "lavacord";
import fetch from "node-fetch";
import format from "format-duration";
import { nodes } from "../../utils/soundplayer.js";
import paginator from "../../utils/pagination/pagination.js";
import MusicCommand from "../../classes/musicCommand.js";
@ -11,8 +11,8 @@ class QueueCommand extends MusicCommand {
if (!this.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!";
if (!this.channel.permissionsOf(this.client.user.id).has("embedLinks")) return "I don't have the `Embed Links` permission!";
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(this.queue), headers: { Authorization: player.player.node.password, "Content-Type": "application/json" } }).then(res => res.json());
const node = nodes.filter((val) => { return val.name === player.player.node.name })[0];
const tracks = await fetch(`http://${node.url}/decodetracks`, { method: "POST", body: JSON.stringify(this.queue), headers: { Authorization: node.auth, "Content-Type": "application/json" } }).then(res => res.json());
const trackList = [];
const firstTrack = tracks.shift();
for (const [i, track] of tracks.entries()) {

View file

@ -1,4 +1,3 @@
import { Rest } from "lavacord";
import { queues } from "../../utils/soundplayer.js";
import MusicCommand from "../../classes/musicCommand.js";
@ -11,7 +10,8 @@ class RemoveCommand extends MusicCommand {
const pos = parseInt(this.options.position ?? 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]);
if (removed.length === 0) return "That's not a valid position!";
const track = await this.connection.player.node.rest.decode(removed[0]);
queues.set(this.channel.guild.id, this.queue);
return `🔊 The song \`${track.title ? track.title : "(blank)"}\` has been removed from the queue.`;
}

View file

@ -1,4 +1,3 @@
import { Rest } from "lavacord";
import MusicCommand from "../../classes/musicCommand.js";
class SeekCommand extends MusicCommand {
@ -8,11 +7,11 @@ class SeekCommand extends MusicCommand {
if (!this.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!";
if (this.connection.host !== this.author.id) return "Only the current voice session host can seek the music!";
const player = this.connection.player;
const track = await Rest.decode(player.node, player.track);
const track = await player.node.rest.decode(player.track);
if (!track.isSeekable) return "This track isn't seekable!";
const seconds = parseFloat(this.options.position ?? this.args[0]);
if (isNaN(seconds) || (seconds * 1000) > track.length || (seconds * 1000) < 0) return "That's not a valid position!";
await player.seek(seconds * 1000);
player.seekTo(seconds * 1000);
return `🔊 Seeked track to ${seconds} second(s).`;
}

View file

@ -16,7 +16,7 @@ class SkipCommand extends MusicCommand {
max: votes.max
};
if (votes.count + 1 === votes.max) {
await player.player.stop(this.channel.guild.id);
await player.player.stopTrack(this.channel.guild.id);
skipVotes.set(this.channel.guild.id, { count: 0, ids: [], max: Math.min(3, player.voiceChannel.voiceMembers.filter((i) => i.id !== this.client.user.id && !i.bot).length) });
if (this.type === "application") return "🔊 The current song has been skipped.";
} else {
@ -24,7 +24,7 @@ class SkipCommand extends MusicCommand {
return `🔊 Voted to skip song (${votes.count + 1}/${votes.max} people have voted).`;
}
} else {
await player.player.stop(this.channel.guild.id);
await player.player.stopTrack();
if (this.type === "application") return "🔊 The current song has been skipped.";
}
}

View file

@ -7,13 +7,12 @@ class StopCommand extends MusicCommand {
if (!this.member.voiceState.channelID) return "You need to be in a voice channel first!";
if (!this.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!";
if (!this.connection) {
await manager.leave(this.channel.guild.id);
await manager.getNode().leaveChannel(this.channel.guild.id);
return "🔊 The current voice channel session has ended.";
}
if (this.connection.host !== this.author.id && !this.member.permissions.has("manageChannels")) return "Only the current voice session host can stop the music!";
await manager.leave(this.channel.guild.id);
const connection = this.connection.player;
await connection.destroy();
connection.node.leaveChannel(this.channel.guild.id);
players.delete(this.channel.guild.id);
queues.delete(this.channel.guild.id);
return "🔊 The current voice channel session has ended.";

View file

@ -7,7 +7,7 @@ class ToggleCommand extends MusicCommand {
if (!this.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!";
if (this.connection.host !== this.author.id && !this.member.permissions.has("manageChannels")) return "Only the current voice session host can pause/resume the music!";
const player = this.connection.player;
await player.pause(!player.paused ? true : false);
player.setPaused(!player.paused ? true : false);
return `🔊 The player has been ${player.paused ? "paused" : "resumed"}.`;
}