utility.lookupinvite: code cleanup
This commit is contained in:
parent
1eab6674c0
commit
778f5aeab1
1 changed files with 93 additions and 74 deletions
|
@ -442,6 +442,15 @@ lookupinvite.callback = async function (msg, line) {
|
|||
: `<t:${Math.floor(new Date(invite.expires_at).getTime() / 1000)}>`,
|
||||
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) {
|
||||
embed.fields.push(
|
||||
|
@ -467,6 +476,7 @@ lookupinvite.callback = async function (msg, line) {
|
|||
inline: true,
|
||||
},
|
||||
expires,
|
||||
inviter,
|
||||
invite.guild.welcome_screen && {
|
||||
name: "Welcome Screen",
|
||||
value: `"${
|
||||
|
@ -509,65 +519,6 @@ lookupinvite.callback = async function (msg, line) {
|
|||
: "png?size=1024"
|
||||
}`,
|
||||
};
|
||||
} else if (invite.type == 1) {
|
||||
embed.title += " (Group DM)";
|
||||
embed.fields.push(
|
||||
{
|
||||
name: "Channel",
|
||||
value: `**${
|
||||
invite.channel.name ??
|
||||
invite.channel.recipients
|
||||
.map((member) => member.username)
|
||||
.join(", ")
|
||||
}** (${invite.channel.id})`,
|
||||
inline: false,
|
||||
},
|
||||
{
|
||||
name: "Member Count",
|
||||
value: `${STATUS_ICONS.offline}${invite.approximate_member_count} members`,
|
||||
inline: true,
|
||||
},
|
||||
expires
|
||||
);
|
||||
embed.thumbnail = {
|
||||
url: invite.channel.icon
|
||||
? `${CHANNEL_ICON_BASE}${invite.channel.id}/${invite.channel.icon}.${
|
||||
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"
|
||||
: "png?size=1024"
|
||||
}`,
|
||||
};
|
||||
}
|
||||
|
||||
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 &&
|
||||
|
@ -611,6 +562,74 @@ lookupinvite.callback = async function (msg, line) {
|
|||
url: `${SPLASH_BASE}${invite.guild.id}/${invite.guild.splash}.png?size=256`,
|
||||
};
|
||||
}
|
||||
} else if (invite.type == 1) {
|
||||
embed.title += " (Group DM)";
|
||||
embed.fields.push(
|
||||
{
|
||||
name: "Channel",
|
||||
value: `**${
|
||||
invite.channel.name ??
|
||||
invite.channel.recipients
|
||||
.map((member) => member.username)
|
||||
.join(", ")
|
||||
}** (${invite.channel.id})`,
|
||||
inline: false,
|
||||
},
|
||||
{
|
||||
name: "Member Count",
|
||||
value: `${STATUS_ICONS.offline}${invite.approximate_member_count} members`,
|
||||
inline: true,
|
||||
},
|
||||
expires,
|
||||
inviter
|
||||
);
|
||||
|
||||
const groupIcon = invite.channel.icon
|
||||
? `${CHANNEL_ICON_BASE}${invite.channel.id}/${invite.channel.icon}.${
|
||||
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
|
||||
];
|
||||
|
||||
embed.thumbnail = {
|
||||
url: groupIcon,
|
||||
};
|
||||
embed.fields.push({
|
||||
name: "\u200b",
|
||||
value: `[Icon](${groupIcon})`,
|
||||
inline: false,
|
||||
});
|
||||
} else if (invite.type == 2) {
|
||||
embed.title += " (Friend)";
|
||||
embed.fields.push(expires, inviter);
|
||||
|
||||
const avatarURL =
|
||||
invite.inviter?.avatar &&
|
||||
`${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};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue