userinfo: fix getting server tag guild name
This commit is contained in:
parent
1d891b5932
commit
265047c71a
4 changed files with 88 additions and 91 deletions
|
@ -279,7 +279,7 @@ events.add("guildAuditLogEntryCreate", "logging", async function (entry) {
|
||||||
default: {
|
default: {
|
||||||
fields.push({
|
fields.push({
|
||||||
name: key,
|
name: key,
|
||||||
value: `\`${oldValue}\` -> \`${newValue}\``,
|
value: formatChange(oldValue, newValue),
|
||||||
inline: true,
|
inline: true,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -19,7 +19,7 @@ const {
|
||||||
ChannelTypeNames,
|
ChannelTypeNames,
|
||||||
} = require("#util/constants.js");
|
} = require("#util/constants.js");
|
||||||
const {snowflakeToTimestamp} = require("#util/time.js");
|
const {snowflakeToTimestamp} = require("#util/time.js");
|
||||||
const {getGuild, tryGetGuild, formatGuildFeatures, makeGuildFeatureFields} = require("#util/misc.js");
|
const {getGuild, getGuildProfile, tryGetGuild, formatGuildFeatures, makeGuildFeatureFields} = require("#util/misc.js");
|
||||||
|
|
||||||
const guildinfo = new Command("guildinfo");
|
const guildinfo = new Command("guildinfo");
|
||||||
guildinfo.category = "utility";
|
guildinfo.category = "utility";
|
||||||
|
@ -72,49 +72,16 @@ guildinfo.callback = async function (msg, line, args, {nolocal, debug}) {
|
||||||
id = snowflake;
|
id = snowflake;
|
||||||
}
|
}
|
||||||
|
|
||||||
let clan = await hf.bot.requestHandler.request("GET", APIEndpoints.CLAN(id), true).catch(() => {});
|
const profile = await getGuildProfile(id, _guild);
|
||||||
if (!clan) {
|
if (profile) {
|
||||||
if (_guild?.data?.profile) {
|
|
||||||
clan = _guild?.profile;
|
|
||||||
} else {
|
|
||||||
const verif = await hf.bot.requestHandler
|
|
||||||
.request("GET", `${APIEndpoints.GUILD_MEMBER_VERIFICATION(id)}?with_guild=true`, true)
|
|
||||||
.catch(() => {});
|
|
||||||
if (verif?.profile) {
|
|
||||||
clan = verif.profile;
|
|
||||||
} else {
|
|
||||||
let code =
|
|
||||||
_guild?.data?.vanityURL ??
|
|
||||||
_guild?.data?.store_page?.guild?.invite?.code ??
|
|
||||||
_guild?.data?.store_page?.role_subscription?.purchase_page_invite?.code ??
|
|
||||||
_guild?.data?.instant_invite?.replace(
|
|
||||||
/(https?:\/\/)?(canary\.|ptb\.)?discord(\.gg|(app)?.com\/invite)\//,
|
|
||||||
""
|
|
||||||
);
|
|
||||||
if (!code && hf.bot.guilds.has(id)) {
|
|
||||||
const invites = await hf.bot.requestHandler
|
|
||||||
.request("GET", APIEndpoints.GUILD_INVITES(id), true)
|
|
||||||
.catch(() => {});
|
|
||||||
if (invites?.[0]?.code) code = invites[0].code;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (code) {
|
|
||||||
const invite = await hf.bot.requestHandler
|
|
||||||
.request("GET", `${APIEndpoints.INVITE(code)}?with_counts=true&with_expiration=true`)
|
|
||||||
.catch(() => {});
|
|
||||||
if (invite?.profile) clan = invite.profile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clan) {
|
|
||||||
const images = [];
|
const images = [];
|
||||||
|
|
||||||
const game_ids = clan.game_ids ?? clan.game_application_ids ?? [];
|
const game_ids = profile.game_ids ?? profile.game_application_ids ?? [];
|
||||||
const games = await Promise.all(
|
const games = await Promise.all(
|
||||||
game_ids
|
game_ids
|
||||||
.sort((a, b) => (clan.game_activity[b]?.activity_score ?? 0) - (clan.game_activity[a]?.activity_score ?? 0))
|
.sort(
|
||||||
|
(a, b) => (profile.game_activity[b]?.activity_score ?? 0) - (profile.game_activity[a]?.activity_score ?? 0)
|
||||||
|
)
|
||||||
.map(async (id) => {
|
.map(async (id) => {
|
||||||
let game = Games.find((x) => x.id == id);
|
let game = Games.find((x) => x.id == id);
|
||||||
if (!game) {
|
if (!game) {
|
||||||
|
@ -123,7 +90,7 @@ guildinfo.callback = async function (msg, line, args, {nolocal, debug}) {
|
||||||
|
|
||||||
let out = `${game.name} (\`${id}\`)`;
|
let out = `${game.name} (\`${id}\`)`;
|
||||||
|
|
||||||
if (clan.game_activity[id]?.activity_level > 1) {
|
if (profile.game_activity[id]?.activity_level > 1) {
|
||||||
out = `:fire: ${out}`;
|
out = `:fire: ${out}`;
|
||||||
} else {
|
} else {
|
||||||
out = `${Icons.blank} ${out}`;
|
out = `${Icons.blank} ${out}`;
|
||||||
|
@ -133,13 +100,14 @@ guildinfo.callback = async function (msg, line, args, {nolocal, debug}) {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
if (clan.wildcard_descriptors) clan.wildcard_descriptors = clan.wildcard_descriptors.filter((x) => x != "");
|
if (profile.wildcard_descriptors)
|
||||||
|
profile.wildcard_descriptors = profile.wildcard_descriptors.filter((x) => x != "");
|
||||||
|
|
||||||
const termLines = [];
|
const termLines = [];
|
||||||
let currentTerm = "";
|
let currentTerm = "";
|
||||||
if (clan.search_terms) {
|
if (profile.search_terms) {
|
||||||
for (const index in clan.search_terms) {
|
for (const index in profile.search_terms) {
|
||||||
const term = clan.search_terms[index];
|
const term = profile.search_terms[index];
|
||||||
const formattedTerm = `\`\u2004${term.replaceAll(" ", "\u2005")}\u2004\``;
|
const formattedTerm = `\`\u2004${term.replaceAll(" ", "\u2005")}\u2004\``;
|
||||||
if (currentTerm.length + 1 + formattedTerm.length > 56) {
|
if (currentTerm.length + 1 + formattedTerm.length > 56) {
|
||||||
termLines.push(currentTerm);
|
termLines.push(currentTerm);
|
||||||
|
@ -147,11 +115,11 @@ guildinfo.callback = async function (msg, line, args, {nolocal, debug}) {
|
||||||
} else {
|
} else {
|
||||||
currentTerm += "\u2004" + formattedTerm;
|
currentTerm += "\u2004" + formattedTerm;
|
||||||
}
|
}
|
||||||
if (index == clan.search_terms.length - 1) termLines.push(currentTerm);
|
if (index == profile.search_terms.length - 1) termLines.push(currentTerm);
|
||||||
}
|
}
|
||||||
} else if (clan.traits) {
|
} else if (profile.traits) {
|
||||||
for (const index in clan.traits) {
|
for (const index in profile.traits) {
|
||||||
const term = clan.traits[index];
|
const term = profile.traits[index];
|
||||||
const formattedTerm = `${term.emoji_name ? `:${term.emoji_name}:` : ""}\`\u2004${term.label.replaceAll(
|
const formattedTerm = `${term.emoji_name ? `:${term.emoji_name}:` : ""}\`\u2004${term.label.replaceAll(
|
||||||
" ",
|
" ",
|
||||||
"\u2005"
|
"\u2005"
|
||||||
|
@ -162,7 +130,7 @@ guildinfo.callback = async function (msg, line, args, {nolocal, debug}) {
|
||||||
} else {
|
} else {
|
||||||
currentTerm += "\u2004" + formattedTerm;
|
currentTerm += "\u2004" + formattedTerm;
|
||||||
}
|
}
|
||||||
if (index == clan.traits.length - 1) termLines.push(currentTerm);
|
if (index == profile.traits.length - 1) termLines.push(currentTerm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,21 +145,21 @@ guildinfo.callback = async function (msg, line, args, {nolocal, debug}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
clanEmbed = {
|
clanEmbed = {
|
||||||
color: clan.brand_color_primary ? parseInt(clan.brand_color_primary.replace("#", "0x")) : 0,
|
color: profile.brand_color_primary ? parseInt(profile.brand_color_primary.replace("#", "0x")) : 0,
|
||||||
title: _guild == null ? clan.name : null,
|
title: _guild == null ? profile.name : null,
|
||||||
author: {
|
author: {
|
||||||
name: clan.tag,
|
name: profile.tag,
|
||||||
},
|
},
|
||||||
description:
|
description:
|
||||||
clan.playstyle || clan.wildcard_descriptors
|
profile.playstyle || profile.wildcard_descriptors
|
||||||
? `-# :video_game:${ClanPlaystyle[clan.playstyle] ?? "Unknown"}${
|
? `-# :video_game:${ClanPlaystyle[profile.playstyle] ?? "Unknown"}${
|
||||||
clan.wildcard_descriptors.length > 0 ? ` \u2022 **${clan.wildcard_descriptors.join(", ")}**` : ""
|
profile.wildcard_descriptors.length > 0 ? ` \u2022 **${profile.wildcard_descriptors.join(", ")}**` : ""
|
||||||
}\n\n${clan.description ?? "*No description*"}`
|
}\n\n${profile.description ?? "*No description*"}`
|
||||||
: clan.description ?? "*No description*",
|
: profile.description ?? "*No description*",
|
||||||
fields: [
|
fields: [
|
||||||
!_guild && {
|
!_guild && {
|
||||||
name: "Member Count",
|
name: "Member Count",
|
||||||
value: clan.member_count,
|
value: profile.member_count,
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
termLines.length > 0 && {
|
termLines.length > 0 && {
|
||||||
|
@ -209,28 +177,30 @@ guildinfo.callback = async function (msg, line, args, {nolocal, debug}) {
|
||||||
value: gameLines2,
|
value: gameLines2,
|
||||||
inline: false,
|
inline: false,
|
||||||
},
|
},
|
||||||
clan.badge_color_primary && {
|
profile.badge_color_primary && {
|
||||||
name: "Badge Colors",
|
name: "Badge Colors",
|
||||||
value: `${clan.badge_color_primary}, ${clan.badge_color_secondary}`,
|
value: `${profile.badge_color_primary}, ${profile.badge_color_secondary}`,
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
clan.brand_color_primary && {
|
profile.brand_color_primary && {
|
||||||
name: "Banner/Brand Colors",
|
name: "Banner/Brand Colors",
|
||||||
value: `${clan.brand_color_primary}${clan.brand_color_secondary ? `, ${clan.brand_color_secondary}` : ""}`,
|
value: `${profile.brand_color_primary}${
|
||||||
|
profile.brand_color_secondary ? `, ${profile.brand_color_secondary}` : ""
|
||||||
|
}`,
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
].filter((x) => !!x),
|
].filter((x) => !!x),
|
||||||
thumbnail: !_guild ? {url: CDNEndpoints.GUILD_ICON(clan.id, clan.icon_hash)} : null,
|
thumbnail: !_guild ? {url: CDNEndpoints.GUILD_ICON(profile.id, profile.icon_hash)} : null,
|
||||||
footer: !_guild ? {text: "Fetched from clan"} : null,
|
footer: !_guild ? {text: "Fetched from clan"} : null,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (clan.badge_hash) {
|
if (profile.badge_hash) {
|
||||||
const url = CDNEndpoints.CLAN_BADGE(clan.id, clan.badge_hash);
|
const url = CDNEndpoints.CLAN_BADGE(profile.id, profile.badge_hash);
|
||||||
images.push(`[Badge](${url})`);
|
images.push(`[Badge](${url})`);
|
||||||
clanEmbed.author.icon_url = url;
|
clanEmbed.author.icon_url = url;
|
||||||
}
|
}
|
||||||
if (clan.banner_hash) {
|
if (profile.banner_hash) {
|
||||||
const url = CDNEndpoints.CLAN_BANNER(clan.id, clan.banner_hash);
|
const url = CDNEndpoints.CLAN_BANNER(profile.id, profile.banner_hash);
|
||||||
images.push(`[Banner](${url})`);
|
images.push(`[Banner](${url})`);
|
||||||
clanEmbed.image = {url};
|
clanEmbed.image = {url};
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,11 @@ const {
|
||||||
ApplicationFlags,
|
ApplicationFlags,
|
||||||
BadgeURLs,
|
BadgeURLs,
|
||||||
CDNEndpoints,
|
CDNEndpoints,
|
||||||
ClanPlaystyle,
|
|
||||||
UserFlags,
|
UserFlags,
|
||||||
} = require("#util/dconstants.js");
|
} = require("#util/dconstants.js");
|
||||||
const {Icons} = require("#util/constants.js");
|
const {Icons} = require("#util/constants.js");
|
||||||
|
|
||||||
const {formatUsername, getDefaultAvatar, getTopColor, pastelize} = require("#util/misc.js");
|
const {formatUsername, getDefaultAvatar, getGuild, getTopColor, pastelize} = require("#util/misc.js");
|
||||||
const {snowflakeToTimestamp} = require("#util/time.js");
|
const {snowflakeToTimestamp} = require("#util/time.js");
|
||||||
const {lookupUser} = require("#util/selection.js");
|
const {lookupUser} = require("#util/selection.js");
|
||||||
|
|
||||||
|
@ -306,13 +305,8 @@ userinfo.callback = async function (msg, line) {
|
||||||
if (user.system) {
|
if (user.system) {
|
||||||
descLines.push("**System account**");
|
descLines.push("**System account**");
|
||||||
}
|
}
|
||||||
let clanData;
|
|
||||||
if (user.clan?.identity_guild_id) {
|
const primaryGuild = await getGuild(user.primary_guild.identity_guild_id);
|
||||||
clanData = await hf.bot.requestHandler
|
|
||||||
.request("GET", APIEndpoints.CLAN(user.clan.identity_guild_id), true)
|
|
||||||
.catch(() => {});
|
|
||||||
if (clanData) clanData.wildcard_descriptors = clanData.wildcard_descriptors.filter((x) => x != "");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (anyMember) {
|
if (anyMember) {
|
||||||
const icons = [];
|
const icons = [];
|
||||||
|
@ -347,15 +341,10 @@ userinfo.callback = async function (msg, line) {
|
||||||
|
|
||||||
const embed = {
|
const embed = {
|
||||||
color: getTopColor(msg, id, user.accent_color ?? pastelize(id)),
|
color: getTopColor(msg, id, user.accent_color ?? pastelize(id)),
|
||||||
author: clanData
|
author: user.primary_guild?.identity_guild_id
|
||||||
? {
|
? {
|
||||||
icon_url: CDNEndpoints.CLAN_BADGE(clanData.id, clanData.badge_hash),
|
icon_url: CDNEndpoints.CLAN_BADGE(user.primary_guild.identity_guild_id, user.primary_guild.badge),
|
||||||
name: clanData.tag,
|
name: user.primary_guild.tag,
|
||||||
}
|
|
||||||
: user.clan?.identity_guild_id
|
|
||||||
? {
|
|
||||||
icon_url: CDNEndpoints.CLAN_BADGE(user.clan.identity_guild_id, user.clan.badge),
|
|
||||||
name: user.clan.tag,
|
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
thumbnail: {
|
thumbnail: {
|
||||||
|
@ -393,11 +382,9 @@ userinfo.callback = async function (msg, line) {
|
||||||
} (\`${user.avatar_decoration_data.sku_id}\`)\n[Image](${decorationUrl})`,
|
} (\`${user.avatar_decoration_data.sku_id}\`)\n[Image](${decorationUrl})`,
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
clanData && {
|
primaryGuild?.name && {
|
||||||
name: "Clan",
|
name: "Server Tag",
|
||||||
value: `${clanData.name} (\`${user.clan.identity_guild_id}\`)\n-# :video_game:${
|
value: `${primaryGuild.name} (\`${user.primary_guild.identity_guild_id}\`)`,
|
||||||
ClanPlaystyle[clanData.playstyle] ?? "Unknown"
|
|
||||||
}${clanData.wildcard_descriptors.length > 0 ? ` \u2022 **${clanData.wildcard_descriptors.join(", ")}**` : ""}`,
|
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
vcBadges?.length > 0 && {
|
vcBadges?.length > 0 && {
|
||||||
|
|
|
@ -93,6 +93,45 @@ async function getGuild(id, noLocal = false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getGuildProfile(id, guild = null) {
|
||||||
|
if (guild == null) guild = await getGuild(id);
|
||||||
|
|
||||||
|
let profile = await hf.bot.requestHandler.request("GET", APIEndpoints.CLAN(id), true).catch(() => {});
|
||||||
|
if (!profile) {
|
||||||
|
if (guild?.data?.profile) {
|
||||||
|
profile = guild?.profile;
|
||||||
|
} else {
|
||||||
|
const verif = await hf.bot.requestHandler
|
||||||
|
.request("GET", `${APIEndpoints.GUILD_MEMBER_VERIFICATION(id)}?with_guild=true`, true)
|
||||||
|
.catch(() => {});
|
||||||
|
if (verif?.profile) {
|
||||||
|
profile = verif.profile;
|
||||||
|
} else {
|
||||||
|
let code =
|
||||||
|
guild?.data?.vanityURL ??
|
||||||
|
guild?.data?.store_page?.guild?.invite?.code ??
|
||||||
|
guild?.data?.store_page?.role_subscription?.purchase_page_invite?.code ??
|
||||||
|
guild?.data?.instant_invite?.replace(/(https?:\/\/)?(canary\.|ptb\.)?discord(\.gg|(app)?.com\/invite)\//, "");
|
||||||
|
if (!code && hf.bot.guilds.has(id)) {
|
||||||
|
const invites = await hf.bot.requestHandler
|
||||||
|
.request("GET", APIEndpoints.GUILD_INVITES(id), true)
|
||||||
|
.catch(() => {});
|
||||||
|
if (invites?.[0]?.code) code = invites[0].code;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (code) {
|
||||||
|
const invite = await hf.bot.requestHandler
|
||||||
|
.request("GET", `${APIEndpoints.INVITE(code)}?with_counts=true&with_expiration=true`)
|
||||||
|
.catch(() => {});
|
||||||
|
if (invite?.profile) profile = invite.profile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
async function tryGetGuild(id) {
|
async function tryGetGuild(id) {
|
||||||
const sources = {
|
const sources = {
|
||||||
local: false,
|
local: false,
|
||||||
|
@ -282,6 +321,7 @@ module.exports = {
|
||||||
hastebin,
|
hastebin,
|
||||||
getUploadLimit,
|
getUploadLimit,
|
||||||
getGuild,
|
getGuild,
|
||||||
|
getGuildProfile,
|
||||||
tryGetGuild,
|
tryGetGuild,
|
||||||
enumKeyToName,
|
enumKeyToName,
|
||||||
formatGuildFeatures,
|
formatGuildFeatures,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue