Fix avatar and banner

This commit is contained in:
Essem 2022-06-07 18:26:50 -05:00
parent 6b34cb9d9e
commit b5ed2cc62a
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
2 changed files with 53 additions and 32 deletions

View file

@ -1,34 +1,45 @@
import Command from "../../classes/command.js"; import Command from "../../classes/command.js";
const mentionRegex = /^<?[@#]?[&!]?(\d+)>?$/;
class AvatarCommand extends Command { class AvatarCommand extends Command {
async run() { async run() {
if (this.message.mentions[0]) { const member = this.specialArgs.member ?? this.args[0];
return this.message.mentions[0].dynamicAvatarURL(null, 1024); const self = await this.client.getRESTUser(this.author.id);
} else if (await this.ipc.fetchUser(this.args[0])) { if (this.type === "classic" && this.message.mentions[0]) {
const user = await this.ipc.fetchUser(this.args[0]); return this.message.mentions[0].dynamicAvatarURL(null, 512);
return user.avatar ? this.client._formatImage(`/avatars/${user.id}/${user.avatar}`, null, 1024) : `https://cdn.discordapp.com/embed/avatars/${user.discriminator % 5}.png`; // hacky "solution" } else if (await this.ipc.fetchUser(member)) {
} else if (this.args[0] && this.args[0].match(/^<?[@#]?[&!]?\d+>?$/) && this.args[0] >= 21154535154122752n) { const user = await this.ipc.fetchUser(member);
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.test(member)) {
const id = member.match(mentionRegex)[1];
if (id < 21154535154122752n) return "That's not a valid mention!";
try { try {
const user = await this.client.getRESTUser(this.args[0]); const user = await this.client.getRESTUser(id);
return user.avatar ? this.client._formatImage(`/avatars/${user.id}/${user.avatar}`, null, 1024) : `https://cdn.discordapp.com/embed/avatars/${user.discriminator % 5}.png`; // repeat of hacky "solution" from above 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
} catch { } catch {
return this.author.dynamicAvatarURL(null, 1024); return self.dynamicAvatarURL(null, 512);
} }
} else if (this.args.join(" ") !== "" && this.channel.guild) { } else if (this.args.join(" ") !== "" && this.channel.guild) {
const userRegex = new RegExp(this.args.join("|"), "i"); console.log(member);
const member = this.channel.guild.members.find(element => { const searched = await this.channel.guild.searchMembers(this.args.join(" "));
return userRegex.test(element.nick) ? userRegex.test(element.nick) : userRegex.test(element.username); if (searched.length === 0) return self.dynamicAvatarURL(null, 512);
}); console.log(searched);
return member ? member.user.dynamicAvatarURL(null, 1024) : this.author.dynamicAvatarURL(null, 1024); const user = await this.client.getRESTUser(searched[0].user.id);
return user ? user.dynamicAvatarURL(null, 512) : self.dynamicAvatarURL(null, 512);
} else { } else {
return this.author.dynamicAvatarURL(null, 1024); return self.dynamicAvatarURL(null, 512);
} }
} }
static description = "Gets a user's avatar"; static description = "Gets a user's avatar";
static aliases = ["pfp", "ava"]; static aliases = ["pfp", "ava"];
static arguments = ["{mention/id}"]; static arguments = ["{mention/id}"];
static slashAllowed = false; static flags = [{
name: "member",
type: 6,
description: "The member to get the banner from",
required: false
}];
} }
export default AvatarCommand; export default AvatarCommand;

View file

@ -1,34 +1,44 @@
import Command from "../../classes/command.js"; import Command from "../../classes/command.js";
const mentionRegex = /^<?[@#]?[&!]?(\d+)>?$/;
class BannerCommand extends Command { class BannerCommand extends Command {
async run() { async run() {
if (this.message.mentions[0]) { const member = this.specialArgs.member ?? this.args[0];
return this.message.mentions[0].banner ? this.message.mentions[0].dynamicBannerURL(null, 1024) : "This user doesn't have a banner!"; const self = await this.client.getRESTUser(this.author.id);
} else if (await this.ipc.fetchUser(this.args[0])) { if (this.type === "classic" && this.message.mentions[0]) {
const user = await this.ipc.fetchUser(this.args[0]); return this.message.mentions[0].dynamicBannerURL(null, 512) ?? "This user doesn't have a banner!";
return user.banner ? this.client._formatImage(`/banners/${user.id}/${user.banner}`, null, 1024) : "This user doesn't have a banner!"; } else if (await this.ipc.fetchUser(member)) {
} else if (this.args[0] && this.args[0].match(/^<?[@#]?[&!]?\d+>?$/) && this.args[0] >= 21154535154122752n) { const user = await this.client.getRESTUser(member);
return user.dynamicBannerURL(null, 512) ?? "This user doesn't have a banner!";
} else if (mentionRegex.test(member)) {
const id = member.match(mentionRegex)[1];
if (id < 21154535154122752n) return "That's not a valid mention!";
try { try {
const user = await this.client.getRESTUser(this.args[0]); const user = await this.client.getRESTUser(id);
return user.banner ? this.client._formatImage(`/banners/${user.id}/${user.banner}`, null, 1024) : "This user doesn't have a banner!"; return user.dynamicBannerURL(null, 512) ?? "This user doesn't have a banner!";
} catch { } catch {
return this.author.banner ? this.author.dynamicBannerURL(null, 1024) : "You don't have a banner!"; return self.dynamicBannerURL(null, 512) ?? "You don't have a banner!";
} }
} else if (this.args.join(" ") !== "" && this.channel.guild) { } else if (this.args.join(" ") !== "" && this.channel.guild) {
const userRegex = new RegExp(this.args.join("|"), "i"); const searched = await this.channel.guild.searchMembers(this.args.join(" "));
const member = this.channel.guild.members.find(element => { if (searched.length === 0) return self.dynamicBannerURL(null, 512) ?? "This user doesn't have a banner!";
return userRegex.test(element.nick) ?? userRegex.test(element.username); 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!");
return member && member.user.banner ? member.user.dynamicBannerURL(null, 1024) : (this.author.banner ? this.author.dynamicBannerURL(null, 1024) : "This user doesn't have a banner!");
} else { } else {
return this.author.banner ? this.author.dynamicBannerURL(null, 1024) : "You don't have a banner!";
return self.dynamicBannerURL(null, 512) ?? "You don't have a banner!";
} }
} }
static description = "Gets a user's banner"; static description = "Gets a user's banner";
static aliases = ["userbanner"]; static aliases = ["userbanner"];
static arguments = ["{mention/id}"]; static arguments = ["{mention/id}"];
static slashAllowed = false; static flags = [{
name: "member",
type: 6,
description: "The member to get the banner from",
required: false
}];
} }
export default BannerCommand; export default BannerCommand;