Port avatar and banner, permission fixes

This commit is contained in:
Essem 2022-09-24 12:25:19 -05:00
parent d68ff19e4d
commit d7597ee2b0
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
10 changed files with 50 additions and 43 deletions

View file

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

View file

@ -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!";
}
}

View file

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

View file

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

View file

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