utility.lookupinvite: group dm and friend invite support

This commit is contained in:
Cynthia Foxwell 2023-05-29 19:51:50 -06:00
parent f4f2015fb3
commit 8a1f5b9fdd
1 changed files with 182 additions and 138 deletions

View File

@ -180,7 +180,8 @@ avatar.callback = async function(msg, line, [user], { server, guild }) {
return "`--server/--guild` can only be used within guilds.";
} else {
const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID);
const url = `${ICON_BASE}${guild.id}/${guild.icon}.${guild.icon.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024"
const url = `${ICON_BASE}${guild.id}/${guild.icon}.${
guild.icon.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024"
}`;
return {
embeds: [
@ -321,7 +322,8 @@ banner.callback = async function(msg, line, [user], { server, guild }) {
if (!guild.banner) return "This guild does not have a banner.";
const url = `${BANNER_BASE}${guild.id}/${guild.banner}.${guild.banner.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024"
const url = `${BANNER_BASE}${guild.id}/${guild.banner}.${
guild.banner.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024"
}`;
return {
embeds: [
@ -356,7 +358,8 @@ banner.callback = async function(msg, line, [user], { server, guild }) {
if (!userObj.banner) return "This user does not have a banner.";
const url = `${BANNER_BASE}${userObj.id}/${userObj.banner}.${userObj.banner.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024"
const url = `${BANNER_BASE}${userObj.id}/${userObj.banner}.${
userObj.banner.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024"
}`;
return {
embeds: [
@ -415,7 +418,30 @@ lookupinvite.callback = async function(msg, line) {
const embed = {
title: `Invite Info: \`${invite.code}\``,
description: invite.description,
fields: [
fields: [],
thumbnail: {
url:
invite.guild.icon &&
`${ICON_BASE}${invite.guild.id}/${invite.guild.icon}.${
invite.guild.icon.startsWith("a_")
? "gif?size=1024&_=.gif"
: "png?size=1024"
}`,
},
};
const expires = {
name: "Expires",
value:
invite.expires_at == null
? "Never"
: `<t:${Math.floor(new Date(invite.expires_at).getTime() / 1000)}>`,
inline: true,
};
if (invite.type == 0) {
embed.fields.push(
...[
{
name: "Guild",
value: `**${invite.guild.name}** (${invite.guild.id})`,
@ -436,23 +462,16 @@ lookupinvite.callback = async function(msg, line) {
value: invite.guild.premium_subscription_count ?? 0,
inline: true,
},
{
name: "Expires",
value:
invite.expires_at == null
? "Never"
: `<t:${Math.floor(
new Date(invite.expires_at).getTime() / 1000
)}>`,
inline: true,
},
expires,
invite.guild.welcome_screen && {
name: "Welcome Screen",
value: `"${invite.guild.welcome_screen.description
value: `"${
invite.guild.welcome_screen.description
}"\n${invite.guild.welcome_screen.welcome_channels
.map(
(c) =>
`${c.emoji_id
`${
c.emoji_id
? `[:${c.emoji_name}:](${EMOTE_BASE}${c.emoji_id}.webp)`
: c.emoji_name
} ${c.description} \`(${c.channel_id})\``
@ -475,42 +494,63 @@ lookupinvite.callback = async function(msg, line) {
: "None",
inline: false,
},
].filter((x) => !!x),
thumbnail: {
url:
invite.guild.icon &&
`${ICON_BASE}${invite.guild.id}/${invite.guild.icon}.${invite.guild.icon.startsWith("a_")
? "gif?size=1024&_=.gif"
: "png?size=1024"
}`,
].filter((x) => !!x)
);
} else if (invite.type == 1) {
embed.title += " (Group DM)";
embed.fields.push(
{
name: "Channel",
value: `**${invite.channel.name}** (${invite.channel.id})`,
inline: true,
},
};
expires
);
} else if (invite.type == 2) {
embed.title += " (Friend)";
embed.fields.push(expires);
}
if (invite.inviter) {
embed.fields.push({
name: "Inviter",
value: `**${invite.inviter.username}#${invite.inviter.discriminator}** (${invite.inviter.id})`,
value: `**${
invite.inviter.discriminator && invite.inviter.discriminator != "0"
? `${invite.inviter.username}#${invite.inviter.discriminator}`
: `@${invite.inviter.username}`
}** (${invite.inviter.id})`,
inline: true,
});
}
if (invite.guild.icon || invite.guild.splash || invite.guild.banner) {
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_")
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
? `${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_")
}${
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"
})`
@ -520,7 +560,7 @@ lookupinvite.callback = async function(msg, line) {
});
}
if (invite.guild.splash) {
if (invite.guild?.splash) {
embed.image = {
url: `${SPLASH_BASE}${invite.guild.id}/${invite.guild.splash}.png?size=256`,
};
@ -605,13 +645,15 @@ flagdump.callback = async function(msg, line, [numOrMention], { id, list }) {
if (!user) {
return "User not cached.";
} else {
return `\`${user.username}#${user.discriminator
return `\`${user.username}#${
user.discriminator
}\`'s public flags:\n\`\`\`${flagFromInt(user.publicFlags)}\`\`\``;
}
} else if (!isNaN(num)) {
return `\`\`\`\n${flagFromInt(num)}\`\`\``;
} else {
return `\`${msg.author.username}#${msg.author.discriminator
return `\`${msg.author.username}#${
msg.author.discriminator
}\`'s public flags:\n\`\`\`${flagFromInt(msg.author.publicFlags)}\`\`\``;
}
};
@ -788,7 +830,8 @@ presence.callback = async function(msg, line) {
if (activity.emoji) {
if (activity.emoji.id) {
const url = `${EMOTE_BASE}${activity.emoji.id}.${activity.emoji.animated ? "gif" : "png"
const url = `${EMOTE_BASE}${activity.emoji.id}.${
activity.emoji.animated ? "gif" : "png"
}`;
embed.author = {
url,
@ -985,7 +1028,8 @@ presence.callback = async function(msg, line) {
}
return {
content: `Presence for **${target.username}#${target.discriminator
content: `Presence for **${target.username}#${
target.discriminator
}**: ${icons.trim()}`,
embeds,
files,