Port avatar and banner, permission fixes
This commit is contained in:
parent
d68ff19e4d
commit
d7597ee2b0
10 changed files with 50 additions and 43 deletions
|
@ -4,35 +4,38 @@ const mentionRegex = /^<?[@#]?[&!]?(\d+)>?$/;
|
|||
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
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -1,39 +1,43 @@
|
|||
import Command from "../../classes/command.js";
|
||||
import { Routes } from "oceanic.js";
|
||||
const mentionRegex = /^<?[@#]?[&!]?(\d+)>?$/;
|
||||
|
||||
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!";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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!";
|
||||
|
||||
|
|
|
@ -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!";
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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!`;
|
||||
|
|
Loading…
Reference in a new issue