From d7597ee2b06778d066da95e871393975693ebf3a Mon Sep 17 00:00:00 2001 From: Essem Date: Sat, 24 Sep 2022 12:25:19 -0500 Subject: [PATCH] Port avatar and banner, permission fixes --- commands/general/avatar.js | 37 +++++++++++++++++++----------------- commands/general/banner.js | 38 ++++++++++++++++++++----------------- commands/general/channel.js | 2 +- commands/general/command.js | 2 +- commands/general/stats.js | 2 +- commands/music/loop.js | 2 +- commands/music/skip.js | 2 +- commands/music/stop.js | 2 +- commands/music/toggle.js | 2 +- commands/tags/tags.js | 4 ++-- 10 files changed, 50 insertions(+), 43 deletions(-) diff --git a/commands/general/avatar.js b/commands/general/avatar.js index 9bd1c78..ee30e9c 100644 --- a/commands/general/avatar.js +++ b/commands/general/avatar.js @@ -4,35 +4,38 @@ const mentionRegex = /^?$/; class AvatarCommand extends Command { async run() { const member = this.options.member ?? this.args[0]; - const self = await this.client.getRESTUser(this.author.id); - if (this.type === "classic" && this.message.mentions[0]) { - return this.message.mentions[0].dynamicAvatarURL(null, 512); - } else if (member) { - const user = await this.client.getRESTUser(member); + const self = this.client.users.get(this.author.id) ?? await this.client.rest.users.get(this.author.id); + if (this.type === "classic" && this.message.mentions.users[0]) { + return this.message.mentions.users[0].avatarURL(null, 512); + } else if (member && member > 21154535154122752n) { + const user = this.client.users.get(member) ?? await this.client.rest.users.get(member); if (user) { - return user?.avatar ? this.client._formatImage(`/avatars/${user.id}/${user.avatar}`, null, 512) : `https://cdn.discordapp.com/embed/avatars/${user.discriminator % 5}.png`; // hacky "solution" - } else if (mentionRegex.text(member)) { + return user.avatarURL(null, 512); + } else if (mentionRegex.test(member)) { const id = member.match(mentionRegex)[1]; if (id < 21154535154122752n) { this.success = false; return "That's not a valid mention!"; } try { - const user = await this.client.getRESTUser(id); - return user.avatar ? this.client._formatImage(`/avatars/${user.id}/${user.avatar}`, null, 512) : `https://cdn.discordapp.com/embed/avatars/${user.discriminator % 5}.png`; // repeat of hacky "solution" from above + const user = this.client.users.get(id) ?? await this.client.rest.users.get(id); + return user.avatarURL(null, 512); } catch { - return self.dynamicAvatarURL(null, 512); + return self.avatarURL(null, 512); } } else { - return self.dynamicAvatarURL(null, 512); + return self.avatarURL(null, 512); } } else if (this.args.join(" ") !== "" && this.guild) { - const searched = await this.guild.searchMembers(this.args.join(" ")); - if (searched.length === 0) return self.dynamicAvatarURL(null, 512); - const user = await this.client.getRESTUser(searched[0].user.id); - return user ? user.dynamicAvatarURL(null, 512) : self.dynamicAvatarURL(null, 512); + const searched = await this.guild.searchMembers({ + query: this.args.join(" "), + limit: 1 + }); + if (searched.length === 0) return self.avatarURL(null, 512); + const user = this.client.users.get(searched[0].user.id) ?? await this.client.rest.users.get(searched[0].user.id); + return user ? user.avatarURL(null, 512) : self.avatarURL(null, 512); } else { - return self.dynamicAvatarURL(null, 512); + return self.avatarURL(null, 512); } } @@ -42,7 +45,7 @@ class AvatarCommand extends Command { static flags = [{ name: "member", type: 6, - description: "The member to get the banner from", + description: "The member to get the avatar from", required: false }]; } diff --git a/commands/general/banner.js b/commands/general/banner.js index 1280689..f9717a2 100644 --- a/commands/general/banner.js +++ b/commands/general/banner.js @@ -1,39 +1,43 @@ import Command from "../../classes/command.js"; +import { Routes } from "oceanic.js"; const mentionRegex = /^?$/; class BannerCommand extends Command { + // this command sucks async run() { const member = this.options.member ?? this.args[0]; - const self = await this.client.getRESTUser(this.author.id); - if (this.type === "classic" && this.message.mentions[0]) { - return this.message.mentions[0].dynamicBannerURL(null, 512) ?? "This user doesn't have a banner!"; - } else if (member) { - const user = await this.client.getRESTUser(member); - if (user) { - return user.dynamicBannerURL(null, 512) ?? "This user doesn't have a banner!"; - } else if (mentionRegex.text(member)) { + const self = await this.client.rest.users.get(this.author.id); // banners are only available over REST + if (this.type === "classic" && this.message.mentions.users[0] && this.message.mentions.users[0].banner) { + return this.client.util.formatImage(Routes.BANNER(this.message.mentions.users[0].id, this.message.mentions.users[0].banner), null, 512); + } else if (member && member > 21154535154122752n) { + const user = await this.client.rest.users.get(member); + if (user && user.banner) { + return this.client.util.formatImage(Routes.BANNER(user.id, user.banner), null, 512); + } else if (mentionRegex.test(member)) { const id = member.match(mentionRegex)[1]; if (id < 21154535154122752n) { this.success = false; return "That's not a valid mention!"; } try { - const user = await this.client.getRESTUser(id); - return user.dynamicBannerURL(null, 512) ?? "This user doesn't have a banner!"; + const user = await this.client.rest.users.get(id); + return user.banner ? this.client.util.formatImage(Routes.BANNER(user.id, user.banner), null, 512) : "This user doesn't have a banner!"; } catch { - return self.dynamicBannerURL(null, 512) ?? "You don't have a banner!"; + return self.banner ? this.client.util.formatImage(Routes.BANNER(self.id, self.banner), null, 512) : "You don't have a banner!"; } } else { return "This user doesn't have a banner!"; } } else if (this.args.join(" ") !== "" && this.guild) { - const searched = await this.guild.searchMembers(this.args.join(" ")); - if (searched.length === 0) return self.dynamicBannerURL(null, 512) ?? "This user doesn't have a banner!"; - const user = await this.client.getRESTUser(searched[0].user.id); - return user.dynamicBannerURL(null, 512) ?? (self.dynamicBannerURL(null, 512) ?? "This user doesn't have a banner!"); + const searched = await this.guild.searchMembers({ + query: this.args.join(" "), + limit: 1 + }); + if (searched.length === 0) return self.banner ? this.client.util.formatImage(Routes.BANNER(self.id, self.banner), null, 512) : "This user doesn't have a banner!"; + const user = await this.client.rest.users.get(searched[0].user.id); + return user.banner ? this.client.util.formatImage(Routes.BANNER(user.id, user.banner), null, 512) : (self.banner ? this.client.util.formatImage(Routes.BANNER(self.id, self.banner), null, 512) : "This user doesn't have a banner!"); } else { - - return self.dynamicBannerURL(null, 512) ?? "You don't have a banner!"; + return self.banner ? this.client.util.formatImage(Routes.BANNER(self.id, self.banner), null, 512) : "You don't have a banner!"; } } diff --git a/commands/general/channel.js b/commands/general/channel.js index a8d0187..f0c5191 100644 --- a/commands/general/channel.js +++ b/commands/general/channel.js @@ -6,7 +6,7 @@ class ChannelCommand extends Command { this.success = false; if (!this.guild) return "This command only works in servers!"; const owners = process.env.OWNER.split(","); - if (!this.member.permissions.has("administrator") && !owners.includes(this.member.id)) return "You need to be an administrator to enable/disable me!"; + if (!this.member.permissions.has("ADMINISTRATOR") && !owners.includes(this.member.id)) return "You need to be an administrator to enable/disable me!"; if (this.args.length === 0) return "You need to provide whether I should be enabled or disabled in this channel!"; if (this.args[0] !== "disable" && this.args[0] !== "enable") return "That's not a valid option!"; diff --git a/commands/general/command.js b/commands/general/command.js index 139f267..16266da 100644 --- a/commands/general/command.js +++ b/commands/general/command.js @@ -7,7 +7,7 @@ class CommandCommand extends Command { this.success = false; if (!this.guild) return "This command only works in servers!"; const owners = process.env.OWNER.split(","); - if (!this.member.permissions.has("administrator") && !owners.includes(this.member.id)) return "You need to be an administrator to enable/disable me!"; + if (!this.member.permissions.has("ADMINISTRATOR") && !owners.includes(this.member.id)) return "You need to be an administrator to enable/disable me!"; if (this.args.length === 0) return "You need to provide whether you want to enable/disable a command!"; if (this.args[0] !== "disable" && this.args[0] !== "enable") return "That's not a valid option!"; if (!this.args[1]) return "You need to provide what command to enable/disable!"; diff --git a/commands/general/stats.js b/commands/general/stats.js index 27df115..cd11e8f 100644 --- a/commands/general/stats.js +++ b/commands/general/stats.js @@ -11,7 +11,7 @@ class StatsCommand extends Command { const uptime = process.uptime() * 1000; const connUptime = this.client.uptime; let owner = this.client.users.get(process.env.OWNER.split(",")[0]); - if (!owner) owner = await this.client.getRESTUser(process.env.OWNER.split(",")[0]); + if (!owner) owner = await this.client.rest.users.get(process.env.OWNER.split(",")[0]); const servers = await getServers(this.client); const processMem = `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`; return { diff --git a/commands/music/loop.js b/commands/music/loop.js index 071eba4..6e39f2e 100644 --- a/commands/music/loop.js +++ b/commands/music/loop.js @@ -7,7 +7,7 @@ class LoopCommand extends MusicCommand { if (!this.guild) return "This command only works in servers!"; if (!this.member.voiceState.channelID) return "You need to be in a voice channel first!"; if (!this.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 loop the music!"; + if (this.connection.host !== this.author.id && !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); diff --git a/commands/music/skip.js b/commands/music/skip.js index 6e77c28..0c23d1f 100644 --- a/commands/music/skip.js +++ b/commands/music/skip.js @@ -8,7 +8,7 @@ class SkipCommand extends MusicCommand { if (!this.member.voiceState.channelID) return "You need to be in a voice channel first!"; if (!this.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!"; const player = this.connection; - if (player.host !== this.author.id && !this.member.permissions.has("manageChannels")) { + if (player.host !== this.author.id && !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.id)) return "You've already voted to skip!"; const newObject = { diff --git a/commands/music/stop.js b/commands/music/stop.js index 4aa6a5b..4b51538 100644 --- a/commands/music/stop.js +++ b/commands/music/stop.js @@ -12,7 +12,7 @@ class StopCommand extends MusicCommand { this.success = true; 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!"; + if (this.connection.host !== this.author.id && !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); diff --git a/commands/music/toggle.js b/commands/music/toggle.js index c15a993..6551e5e 100644 --- a/commands/music/toggle.js +++ b/commands/music/toggle.js @@ -6,7 +6,7 @@ class ToggleCommand extends MusicCommand { if (!this.guild) return "This command only works in servers!"; if (!this.member.voiceState.channelID) return "You need to be in a voice channel first!"; if (!this.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!"; + if (this.connection.host !== this.author.id && !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; diff --git a/commands/tags/tags.js b/commands/tags/tags.js index 102b59a..02d224f 100644 --- a/commands/tags/tags.js +++ b/commands/tags/tags.js @@ -27,7 +27,7 @@ class TagsCommand extends Command { const getResult = await database.getTag(this.guild.id, tagName); if (!getResult) return "This tag doesn't exist!"; const owners = process.env.OWNER.split(","); - if (getResult.author !== this.author.id && !this.member.permissions.has("manageMessages") && !owners.includes(this.author.id)) return "You don't own this tag!"; + if (getResult.author !== this.author.id && !this.member.permissions.has("MANAGE_MESSAGES") && !owners.includes(this.author.id)) return "You don't own this tag!"; await database.removeTag(tagName, this.guild); this.success = true; return `The tag \`${tagName}\` has been deleted!`; @@ -36,7 +36,7 @@ class TagsCommand extends Command { const getResult = await database.getTag(this.guild.id, tagName); if (!getResult) return "This tag doesn't exist!"; const owners = process.env.OWNER.split(","); - if (getResult.author !== this.author.id && !this.member.permissions.has("manageMessages") && !owners.includes(this.author.id)) return "You don't own this tag!"; + if (getResult.author !== this.author.id && !this.member.permissions.has("MANAGE_MESSAGES") && !owners.includes(this.author.id)) return "You don't own this tag!"; await database.editTag(tagName, { content: this.type === "classic" ? this.args.slice(2).join(" ") : this.optionsArray[0].options[1].value, author: this.member.id }, this.guild); this.success = true; return `The tag \`${tagName}\` has been edited!`;