userinfo: redesign a bit based off of cv2 prototype
This commit is contained in:
		
							parent
							
								
									94968141ff
								
							
						
					
					
						commit
						e9b8b114ef
					
				
					 1 changed files with 69 additions and 51 deletions
				
			
		| 
						 | 
				
			
			@ -299,9 +299,19 @@ userinfo.callback = async function (msg, line) {
 | 
			
		|||
    images.push(bannerUrl);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  let decoration;
 | 
			
		||||
  if (user.avatar_decoration_data) {
 | 
			
		||||
    decoration = await hf.bot.requestHandler
 | 
			
		||||
      .request("GET", APIEndpoints.STORE_PUBLISHED_LISTING(user.avatar_decoration_data.sku_id), true)
 | 
			
		||||
      .catch(() => {});
 | 
			
		||||
    const decorationUrl = CDNEndpoints.AVATAR_DECORATION(user.avatar_decoration_data.asset);
 | 
			
		||||
    images.push(`[Avatar Decoration](${decorationUrl})`);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  //const guildImages = [];
 | 
			
		||||
  const guildAvatar = member?.avatar && CDNEndpoints.GUILD_MEMBER_AVATAR(msg.guildID, id, member.avatar);
 | 
			
		||||
  let guildBanner;
 | 
			
		||||
  if (member) {
 | 
			
		||||
    const guildAvatar = member.avatar && CDNEndpoints.GUILD_MEMBER_AVATAR(msg.guildID, id, member.avatar);
 | 
			
		||||
    if (guildAvatar) {
 | 
			
		||||
      //const avatarRes = await fetch(guildAvatar, {method: "HEAD"});
 | 
			
		||||
      //const avatarMod = avatarRes.headers.get("last-modified");
 | 
			
		||||
| 
						 | 
				
			
			@ -314,7 +324,7 @@ userinfo.callback = async function (msg, line) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    const memberObj = await hf.bot.requestHandler.request("GET", APIEndpoints.GUILD_MEMBER(msg.guildID, id), true);
 | 
			
		||||
    const guildBanner = memberObj.banner && CDNEndpoints.GUILD_MEMBER_BANNER(msg.guildID, id, memberObj.banner);
 | 
			
		||||
    guildBanner = memberObj.banner && CDNEndpoints.GUILD_MEMBER_BANNER(msg.guildID, id, memberObj.banner);
 | 
			
		||||
    if (guildBanner) {
 | 
			
		||||
      //const bannerRes = await fetch(guildBanner, {method: "HEAD"});
 | 
			
		||||
      //const bannerMod = bannerRes.headers.get("last-modified");
 | 
			
		||||
| 
						 | 
				
			
			@ -327,66 +337,78 @@ userinfo.callback = async function (msg, line) {
 | 
			
		|||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  let decoration, decorationUrl;
 | 
			
		||||
  if (user.avatar_decoration_data) {
 | 
			
		||||
    decoration = await hf.bot.requestHandler
 | 
			
		||||
      .request("GET", APIEndpoints.STORE_PUBLISHED_LISTING(user.avatar_decoration_data.sku_id), true)
 | 
			
		||||
      .catch(() => {});
 | 
			
		||||
    decorationUrl = CDNEndpoints.AVATAR_DECORATION(user.avatar_decoration_data.asset);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const shared = Array.from(hf.bot.guilds.values()).filter((g) => g.members.get(id) != null);
 | 
			
		||||
 | 
			
		||||
  const descLines = [`<@${id}>`];
 | 
			
		||||
  const descLines = [`# ${user.global_name ?? user.username} ${user.bot ? Icons.boat.replace(":i:", ":Bot:") : ""}`];
 | 
			
		||||
  let subline = `${formatUsername(user).replace("@", "")} \u2022 <@${id}>`;
 | 
			
		||||
  if (badges.length > 0) {
 | 
			
		||||
    descLines.push(badges.join(""));
 | 
			
		||||
    subline += "\u2007" + badges.join("");
 | 
			
		||||
  }
 | 
			
		||||
  if (botDeleted) {
 | 
			
		||||
    descLines.push("*This bot's application has been deleted*\n-# (or app ID and user ID desync)");
 | 
			
		||||
  }
 | 
			
		||||
  if (user.system) {
 | 
			
		||||
    descLines.push("**System account**");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  let primaryGuild;
 | 
			
		||||
  if (user.primary_guild?.identity_guild_id) primaryGuild = await getGuild(user.primary_guild.identity_guild_id);
 | 
			
		||||
  const activityLines = [];
 | 
			
		||||
 | 
			
		||||
  if (anyMember) {
 | 
			
		||||
    const icons = [];
 | 
			
		||||
    if (anyMember.clientStatus) {
 | 
			
		||||
      for (const platform of Object.keys(anyMember.clientStatus)) {
 | 
			
		||||
        const status = anyMember.clientStatus[platform];
 | 
			
		||||
        if (status == "offline") continue;
 | 
			
		||||
        if (status === "offline") continue;
 | 
			
		||||
 | 
			
		||||
        icons.push(Icons.presence[platform][status]);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    descLines.push("");
 | 
			
		||||
    if (icons.length > 0) {
 | 
			
		||||
      descLines.push(icons.join(""));
 | 
			
		||||
    } else {
 | 
			
		||||
      descLines.push(Icons.offline.replace(":i:", ":Offline:"));
 | 
			
		||||
      subline += "\u2007" + icons.join("");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (anyMember.activities?.length > 0) {
 | 
			
		||||
      for (const activity of anyMember.activities) {
 | 
			
		||||
        if (activity.type == 4 || activity.type == 6) {
 | 
			
		||||
          descLines.push(ActivityTypeNames[activity.type]);
 | 
			
		||||
          activityLines.push(ActivityTypeNames[activity.type]);
 | 
			
		||||
        } else {
 | 
			
		||||
          descLines.push(
 | 
			
		||||
          let name = activity.name;
 | 
			
		||||
          if (activity.status_display_type === 1 && activity.state) {
 | 
			
		||||
            name = activity.state;
 | 
			
		||||
            if (activity.state_url) name = `[${name}](${activity.state_url})`;
 | 
			
		||||
          } else if (activity.status_display_type === 2 && activity.details) {
 | 
			
		||||
            name = activity.details;
 | 
			
		||||
            if (activity.details_url) name = `[${name}](${activity.details_url})`;
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          activityLines.push(
 | 
			
		||||
            `${activity.name === "Spotify" ? Icons.spotify : ActivityTypeIcons[activity.type] ?? ""} ${
 | 
			
		||||
              ActivityTypeNames[activity.type]
 | 
			
		||||
            } **${
 | 
			
		||||
              activity.name === "Spotify"
 | 
			
		||||
                ? `[${activity.state.replaceAll("; ", ", ")}](https://open.spotify.com/track/${activity.sync_id})`
 | 
			
		||||
                : activity.name
 | 
			
		||||
                : name
 | 
			
		||||
            }**`.trim()
 | 
			
		||||
          );
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  descLines.push(subline);
 | 
			
		||||
  if (shared.length > 0) {
 | 
			
		||||
    descLines.push(`-# ${shared.length} Bot Mutual Server${shared.length > 1 ? "s" : ""}`);
 | 
			
		||||
  } else {
 | 
			
		||||
    descLines.push("");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (botDeleted) {
 | 
			
		||||
    descLines.push("*This bot's application has been deleted*\n-# (or app ID and user ID desync)");
 | 
			
		||||
  }
 | 
			
		||||
  if (user.system) {
 | 
			
		||||
    descLines.push("**System account**");
 | 
			
		||||
  }
 | 
			
		||||
  descLines.push("");
 | 
			
		||||
 | 
			
		||||
  if (activityLines.length > 0) {
 | 
			
		||||
    descLines.push(...activityLines);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  let primaryGuild;
 | 
			
		||||
  if (user.primary_guild?.identity_guild_id) primaryGuild = await getGuild(user.primary_guild.identity_guild_id);
 | 
			
		||||
 | 
			
		||||
  const vcBadges = vencordBadges.has(id) && vencordBadges.get(id);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -399,24 +421,15 @@ userinfo.callback = async function (msg, line) {
 | 
			
		|||
        }
 | 
			
		||||
      : null,
 | 
			
		||||
    thumbnail: {
 | 
			
		||||
      url: avatar,
 | 
			
		||||
      url: guildAvatar || avatar,
 | 
			
		||||
    },
 | 
			
		||||
    image: {
 | 
			
		||||
      url: banner,
 | 
			
		||||
    },
 | 
			
		||||
    title: `${user.global_name ?? user.username} (${formatUsername(user)}) ${
 | 
			
		||||
      user.bot ? Icons.boat.replace(":i:", ":Bot:") : ""
 | 
			
		||||
    }`,
 | 
			
		||||
    description: descLines.join("\n"),
 | 
			
		||||
    fields: [
 | 
			
		||||
      {
 | 
			
		||||
        name: "Created",
 | 
			
		||||
        value: `<t:${Math.floor(snowflakeToTimestamp(id) / 1000)}:R>`,
 | 
			
		||||
        inline: true,
 | 
			
		||||
      },
 | 
			
		||||
      member && {
 | 
			
		||||
        name: "Joined",
 | 
			
		||||
        value: `<t:${Math.floor(member.joinedAt / 1000)}:R>`,
 | 
			
		||||
        name: "Member Since",
 | 
			
		||||
        value: `<t:${Math.floor(snowflakeToTimestamp(id) / 1000)}:D>${
 | 
			
		||||
          member ? ` \u2022 <t:${Math.floor(member.joinedAt / 1000)}:D>` : ""
 | 
			
		||||
        }`,
 | 
			
		||||
        inline: true,
 | 
			
		||||
      },
 | 
			
		||||
      member?.nick && {
 | 
			
		||||
| 
						 | 
				
			
			@ -430,7 +443,7 @@ userinfo.callback = async function (msg, line) {
 | 
			
		|||
          decoration?.sku
 | 
			
		||||
            ? `[${decoration?.sku?.name}](https://discord.com/shop#itemSkuId=${user.avatar_decoration_data.sku_id})`
 | 
			
		||||
            : questDecorationName ?? "*Unknown*"
 | 
			
		||||
        }\n-# ${user.avatar_decoration_data.sku_id}\n[Image](${decorationUrl})`,
 | 
			
		||||
        }\n-# ${user.avatar_decoration_data.sku_id}`,
 | 
			
		||||
        inline: true,
 | 
			
		||||
      },
 | 
			
		||||
      user.primary_guild?.identity_guild_id && {
 | 
			
		||||
| 
						 | 
				
			
			@ -448,12 +461,7 @@ userinfo.callback = async function (msg, line) {
 | 
			
		|||
        value: member.roles
 | 
			
		||||
          .sort((a, b) => guild.roles.get(b).position - guild.roles.get(a).position)
 | 
			
		||||
          .map((role) => `<@&${role}>`)
 | 
			
		||||
          .join(" "),
 | 
			
		||||
        inline: false,
 | 
			
		||||
      },
 | 
			
		||||
      shared.length > 0 && {
 | 
			
		||||
        name: "Bot Mutual Servers",
 | 
			
		||||
        value: `${shared.length} servers`,
 | 
			
		||||
          .join("\u2007"),
 | 
			
		||||
        inline: false,
 | 
			
		||||
      },
 | 
			
		||||
      images.length > 0 && {
 | 
			
		||||
| 
						 | 
				
			
			@ -467,7 +475,17 @@ userinfo.callback = async function (msg, line) {
 | 
			
		|||
    },
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  return {embeds: [embed]};
 | 
			
		||||
  return {
 | 
			
		||||
    embeds: [
 | 
			
		||||
      banner && {
 | 
			
		||||
        color: embed.color,
 | 
			
		||||
        image: {
 | 
			
		||||
          url: guildBanner || banner,
 | 
			
		||||
        },
 | 
			
		||||
      },
 | 
			
		||||
      embed,
 | 
			
		||||
    ].filter((x) => !!x),
 | 
			
		||||
  };
 | 
			
		||||
};
 | 
			
		||||
hf.registerCommand(userinfo);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue