From 9be36e71998bd1159a2e9ff729343e33469bb509 Mon Sep 17 00:00:00 2001 From: murm Date: Sat, 18 Mar 2023 20:01:28 -0400 Subject: [PATCH] removed music commands --- commands/music/host.js | 60 --------------------------------- commands/music/loop.js | 23 ------------- commands/music/music.js | 48 -------------------------- commands/music/nowplaying.js | 51 ---------------------------- commands/music/play.js | 41 ----------------------- commands/music/queue.js | 65 ------------------------------------ commands/music/remove.js | 33 ------------------ commands/music/seek.js | 38 --------------------- commands/music/shuffle.js | 23 ------------- commands/music/skip.js | 41 ----------------------- commands/music/stop.js | 28 ---------------- commands/music/toggle.js | 21 ------------ 12 files changed, 472 deletions(-) delete mode 100644 commands/music/host.js delete mode 100644 commands/music/loop.js delete mode 100644 commands/music/music.js delete mode 100644 commands/music/nowplaying.js delete mode 100644 commands/music/play.js delete mode 100644 commands/music/queue.js delete mode 100644 commands/music/remove.js delete mode 100644 commands/music/seek.js delete mode 100644 commands/music/shuffle.js delete mode 100644 commands/music/skip.js delete mode 100644 commands/music/stop.js delete mode 100644 commands/music/toggle.js diff --git a/commands/music/host.js b/commands/music/host.js deleted file mode 100644 index 008d52b..0000000 --- a/commands/music/host.js +++ /dev/null @@ -1,60 +0,0 @@ -import { players } from "../../utils/soundplayer.js"; -import MusicCommand from "../../classes/musicCommand.js"; - -class HostCommand extends MusicCommand { - async run() { - this.success = false; - if (!this.guild) return "This command only works in servers!"; - if (!this.member.voiceState) return "You need to be in a voice channel first!"; - if (!this.guild.voiceStates.has(this.client.user.id)) return "I'm not in a voice channel!"; - if (!this.connection) return "I haven't completely connected yet!"; - if (this.connection.host !== this.author && !process.env.OWNER.split(",").includes(this.connection.host)) return "Only the current voice session host can choose another host!"; - const input = this.options.user ?? this.args.join(" "); - if (input?.trim()) { - let user; - if (this.type === "classic") { - const getUser = this.message.mentions.users.length >= 1 ? this.message.mentions.users[0] : this.client.users.get(input); - if (getUser) { - user = getUser; - } else if (input.match(/^?$/) && input >= 21154535154122752n) { - try { - user = await this.client.rest.users.get(input); - } catch { - // no-op - } - } else { - const userRegex = new RegExp(input.split(" ").join("|"), "i"); - const member = this.client.users.find(element => { - return userRegex.test(element.username); - }); - user = member; - } - } else { - user = input; - } - if (!user) return "I can't find that user!"; - if (user.bot) return "This is illegal, you know."; - const member = this.guild.members.get(user.id); - if (!member) return "That user isn't in this server!"; - const object = this.connection; - object.host = member.id; - players.set(this.guildID, object); - this.success = true; - return `🔊 ${member.mention} is the new voice channel host.`; - } else { - const member = this.guild.members.get(players.get(this.guild.id).host); - this.success = true; - return `🔊 The current voice channel host is **${member?.username}#${member?.discriminator}**.`; - } - } - - static flags = [{ - name: "user", - type: 6, - description: "The user you want the new host to be" - }]; - static description = "Gets or changes the host of the current voice session"; - static aliases = ["sethost"]; -} - -export default HostCommand; diff --git a/commands/music/loop.js b/commands/music/loop.js deleted file mode 100644 index 951d278..0000000 --- a/commands/music/loop.js +++ /dev/null @@ -1,23 +0,0 @@ -import { players } from "../../utils/soundplayer.js"; -import MusicCommand from "../../classes/musicCommand.js"; - -class LoopCommand extends MusicCommand { - async run() { - this.success = false; - if (!this.guild) return "This command only works in servers!"; - if (!this.member.voiceState) return "You need to be in a voice channel first!"; - if (!this.guild.voiceStates.has(this.client.user.id)) return "I'm not in a voice channel!"; - if (!this.connection) return "I haven't completely connected yet!"; - if (this.connection.host !== this.author && !this.member.permissions.has("MANAGE_CHANNELS")) return "Only the current voice session host can loop the music!"; - const object = this.connection; - object.loop = !object.loop; - players.set(this.guild.id, object); - this.success = true; - return object.loop ? "🔊 The player is now looping." : "🔊 The player is no longer looping."; - } - - static description = "Loops the music"; - static aliases = ["toggleloop", "repeat"]; -} - -export default LoopCommand; \ No newline at end of file diff --git a/commands/music/music.js b/commands/music/music.js deleted file mode 100644 index 3be88bc..0000000 --- a/commands/music/music.js +++ /dev/null @@ -1,48 +0,0 @@ -import Command from "../../classes/command.js"; -import { commands, aliases, info, categories } from "../../utils/collections.js"; - -// all-in-one music command -class MusicAIOCommand extends Command { - async run() { - let cmd = this.type === "classic" ? this.args[0] : this.optionsArray[0].name; - if (cmd === "music" || this.constructor.aliases.includes(cmd)) return "https://esmbot.net/robotdance.gif"; - // await this.acknowledge(); - if (this.type === "classic") { - this.origOptions.args.shift(); - } else { - this.origOptions.interaction.data.options.raw = this.origOptions.interaction.data.options.raw[0].options; - } - if (aliases.has(cmd)) cmd = aliases.get(cmd); - if (commands.has(cmd) && info.get(cmd).category === "music") { - const command = commands.get(cmd); - const inst = new command(this.client, this.origOptions); - const result = await inst.run(); - this.success = inst.success; - return result; - } else { - this.success = false; - return "That isn't a valid music command!"; - } - } - - static postInit() { - this.flags = []; - for (const cmd of categories.get("music")) { - if (cmd === "music") continue; - const cmdInfo = info.get(cmd); - this.flags.push({ - name: cmd, - type: 1, - description: cmdInfo.description, - options: cmdInfo.flags - }); - } - return this; - } - - static description = "Handles music playback"; - static aliases = ["m"]; - static directAllowed = false; -} - -export default MusicAIOCommand; diff --git a/commands/music/nowplaying.js b/commands/music/nowplaying.js deleted file mode 100644 index f453048..0000000 --- a/commands/music/nowplaying.js +++ /dev/null @@ -1,51 +0,0 @@ -import format from "format-duration"; -import MusicCommand from "../../classes/musicCommand.js"; - -class NowPlayingCommand extends MusicCommand { - async run() { - this.success = false; - if (!this.guild) return "This command only works in servers!"; - if (!this.member.voiceState) return "You need to be in a voice channel first!"; - if (!this.guild.voiceStates.has(this.client.user.id)) return "I'm not in a voice channel!"; - if (!this.connection) return "I haven't completely connected yet!"; - const player = this.connection.player; - if (!player) return "I'm not playing anything!"; - const track = await player.node.rest.decode(player.track); - const parts = Math.floor((player.position / track.length) * 10); - this.success = true; - return { - embeds: [{ - color: 16711680, - author: { - name: "Now Playing", - iconURL: this.client.user.avatarURL() - }, - fields: [{ - name: "ℹī¸ Title", - value: track.title ? track.title : "Unknown" - }, - { - name: "🎤 Artist", - value: track.author ? track.author : "Unknown" - }, - { - name: "đŸ’Ŧ Channel", - value: (this.guild.channels.get(this.member.voiceState.channelID) ?? await this.client.rest.channels.get(this.member.voiceState.channelID)).name - }, - { - name: "🌐 Node", - value: player.node ? player.node.name : "Unknown" - }, - { - name: `${"â–Ŧ".repeat(parts)}🔘${"â–Ŧ".repeat(10 - parts)}`, - value: `${format(player.position)}/${track.isStream ? "∞" : format(track.length)}` - }] - }] - }; - } - - static description = "Shows the currently playing song"; - static aliases = ["playing", "np", "current"]; -} - -export default NowPlayingCommand; diff --git a/commands/music/play.js b/commands/music/play.js deleted file mode 100644 index ac950a9..0000000 --- a/commands/music/play.js +++ /dev/null @@ -1,41 +0,0 @@ -import { play } from "../../utils/soundplayer.js"; -import MusicCommand from "../../classes/musicCommand.js"; -const prefixes = ["scsearch:", "spsearch:", "sprec:", "amsearch:", "dzsearch:", "dzisrc:"]; -if (process.env.YT_DISABLED !== "true") prefixes.push("ytsearch:", "ytmsearch:"); - -class PlayCommand extends MusicCommand { - async run() { - const input = this.options.query ?? this.args.join(" "); - if (!input && ((!this.message || this.message?.attachments.size <= 0))) { - this.success = false; - return "You need to provide what you want to play!"; - } - let query = input ? input.trim() : ""; - const attachment = this.type === "classic" ? this.message.attachments.first() : null; - if (query.startsWith("||") && query.endsWith("||")) { - query = query.substring(2, query.length - 2); - } - if (query.startsWith("<") && query.endsWith(">")) { - query = query.substring(1, query.length - 1); - } - try { - const url = new URL(query); - return play(this.client, url, { channel: this.channel, member: this.member, type: this.type, interaction: this.interaction }, true); - } catch { - const search = prefixes.some(v => query.startsWith(v)) ? query : !query && attachment ? attachment.url : (process.env.YT_DISABLED !== "true" ? `ytsearch:${query}` : `dzsearch:${query}`); - return play(this.client, search, { channel: this.channel, member: this.member, type: this.type, interaction: this.interaction }, true); - } - } - - static flags = [{ - name: "query", - type: 3, - description: "An audio search query or URL", - required: true - }]; - static description = "Plays a song or adds it to the queue"; - static aliases = ["p"]; - static arguments = ["[url]"]; -} - -export default PlayCommand; diff --git a/commands/music/queue.js b/commands/music/queue.js deleted file mode 100644 index e42de7f..0000000 --- a/commands/music/queue.js +++ /dev/null @@ -1,65 +0,0 @@ -import { request } from "undici"; -import format from "format-duration"; -import { nodes } from "../../utils/soundplayer.js"; -import paginator from "../../utils/pagination/pagination.js"; -import MusicCommand from "../../classes/musicCommand.js"; - -class QueueCommand extends MusicCommand { - async run() { - this.success = false; - if (!this.guild) return "This command only works in servers!"; - if (!this.member.voiceState) return "You need to be in a voice channel first!"; - if (!this.guild.voiceStates.has(this.client.user.id)) return "I'm not in a voice channel!"; - if (!this.channel.permissionsOf(this.client.user.id.toString()).has("EMBED_LINKS")) return "I don't have the `Embed Links` permission!"; - const player = this.connection; - if (!player) return "I haven't completely connected yet!"; - const node = nodes.filter((val) => val.name === player.player.node.name)[0]; - const tracks = await request(`http://${node.url}/decodetracks`, { method: "POST", body: JSON.stringify(this.queue), headers: { authorization: node.auth, "content-type": "application/json" } }).then(res => res.body.json()); - const trackList = []; - const firstTrack = tracks.shift(); - for (const [i, track] of tracks.entries()) { - trackList.push(`${i + 1}. ${track.info.author !== "" ? track.info.author : "(blank)"} - **${track.info.title !== "" ? track.info.title : "(blank)"}** (${track.info.isStream ? "∞" : format(track.info.length)})`); - } - const pageSize = 5; - const embeds = []; - const groups = trackList.map((item, index) => { - return index % pageSize === 0 ? trackList.slice(index, index + pageSize) : null; - }).filter(Boolean); - if (groups.length === 0) groups.push("del"); - for (const [i, value] of groups.entries()) { - embeds.push({ - embeds: [{ - author: { - name: "Queue", - iconURL: this.client.user.avatarURL() - }, - color: 16711680, - footer: { - text: `Page ${i + 1} of ${groups.length}` - }, - fields: [{ - name: "đŸŽļ Now Playing", - value: `${firstTrack.info.author !== "" ? firstTrack.info.author : "(blank)"} - **${firstTrack.info.title !== "" ? firstTrack.info.title : "(blank)"}** (${firstTrack.info.isStream ? "∞" : format(firstTrack.info.length)})` - }, { - name: "🔁 Looping?", - value: player.loop ? "Yes" : "No" - }, { - name: "🌐 Node", - value: player.player.node ? player.player.node.name : "Unknown" - }, { - name: "🗒ī¸ Queue", - value: value !== "del" ? value.join("\n") : "There's nothing in the queue!" - }] - }] - }); - } - if (embeds.length === 0) return "There's nothing in the queue!"; - this.success = true; - return paginator(this.client, { type: this.type, message: this.message, interaction: this.interaction, channel: this.channel, author: this.author }, embeds); - } - - static description = "Shows the current queue"; - static aliases = ["q"]; -} - -export default QueueCommand; \ No newline at end of file diff --git a/commands/music/remove.js b/commands/music/remove.js deleted file mode 100644 index 48a0840..0000000 --- a/commands/music/remove.js +++ /dev/null @@ -1,33 +0,0 @@ -import { queues } from "../../utils/soundplayer.js"; -import MusicCommand from "../../classes/musicCommand.js"; - -class RemoveCommand extends MusicCommand { - async run() { - this.success = false; - if (!this.guild) return "This command only works in servers!"; - if (!this.member.voiceState) return "You need to be in a voice channel first!"; - if (!this.guild.voiceStates.has(this.client.user.id)) return "I'm not in a voice channel!"; - if (!this.connection) return "I haven't completely connected yet!"; - if (this.connection.host !== this.author && !process.env.OWNER.split(",").includes(this.connection.host)) return "Only the current voice session host can remove songs from the queue!"; - 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); - 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.guildID, this.queue); - this.success = true; - return `🔊 The song \`${track.title ? track.title : "(blank)"}\` has been removed from the queue.`; - } - - static flags = [{ - name: "position", - type: 4, - description: "The queue position you want to remove", - min_value: 1, - required: true - }]; - static description = "Removes a song from the queue"; - static aliases = ["rm"]; -} - -export default RemoveCommand; diff --git a/commands/music/seek.js b/commands/music/seek.js deleted file mode 100644 index dc789f0..0000000 --- a/commands/music/seek.js +++ /dev/null @@ -1,38 +0,0 @@ -import MusicCommand from "../../classes/musicCommand.js"; - -class SeekCommand extends MusicCommand { - async run() { - this.success = false; - if (!this.guild) return "This command only works in servers!"; - if (!this.member.voiceState) return "You need to be in a voice channel first!"; - if (!this.guild.voiceStates.has(this.client.user.id)) return "I'm not in a voice channel!"; - if (!this.connection) return "I haven't completely connected yet!"; - if (this.connection.host !== this.author) return "Only the current voice session host can seek the music!"; - const player = this.connection.player; - const track = await player.node.rest.decode(player.track); - if (!track.isSeekable) return "This track isn't seekable!"; - const pos = this.options.position ?? this.args[0]; - let seconds; - if (typeof pos === "string" && pos.includes(":")) { - seconds = +(pos.split(":").reduce((acc, time) => (60 * acc) + +time)); - } else { - seconds = parseFloat(pos); - } - if (isNaN(seconds) || (seconds * 1000) > track.length || (seconds * 1000) < 0) return "That's not a valid position!"; - player.seekTo(seconds * 1000); - this.success = true; - return `🔊 Seeked track to ${seconds} second(s).`; - } - - static flags = [{ - name: "position", - type: 3, - description: "Seek to this position", - required: true - }]; - static description = "Seeks to a different position in the music"; - static aliases = ["pos"]; - static arguments = ["[seconds]"]; -} - -export default SeekCommand; diff --git a/commands/music/shuffle.js b/commands/music/shuffle.js deleted file mode 100644 index 022d4d2..0000000 --- a/commands/music/shuffle.js +++ /dev/null @@ -1,23 +0,0 @@ -import { players } from "../../utils/soundplayer.js"; -import MusicCommand from "../../classes/musicCommand.js"; - -class ShuffleCommand extends MusicCommand { - async run() { - this.success = false; - if (!this.guild) return "This command only works in servers!"; - if (!this.member.voiceState) return "You need to be in a voice channel first!"; - if (!this.guild.voiceStates.has(this.client.user.id)) return "I'm not in a voice channel!"; - if (!this.connection) return "I haven't completely connected yet!"; - if (this.connection.host !== this.author) return "Only the current voice session host can shuffle the music!"; - const object = this.connection; - object.shuffle = !object.shuffle; - players.set(this.guildID, object); - this.success = true; - return object.shuffle ? "🔊 The player is now shuffling." : "🔊 The player is no longer shuffling."; - } - - static description = "Shuffles the music"; - static aliases = ["toggleshuffle"]; -} - -export default ShuffleCommand; \ No newline at end of file diff --git a/commands/music/skip.js b/commands/music/skip.js deleted file mode 100644 index 4c68d68..0000000 --- a/commands/music/skip.js +++ /dev/null @@ -1,41 +0,0 @@ -import { skipVotes } from "../../utils/soundplayer.js"; -import MusicCommand from "../../classes/musicCommand.js"; - -class SkipCommand extends MusicCommand { - async run() { - this.success = false; - if (!this.guild) return "This command only works in servers!"; - if (!this.member.voiceState) return "You need to be in a voice channel first!"; - if (!this.guild.voiceStates.has(this.client.user.id)) return "I'm not in a voice channel!"; - const player = this.connection; - if (!player) return "I haven't completely connected yet!"; - if (player.host !== this.author && !this.member.permissions.has("MANAGE_CHANNELS")) { - const votes = skipVotes.get(this.guild.id) ?? { count: 0, ids: [], max: Math.min(3, player.voiceChannel.voiceMembers.filter((i) => i.id !== this.client.user.id && !i.bot).length) }; - if (votes.ids.includes(this.author)) return "You've already voted to skip!"; - const newObject = { - count: votes.count + 1, - ids: [...votes.ids, this.author].filter(item => !!item), - max: votes.max - }; - if (votes.count + 1 === votes.max) { - await player.player.stopTrack(this.guild.id); - skipVotes.set(this.guild.id, { count: 0, ids: [], max: Math.min(3, player.voiceChannel.voiceMembers.filter((i) => i.id !== this.client.user.id && !i.bot).length) }); - this.success = true; - if (this.type === "application") return "🔊 The current song has been skipped."; - } else { - skipVotes.set(this.guild.id, newObject); - this.success = true; - return `🔊 Voted to skip song (${votes.count + 1}/${votes.max} people have voted).`; - } - } else { - await player.player.stopTrack(); - this.success = true; - if (this.type === "application") return "🔊 The current song has been skipped."; - } - } - - static description = "Skips the current song"; - static aliases = ["forceskip", "s"]; -} - -export default SkipCommand; diff --git a/commands/music/stop.js b/commands/music/stop.js deleted file mode 100644 index 712534f..0000000 --- a/commands/music/stop.js +++ /dev/null @@ -1,28 +0,0 @@ -import { manager, players, queues } from "../../utils/soundplayer.js"; -import MusicCommand from "../../classes/musicCommand.js"; - -class StopCommand extends MusicCommand { - async run() { - this.success = false; - if (!this.guild) return "This command only works in servers!"; - if (!this.member.voiceState) return "You need to be in a voice channel first!"; - if (!this.guild.voiceStates.has(this.client.user.id)) return "I'm not in a voice channel!"; - if (!this.connection) { - await manager.getNode().leaveChannel(this.guild.id); - this.success = true; - return "🔊 The current voice channel session has ended."; - } - if (this.connection.host !== this.author && !this.member.permissions.has("MANAGE_CHANNELS")) return "Only the current voice session host can stop the music!"; - const connection = this.connection.player; - connection.node.leaveChannel(this.guild.id); - players.delete(this.guild.id); - queues.delete(this.guild.id); - this.success = true; - return `🔊 The voice channel session in \`${this.connection.voiceChannel.name}\` has ended.`; - } - - static description = "Stops the music"; - static aliases = ["disconnect"]; -} - -export default StopCommand; diff --git a/commands/music/toggle.js b/commands/music/toggle.js deleted file mode 100644 index e642547..0000000 --- a/commands/music/toggle.js +++ /dev/null @@ -1,21 +0,0 @@ -import MusicCommand from "../../classes/musicCommand.js"; - -class ToggleCommand extends MusicCommand { - async run() { - this.success = false; - if (!this.guild) return "This command only works in servers!"; - if (!this.member.voiceState) return "You need to be in a voice channel first!"; - if (!this.guild.voiceStates.has(this.client.user.id)) return "I'm not in a voice channel!"; - if (!this.connection) return "I haven't completely connected yet!"; - if (this.connection.host !== this.author && !this.member.permissions.has("MANAGE_CHANNELS")) return "Only the current voice session host can pause/resume the music!"; - const player = this.connection.player; - player.setPaused(!player.paused ? true : false); - this.success = true; - return `🔊 The player has been ${player.paused ? "paused" : "resumed"}.`; - } - - static description = "Pauses/resumes the current song"; - static aliases = ["pause", "resume"]; -} - -export default ToggleCommand;