guildinfo: fix local not resolving profile from vanity
This commit is contained in:
parent
7c82811b4b
commit
89480d98d7
1 changed files with 144 additions and 144 deletions
|
@ -70,160 +70,160 @@ guildinfo.callback = async function (msg, line, args, {nolocal, debug}) {
|
||||||
const snowflake = line.match(SNOWFLAKE_REGEX)[1];
|
const snowflake = line.match(SNOWFLAKE_REGEX)[1];
|
||||||
_guild = await getGuild(snowflake, nolocal);
|
_guild = await getGuild(snowflake, nolocal);
|
||||||
id = snowflake;
|
id = snowflake;
|
||||||
|
}
|
||||||
|
|
||||||
let clan = await hf.bot.requestHandler.request("GET", APIEndpoints.CLAN(snowflake), true).catch(() => {});
|
let clan = await hf.bot.requestHandler.request("GET", APIEndpoints.CLAN(id), true).catch(() => {});
|
||||||
if (!clan) {
|
if (!clan) {
|
||||||
if (_guild?.profile) {
|
if (_guild?.profile) {
|
||||||
clan = _guild?.profile;
|
clan = _guild?.profile;
|
||||||
} else {
|
} else {
|
||||||
const verif = await hf.bot.requestHandler
|
const verif = await hf.bot.requestHandler
|
||||||
.request("GET", `${APIEndpoints.GUILD_MEMBER_VERIFICATION(snowflake)}?with_guild=true`, true)
|
.request("GET", `${APIEndpoints.GUILD_MEMBER_VERIFICATION(id)}?with_guild=true`, true)
|
||||||
|
.catch(() => {});
|
||||||
|
if (verif?.profile) {
|
||||||
|
clan = verif.profile;
|
||||||
|
} else if (_guild?.vanityURL) {
|
||||||
|
const invite = await hf.bot.requestHandler
|
||||||
|
.request("GET", `${APIEndpoints.INVITE(_guild.vanityURL)}?with_counts=true&with_expiration=true`)
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
if (verif?.profile) {
|
if (invite?.profile) clan = invite.profile;
|
||||||
clan = verif.profile;
|
}
|
||||||
} else if (_guild?.vanityURL) {
|
}
|
||||||
const invite = await hf.bot.requestHandler
|
}
|
||||||
.request("GET", `${APIEndpoints.INVITE(_guild.vanityURL)}?with_counts=true&with_expiration=true`)
|
|
||||||
.catch(() => {});
|
if (clan) {
|
||||||
if (invite?.profile) clan = invite.profile;
|
const images = [];
|
||||||
|
|
||||||
|
const game_ids = clan.game_ids ?? clan.game_application_ids ?? [];
|
||||||
|
const games = await Promise.all(
|
||||||
|
game_ids
|
||||||
|
.sort((a, b) => (clan.game_activity[b]?.activity_score ?? 0) - (clan.game_activity[a]?.activity_score ?? 0))
|
||||||
|
.map(async (id) => {
|
||||||
|
let game = Games.find((x) => x.id == id);
|
||||||
|
if (!game) {
|
||||||
|
game = await hf.bot.requestHandler.request("GET", APIEndpoints.APPLICATION_RPC(id), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
let out = `${game.name} (\`${id}\`)`;
|
||||||
|
|
||||||
|
if (clan.game_activity[id]?.activity_level > 1) {
|
||||||
|
out = `:fire: ${out}`;
|
||||||
|
} else {
|
||||||
|
out = `${Icons.blank} ${out}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
if (clan.wildcard_descriptors) clan.wildcard_descriptors = clan.wildcard_descriptors.filter((x) => x != "");
|
||||||
|
|
||||||
|
const termLines = [];
|
||||||
|
let currentTerm = "";
|
||||||
|
if (clan.search_terms) {
|
||||||
|
for (const index in clan.search_terms) {
|
||||||
|
const term = clan.search_terms[index];
|
||||||
|
const formattedTerm = `\`\u2004${term.replaceAll(" ", "\u2005")}\u2004\``;
|
||||||
|
if (currentTerm.length + 1 + formattedTerm.length > 56) {
|
||||||
|
termLines.push(currentTerm);
|
||||||
|
currentTerm = formattedTerm;
|
||||||
|
} else {
|
||||||
|
currentTerm += "\u2004" + formattedTerm;
|
||||||
}
|
}
|
||||||
|
if (index == clan.search_terms.length - 1) termLines.push(currentTerm);
|
||||||
|
}
|
||||||
|
} else if (clan.traits) {
|
||||||
|
for (const index in clan.traits) {
|
||||||
|
const term = clan.traits[index];
|
||||||
|
const formattedTerm = `${term.emoji_name ? `:${term.emoji_name}:` : ""}\`\u2004${term.label.replaceAll(
|
||||||
|
" ",
|
||||||
|
"\u2005"
|
||||||
|
)}\u2004\``;
|
||||||
|
if (currentTerm.length + 1 + formattedTerm.length > 56) {
|
||||||
|
termLines.push(currentTerm);
|
||||||
|
currentTerm = formattedTerm;
|
||||||
|
} else {
|
||||||
|
currentTerm += "\u2004" + formattedTerm;
|
||||||
|
}
|
||||||
|
if (index == clan.traits.length - 1) termLines.push(currentTerm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clan) {
|
let gameLines = "";
|
||||||
const images = [];
|
let gameLines2 = "";
|
||||||
|
for (const line of games) {
|
||||||
const game_ids = clan.game_ids ?? clan.game_application_ids ?? [];
|
if (gameLines.length + line.length + 1 <= 1024) {
|
||||||
const games = await Promise.all(
|
gameLines += line + "\n";
|
||||||
game_ids
|
} else {
|
||||||
.sort((a, b) => (clan.game_activity[b]?.activity_score ?? 0) - (clan.game_activity[a]?.activity_score ?? 0))
|
gameLines2 += line + "\n";
|
||||||
.map(async (id) => {
|
|
||||||
let game = Games.find((x) => x.id == id);
|
|
||||||
if (!game) {
|
|
||||||
game = await hf.bot.requestHandler.request("GET", APIEndpoints.APPLICATION_RPC(id), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
let out = `${game.name} (\`${id}\`)`;
|
|
||||||
|
|
||||||
if (clan.game_activity[id]?.activity_level > 1) {
|
|
||||||
out = `:fire: ${out}`;
|
|
||||||
} else {
|
|
||||||
out = `${Icons.blank} ${out}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
if (clan.wildcard_descriptors) clan.wildcard_descriptors = clan.wildcard_descriptors.filter((x) => x != "");
|
|
||||||
|
|
||||||
const termLines = [];
|
|
||||||
let currentTerm = "";
|
|
||||||
if (clan.search_terms) {
|
|
||||||
for (const index in clan.search_terms) {
|
|
||||||
const term = clan.search_terms[index];
|
|
||||||
const formattedTerm = `\`\u2004${term.replaceAll(" ", "\u2005")}\u2004\``;
|
|
||||||
if (currentTerm.length + 1 + formattedTerm.length > 56) {
|
|
||||||
termLines.push(currentTerm);
|
|
||||||
currentTerm = formattedTerm;
|
|
||||||
} else {
|
|
||||||
currentTerm += "\u2004" + formattedTerm;
|
|
||||||
}
|
|
||||||
if (index == clan.search_terms.length - 1) termLines.push(currentTerm);
|
|
||||||
}
|
|
||||||
} else if (clan.traits) {
|
|
||||||
for (const index in clan.traits) {
|
|
||||||
const term = clan.traits[index];
|
|
||||||
const formattedTerm = `${term.emoji_name ? `:${term.emoji_name}:` : ""}\`\u2004${term.label.replaceAll(
|
|
||||||
" ",
|
|
||||||
"\u2005"
|
|
||||||
)}\u2004\``;
|
|
||||||
if (currentTerm.length + 1 + formattedTerm.length > 56) {
|
|
||||||
termLines.push(currentTerm);
|
|
||||||
currentTerm = formattedTerm;
|
|
||||||
} else {
|
|
||||||
currentTerm += "\u2004" + formattedTerm;
|
|
||||||
}
|
|
||||||
if (index == clan.traits.length - 1) termLines.push(currentTerm);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let gameLines = "";
|
clanEmbed = {
|
||||||
let gameLines2 = "";
|
color: clan.brand_color_primary ? parseInt(clan.brand_color_primary.replace("#", "0x")) : 0,
|
||||||
for (const line of games) {
|
title: _guild == null ? clan.name : null,
|
||||||
if (gameLines.length + line.length + 1 <= 1024) {
|
author: {
|
||||||
gameLines += line + "\n";
|
name: clan.tag,
|
||||||
} else {
|
},
|
||||||
gameLines2 += line + "\n";
|
description:
|
||||||
}
|
clan.playstyle || clan.wildcard_descriptors
|
||||||
}
|
? `-# :video_game:${ClanPlaystyle[clan.playstyle] ?? "Unknown"}${
|
||||||
|
clan.wildcard_descriptors.length > 0 ? ` \u2022 **${clan.wildcard_descriptors.join(", ")}**` : ""
|
||||||
clanEmbed = {
|
}\n\n${clan.description ?? "*No description*"}`
|
||||||
color: clan.brand_color_primary ? parseInt(clan.brand_color_primary.replace("#", "0x")) : 0,
|
: clan.description ?? "*No description*",
|
||||||
title: _guild == null ? clan.name : null,
|
fields: [
|
||||||
author: {
|
!_guild && {
|
||||||
name: clan.tag,
|
name: "Member Count",
|
||||||
|
value: clan.member_count,
|
||||||
|
inline: true,
|
||||||
},
|
},
|
||||||
description:
|
termLines.length > 0 && {
|
||||||
clan.playstyle || clan.wildcard_descriptors
|
name: "Traits",
|
||||||
? `-# :video_game:${ClanPlaystyle[clan.playstyle] ?? "Unknown"}${
|
value: termLines.join("\n"),
|
||||||
clan.wildcard_descriptors.length > 0 ? ` \u2022 **${clan.wildcard_descriptors.join(", ")}**` : ""
|
|
||||||
}\n\n${clan.description ?? "*No description*"}`
|
|
||||||
: clan.description ?? "*No description*",
|
|
||||||
fields: [
|
|
||||||
!_guild && {
|
|
||||||
name: "Member Count",
|
|
||||||
value: clan.member_count,
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
termLines.length > 0 && {
|
|
||||||
name: "Traits",
|
|
||||||
value: termLines.join("\n"),
|
|
||||||
inline: false,
|
|
||||||
},
|
|
||||||
games.length > 0 && {
|
|
||||||
name: "Associated Games",
|
|
||||||
value: gameLines,
|
|
||||||
inline: false,
|
|
||||||
},
|
|
||||||
gameLines2 != "" && {
|
|
||||||
name: "\u200b",
|
|
||||||
value: gameLines2,
|
|
||||||
inline: false,
|
|
||||||
},
|
|
||||||
clan.badge_color_primary && {
|
|
||||||
name: "Badge Colors",
|
|
||||||
value: `${clan.badge_color_primary}, ${clan.badge_color_secondary}`,
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
clan.brand_color_primary && {
|
|
||||||
name: "Banner/Brand Colors",
|
|
||||||
value: `${clan.brand_color_primary}${clan.brand_color_secondary ? `, ${clan.brand_color_secondary}` : ""}`,
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
].filter((x) => !!x),
|
|
||||||
thumbnail: !_guild ? {url: CDNEndpoints.GUILD_ICON(clan.id, clan.icon_hash)} : null,
|
|
||||||
footer: !_guild ? {text: "Fetched from clan"} : null,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (clan.badge_hash) {
|
|
||||||
const url = CDNEndpoints.CLAN_BADGE(clan.id, clan.badge_hash);
|
|
||||||
images.push(`[Badge](${url})`);
|
|
||||||
clanEmbed.author.icon_url = url;
|
|
||||||
}
|
|
||||||
if (clan.banner_hash) {
|
|
||||||
const url = CDNEndpoints.CLAN_BANNER(clan.id, clan.banner_hash);
|
|
||||||
images.push(`[Banner](${url})`);
|
|
||||||
clanEmbed.image = {url};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (images.length > 0) {
|
|
||||||
clanEmbed.fields.push({
|
|
||||||
name: "\u200b",
|
|
||||||
value: images.join("\u3000\u3000"),
|
|
||||||
inline: false,
|
inline: false,
|
||||||
});
|
},
|
||||||
}
|
games.length > 0 && {
|
||||||
|
name: "Associated Games",
|
||||||
|
value: gameLines,
|
||||||
|
inline: false,
|
||||||
|
},
|
||||||
|
gameLines2 != "" && {
|
||||||
|
name: "\u200b",
|
||||||
|
value: gameLines2,
|
||||||
|
inline: false,
|
||||||
|
},
|
||||||
|
clan.badge_color_primary && {
|
||||||
|
name: "Badge Colors",
|
||||||
|
value: `${clan.badge_color_primary}, ${clan.badge_color_secondary}`,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
clan.brand_color_primary && {
|
||||||
|
name: "Banner/Brand Colors",
|
||||||
|
value: `${clan.brand_color_primary}${clan.brand_color_secondary ? `, ${clan.brand_color_secondary}` : ""}`,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
].filter((x) => !!x),
|
||||||
|
thumbnail: !_guild ? {url: CDNEndpoints.GUILD_ICON(clan.id, clan.icon_hash)} : null,
|
||||||
|
footer: !_guild ? {text: "Fetched from clan"} : null,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (clan.badge_hash) {
|
||||||
|
const url = CDNEndpoints.CLAN_BADGE(clan.id, clan.badge_hash);
|
||||||
|
images.push(`[Badge](${url})`);
|
||||||
|
clanEmbed.author.icon_url = url;
|
||||||
|
}
|
||||||
|
if (clan.banner_hash) {
|
||||||
|
const url = CDNEndpoints.CLAN_BANNER(clan.id, clan.banner_hash);
|
||||||
|
images.push(`[Banner](${url})`);
|
||||||
|
clanEmbed.image = {url};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (images.length > 0) {
|
||||||
|
clanEmbed.fields.push({
|
||||||
|
name: "\u200b",
|
||||||
|
value: images.join("\u3000\u3000"),
|
||||||
|
inline: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue