utility.lookupinvite: group dm and friend invite support
This commit is contained in:
parent
f4f2015fb3
commit
8a1f5b9fdd
1 changed files with 182 additions and 138 deletions
|
@ -11,7 +11,7 @@ const {
|
|||
formatTime,
|
||||
safeString,
|
||||
} = require("../lib/utils.js");
|
||||
const { getNamesFromString } = require("../lib/unicode.js");
|
||||
const {getNamesFromString} = require("../lib/unicode.js");
|
||||
|
||||
const GameData = require("../../data/games.json");
|
||||
|
||||
|
@ -174,14 +174,15 @@ const avatar = new Command("avatar");
|
|||
avatar.category = CATEGORY;
|
||||
avatar.helpText = "Get avatar of a user";
|
||||
avatar.usage = "<user>";
|
||||
avatar.callback = async function(msg, line, [user], { server, guild }) {
|
||||
avatar.callback = async function (msg, line, [user], {server, guild}) {
|
||||
if (server || guild) {
|
||||
if (!msg.guildID) {
|
||||
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: [
|
||||
{
|
||||
|
@ -235,24 +236,24 @@ avatar.callback = async function(msg, line, [user], { server, guild }) {
|
|||
const guildUrl =
|
||||
guildAvatar &&
|
||||
"https://cdn.discordapp.com/guilds/" +
|
||||
guild.id +
|
||||
"/users/" +
|
||||
member.id +
|
||||
"/avatars/" +
|
||||
guildAvatar +
|
||||
"." +
|
||||
(guildAvatar.startsWith("a_")
|
||||
? "gif?size=1024&_=.gif"
|
||||
: "png?size=1024");
|
||||
guild.id +
|
||||
"/users/" +
|
||||
member.id +
|
||||
"/avatars/" +
|
||||
guildAvatar +
|
||||
"." +
|
||||
(guildAvatar.startsWith("a_")
|
||||
? "gif?size=1024&_=.gif"
|
||||
: "png?size=1024");
|
||||
|
||||
baseEmbed.description =
|
||||
`[Normal avatar](${normalUrl})` +
|
||||
(guild && guildAvatar ? `\n[Guild avatar](${guildUrl})` : "");
|
||||
baseEmbed.url = normalUrl;
|
||||
|
||||
const guildEmbed = { ...baseEmbed };
|
||||
baseEmbed.image = { url: normalUrl };
|
||||
guildEmbed.image = { url: guildUrl };
|
||||
const guildEmbed = {...baseEmbed};
|
||||
baseEmbed.image = {url: normalUrl};
|
||||
guildEmbed.image = {url: guildUrl};
|
||||
|
||||
return {
|
||||
embeds: [baseEmbed, guildAvatar && guildEmbed].filter((x) => x != null),
|
||||
|
@ -280,24 +281,24 @@ avatar.callback = async function(msg, line, [user], { server, guild }) {
|
|||
const guildUrl =
|
||||
guildAvatar &&
|
||||
"https://cdn.discordapp.com/guilds/" +
|
||||
guild.id +
|
||||
"/users/" +
|
||||
msg.author.id +
|
||||
"/avatars/" +
|
||||
guildAvatar +
|
||||
"." +
|
||||
(guildAvatar.startsWith("a_")
|
||||
? "gif?size=1024&_=.gif"
|
||||
: "png?size=1024");
|
||||
guild.id +
|
||||
"/users/" +
|
||||
msg.author.id +
|
||||
"/avatars/" +
|
||||
guildAvatar +
|
||||
"." +
|
||||
(guildAvatar.startsWith("a_")
|
||||
? "gif?size=1024&_=.gif"
|
||||
: "png?size=1024");
|
||||
|
||||
baseEmbed.description =
|
||||
`[Normal avatar](${normalUrl})` +
|
||||
(guild && guildAvatar ? `\n[Guild avatar](${guildUrl})` : "");
|
||||
baseEmbed.url = normalUrl;
|
||||
|
||||
const guildEmbed = { ...baseEmbed };
|
||||
baseEmbed.image = { url: normalUrl };
|
||||
guildEmbed.image = { url: guildUrl };
|
||||
const guildEmbed = {...baseEmbed};
|
||||
baseEmbed.image = {url: normalUrl};
|
||||
guildEmbed.image = {url: guildUrl};
|
||||
|
||||
return {
|
||||
embeds: [baseEmbed, guildAvatar && guildEmbed].filter((x) => x != null),
|
||||
|
@ -310,7 +311,7 @@ const banner = new Command("banner");
|
|||
banner.category = CATEGORY;
|
||||
banner.helpText = "Get banner of a user";
|
||||
banner.usage = "<user>";
|
||||
banner.callback = async function(msg, line, [user], { server, guild }) {
|
||||
banner.callback = async function (msg, line, [user], {server, guild}) {
|
||||
let id = msg.author.id;
|
||||
|
||||
if (server || guild) {
|
||||
|
@ -321,8 +322,9 @@ 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,8 +358,9 @@ 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: [
|
||||
{
|
||||
|
@ -377,7 +380,7 @@ lookupinvite.category = CATEGORY;
|
|||
lookupinvite.helpText = "Lookup an invite";
|
||||
lookupinvite.usage = "<invite code>";
|
||||
lookupinvite.addAlias("linvite");
|
||||
lookupinvite.callback = async function(msg, line) {
|
||||
lookupinvite.callback = async function (msg, line) {
|
||||
if (!line || line == "") {
|
||||
return "No arguments passed.";
|
||||
}
|
||||
|
@ -415,118 +418,155 @@ lookupinvite.callback = async function(msg, line) {
|
|||
const embed = {
|
||||
title: `Invite Info: \`${invite.code}\``,
|
||||
description: invite.description,
|
||||
fields: [
|
||||
{
|
||||
name: "Guild",
|
||||
value: `**${invite.guild.name}** (${invite.guild.id})`,
|
||||
inline: true,
|
||||
},
|
||||
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})`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "Channel",
|
||||
value: `**${invite.channel.name}** (${invite.channel.id})`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "Member Count",
|
||||
value: `${STATUS_ICONS.online}${invite.approximate_presence_count} online\t\t${STATUS_ICONS.offline}${invite.approximate_member_count} members`,
|
||||
inline: false,
|
||||
},
|
||||
{
|
||||
name: "Boosts",
|
||||
value: invite.guild.premium_subscription_count ?? 0,
|
||||
inline: true,
|
||||
},
|
||||
expires,
|
||||
invite.guild.welcome_screen && {
|
||||
name: "Welcome Screen",
|
||||
value: `"${
|
||||
invite.guild.welcome_screen.description
|
||||
}"\n${invite.guild.welcome_screen.welcome_channels
|
||||
.map(
|
||||
(c) =>
|
||||
`${
|
||||
c.emoji_id
|
||||
? `[:${c.emoji_name}:](${EMOTE_BASE}${c.emoji_id}.webp)`
|
||||
: c.emoji_name
|
||||
} ${c.description} \`(${c.channel_id})\``
|
||||
)
|
||||
.join("\n")}`,
|
||||
inline: false,
|
||||
},
|
||||
{
|
||||
name: "Features",
|
||||
value:
|
||||
invite.guild.features.length > 0
|
||||
? invite.guild.features
|
||||
.map((feature) =>
|
||||
feature
|
||||
.split("_")
|
||||
.map((x) => x[0] + x.substring(1).toLowerCase())
|
||||
.join(" ")
|
||||
)
|
||||
.join(", ")
|
||||
: "None",
|
||||
inline: false,
|
||||
},
|
||||
].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,
|
||||
},
|
||||
{
|
||||
name: "Member Count",
|
||||
value: `${STATUS_ICONS.online}${invite.approximate_presence_count} online\t\t${STATUS_ICONS.offline}${invite.approximate_member_count} members`,
|
||||
inline: false,
|
||||
},
|
||||
{
|
||||
name: "Boosts",
|
||||
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,
|
||||
},
|
||||
invite.guild.welcome_screen && {
|
||||
name: "Welcome Screen",
|
||||
value: `"${invite.guild.welcome_screen.description
|
||||
}"\n${invite.guild.welcome_screen.welcome_channels
|
||||
.map(
|
||||
(c) =>
|
||||
`${c.emoji_id
|
||||
? `[:${c.emoji_name}:](${EMOTE_BASE}${c.emoji_id}.webp)`
|
||||
: c.emoji_name
|
||||
} ${c.description} \`(${c.channel_id})\``
|
||||
)
|
||||
.join("\n")}`,
|
||||
inline: false,
|
||||
},
|
||||
{
|
||||
name: "Features",
|
||||
value:
|
||||
invite.guild.features.length > 0
|
||||
? invite.guild.features
|
||||
.map((feature) =>
|
||||
feature
|
||||
.split("_")
|
||||
.map((x) => x[0] + x.substring(1).toLowerCase())
|
||||
.join(" ")
|
||||
)
|
||||
.join(", ")
|
||||
: "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"
|
||||
}`,
|
||||
},
|
||||
};
|
||||
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_")
|
||||
? "gif?size=1024"
|
||||
: "png?size=1024"
|
||||
})`
|
||||
: ""
|
||||
}${invite.guild.splash
|
||||
? `${invite.guild.icon ? " | " : ""}[Splash](${SPLASH_BASE}${invite.guild.id
|
||||
}/${invite.guild.splash}.png?size=2048)`
|
||||
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.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"
|
||||
})`
|
||||
}${
|
||||
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) {
|
||||
if (invite.guild?.splash) {
|
||||
embed.image = {
|
||||
url: `${SPLASH_BASE}${invite.guild.id}/${invite.guild.splash}.png?size=256`,
|
||||
};
|
||||
}
|
||||
|
||||
return { embed };
|
||||
return {embed};
|
||||
}
|
||||
};
|
||||
hf.registerCommand(lookupinvite);
|
||||
|
@ -535,7 +575,7 @@ const snowflake = new Command("snowflake");
|
|||
snowflake.category = CATEGORY;
|
||||
snowflake.helpText = "Converts a snowflake ID into readable time.";
|
||||
snowflake.usage = "<--twitter> [snowflake]";
|
||||
snowflake.callback = function(msg, line, [snowflake], { twitter }) {
|
||||
snowflake.callback = function (msg, line, [snowflake], {twitter}) {
|
||||
const num = parseInt(snowflake);
|
||||
if (!isNaN(num)) {
|
||||
let binary = num.toString(2);
|
||||
|
@ -582,7 +622,7 @@ const flagdump = new Command("flagdump");
|
|||
flagdump.category = CATEGORY;
|
||||
flagdump.helpText = "Dumps Discord user flags.";
|
||||
flagdump.usage = "[flags or user mention]";
|
||||
flagdump.callback = async function(msg, line, [numOrMention], { id, list }) {
|
||||
flagdump.callback = async function (msg, line, [numOrMention], {id, list}) {
|
||||
const num = Number(numOrMention);
|
||||
if (list) {
|
||||
let allFlags = 0n;
|
||||
|
@ -595,7 +635,7 @@ flagdump.callback = async function(msg, line, [numOrMention], { id, list }) {
|
|||
const targetId = id || numOrMention.match(/<@!?(\d+)>/)?.[1];
|
||||
if (!targetId) return "Got null ID.";
|
||||
const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID);
|
||||
let user = guild && (await guild.fetchMembers({ userIDs: [targetId] }));
|
||||
let user = guild && (await guild.fetchMembers({userIDs: [targetId]}));
|
||||
if (!user || !user[0]) {
|
||||
user = hf.bot.users.get(id);
|
||||
} else {
|
||||
|
@ -605,14 +645,16 @@ flagdump.callback = async function(msg, line, [numOrMention], { id, list }) {
|
|||
if (!user) {
|
||||
return "User not cached.";
|
||||
} else {
|
||||
return `\`${user.username}#${user.discriminator
|
||||
}\`'s public flags:\n\`\`\`${flagFromInt(user.publicFlags)}\`\`\``;
|
||||
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
|
||||
}\`'s public flags:\n\`\`\`${flagFromInt(msg.author.publicFlags)}\`\`\``;
|
||||
return `\`${msg.author.username}#${
|
||||
msg.author.discriminator
|
||||
}\`'s public flags:\n\`\`\`${flagFromInt(msg.author.publicFlags)}\`\`\``;
|
||||
}
|
||||
};
|
||||
hf.registerCommand(flagdump);
|
||||
|
@ -624,7 +666,7 @@ jumbo.usage = "<emoji>";
|
|||
jumbo.addAlias("e");
|
||||
jumbo.addAlias("emote");
|
||||
jumbo.addAlias("emoji");
|
||||
jumbo.callback = async function(msg, line) {
|
||||
jumbo.callback = async function (msg, line) {
|
||||
if (CUSTOM_EMOTE_REGEX.test(line)) {
|
||||
const [_, animatedFlag, name, id] = line.match(CUSTOM_EMOTE_REGEX);
|
||||
const animated = animatedFlag === "a";
|
||||
|
@ -659,10 +701,10 @@ jumbo.callback = async function(msg, line) {
|
|||
const name = EMOJI_NAMES[line]
|
||||
? `\\:${EMOJI_NAMES[line]}\\:`
|
||||
: await getNamesFromString(line).then((name) =>
|
||||
name.map((x) => x[1]).join(", ")
|
||||
);
|
||||
name.map((x) => x[1]).join(", ")
|
||||
);
|
||||
|
||||
const emojiFound = await fetch(url, { method: "HEAD" }).then((res) => res.ok);
|
||||
const emojiFound = await fetch(url, {method: "HEAD"}).then((res) => res.ok);
|
||||
|
||||
if (emojiFound) {
|
||||
return "Emoji not found. The emoji set chosen might not have this emote as an image.";
|
||||
|
@ -672,7 +714,7 @@ jumbo.callback = async function(msg, line) {
|
|||
const svg = await fetch(url)
|
||||
.then((res) => res.arrayBuffer())
|
||||
.then((b) => Buffer.from(b));
|
||||
const converted = await sharp(svg, { density: 2400 })
|
||||
const converted = await sharp(svg, {density: 2400})
|
||||
.resize(1024)
|
||||
.toBuffer();
|
||||
|
||||
|
@ -713,7 +755,7 @@ charinfo.category = CATEGORY;
|
|||
charinfo.helpText = "Get information about a set of characters.";
|
||||
charinfo.usage = "[characters]";
|
||||
charinfo.addAlias("char");
|
||||
charinfo.callback = async function(msg, line) {
|
||||
charinfo.callback = async function (msg, line) {
|
||||
const names = await getNamesFromString(line);
|
||||
const chars = [...line];
|
||||
const lines = names
|
||||
|
@ -736,7 +778,7 @@ presence.category = CATEGORY;
|
|||
presence.helpText = "Get presences of a user.";
|
||||
presence.usage = "<user>";
|
||||
presence.addAlias("status");
|
||||
presence.callback = async function(msg, line) {
|
||||
presence.callback = async function (msg, line) {
|
||||
if (!msg.guildID) return "Can only be used in guilds.";
|
||||
|
||||
let target;
|
||||
|
@ -788,8 +830,9 @@ 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,
|
||||
icon_url: url,
|
||||
|
@ -985,8 +1028,9 @@ presence.callback = async function(msg, line) {
|
|||
}
|
||||
|
||||
return {
|
||||
content: `Presence for **${target.username}#${target.discriminator
|
||||
}**: ${icons.trim()}`,
|
||||
content: `Presence for **${target.username}#${
|
||||
target.discriminator
|
||||
}**: ${icons.trim()}`,
|
||||
embeds,
|
||||
files,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue