utility.lookupinvite: code cleanup

This commit is contained in:
Cynthia Foxwell 2023-05-29 20:27:43 -06:00
parent 1eab6674c0
commit 778f5aeab1

View file

@ -442,6 +442,15 @@ lookupinvite.callback = async function (msg, line) {
: `<t:${Math.floor(new Date(invite.expires_at).getTime() / 1000)}>`, : `<t:${Math.floor(new Date(invite.expires_at).getTime() / 1000)}>`,
inline: true, inline: true,
}; };
const inviter = {
name: "Inviter",
value: `**${
invite.inviter.discriminator && invite.inviter.discriminator != "0"
? `${invite.inviter.username}#${invite.inviter.discriminator}`
: `@${invite.inviter.username}`
}** (${invite.inviter.id})`,
inline: false,
};
if (invite.type == 0) { if (invite.type == 0) {
embed.fields.push( embed.fields.push(
@ -467,6 +476,7 @@ lookupinvite.callback = async function (msg, line) {
inline: true, inline: true,
}, },
expires, expires,
inviter,
invite.guild.welcome_screen && { invite.guild.welcome_screen && {
name: "Welcome Screen", name: "Welcome Screen",
value: `"${ value: `"${
@ -509,6 +519,49 @@ lookupinvite.callback = async function (msg, line) {
: "png?size=1024" : "png?size=1024"
}`, }`,
}; };
if (
invite.guild &&
(invite.guild.icon || invite.guild.splash || invite.guild.banner)
) {
embed.fields.push({
name: "\u200b",
value: `${
invite.guild.icon
? `[Icon](${ICON_BASE}${invite.guild.id}/${invite.guild.icon}.${
invite.guild.icon.startsWith("a_")
? "gif?size=1024"
: "png?size=1024"
})`
: ""
}${
invite.guild.splash
? `${invite.guild.icon ? " | " : ""}[Splash](${SPLASH_BASE}${
invite.guild.id
}/${invite.guild.splash}.png?size=2048)`
: ""
}${
invite.guild.banner
? `${
invite.guild.icon || invite.guild.splash ? " | " : ""
}[Banner](${BANNER_BASE}${invite.guild.id}/${
invite.guild.banner
}.${
invite.guild.banner.startsWith("a_")
? "gif?size=1024"
: "png?size=1024"
})`
: ""
}`,
inline: false,
});
}
if (invite.guild?.splash) {
embed.image = {
url: `${SPLASH_BASE}${invite.guild.id}/${invite.guild.splash}.png?size=256`,
};
}
} else if (invite.type == 1) { } else if (invite.type == 1) {
embed.title += " (Group DM)"; embed.title += " (Group DM)";
embed.fields.push( embed.fields.push(
@ -527,89 +580,55 @@ lookupinvite.callback = async function (msg, line) {
value: `${STATUS_ICONS.offline}${invite.approximate_member_count} members`, value: `${STATUS_ICONS.offline}${invite.approximate_member_count} members`,
inline: true, inline: true,
}, },
expires expires,
inviter
); );
embed.thumbnail = {
url: invite.channel.icon const groupIcon = invite.channel.icon
? `${CHANNEL_ICON_BASE}${invite.channel.id}/${invite.channel.icon}.${ ? `${CHANNEL_ICON_BASE}${invite.channel.id}/${invite.channel.icon}.${
invite.channel.icon.startsWith("a_") invite.channel.icon.startsWith("a_")
? "gif?size=1024&_=.gif"
: "png?size=1024"
}`
: "https://discord.com" +
DEFAULT_GROUP_DM_AVATARS[
(Math.floor(Number(invite.channel.id) / Math.pow(2, 22)) +
1420070400000) %
DEFAULT_GROUP_DM_AVATARS.length
],
};
} else if (invite.type == 2) {
embed.title += " (Friend)";
embed.fields.push(expires);
embed.thumbnail = {
url:
invite.inviter?.avatar &&
`${AVATAR_BASE}${invite.inviter.id}/${invite.inviter.avatar}.${
invite.inviter.avatar.startsWith("a_")
? "gif?size=1024&_=.gif" ? "gif?size=1024&_=.gif"
: "png?size=1024" : "png?size=1024"
}`, }`
: "https://discord.com" +
DEFAULT_GROUP_DM_AVATARS[
(Math.floor(Number(invite.channel.id) / Math.pow(2, 22)) +
1420070400000) %
DEFAULT_GROUP_DM_AVATARS.length
];
embed.thumbnail = {
url: groupIcon,
}; };
}
if (invite.inviter) {
embed.fields.push({
name: "Inviter",
value: `**${
invite.inviter.discriminator && invite.inviter.discriminator != "0"
? `${invite.inviter.username}#${invite.inviter.discriminator}`
: `@${invite.inviter.username}`
}** (${invite.inviter.id})`,
inline: false,
});
}
if (
invite.guild &&
(invite.guild.icon || invite.guild.splash || invite.guild.banner)
) {
embed.fields.push({ embed.fields.push({
name: "\u200b", name: "\u200b",
value: `${ value: `[Icon](${groupIcon})`,
invite.guild.icon
? `[Icon](${ICON_BASE}${invite.guild.id}/${invite.guild.icon}.${
invite.guild.icon.startsWith("a_")
? "gif?size=1024"
: "png?size=1024"
})`
: ""
}${
invite.guild.splash
? `${invite.guild.icon ? " | " : ""}[Splash](${SPLASH_BASE}${
invite.guild.id
}/${invite.guild.splash}.png?size=2048)`
: ""
}${
invite.guild.banner
? `${
invite.guild.icon || invite.guild.splash ? " | " : ""
}[Banner](${BANNER_BASE}${invite.guild.id}/${
invite.guild.banner
}.${
invite.guild.banner.startsWith("a_")
? "gif?size=1024"
: "png?size=1024"
})`
: ""
}`,
inline: false, inline: false,
}); });
} } else if (invite.type == 2) {
embed.title += " (Friend)";
embed.fields.push(expires, inviter);
if (invite.guild?.splash) { const avatarURL =
embed.image = { invite.inviter?.avatar &&
url: `${SPLASH_BASE}${invite.guild.id}/${invite.guild.splash}.png?size=256`, `${AVATAR_BASE}${invite.inviter.id}/${invite.inviter.avatar}.${
}; invite.inviter.avatar.startsWith("a_")
? "gif?size=1024&_=.gif"
: "png?size=1024"
}`;
if (avatarURL) {
embed.thumbnail = {
url: avatarURL,
};
embed.fields.push({
name: "\u200b",
value: `[Avatar](${avatarURL})`,
inline: false,
});
}
} else {
return `Unhandled invite type: \`${invite.type}\``;
} }
return {embed}; return {embed};