diff --git a/README.md b/README.md index 31c079a..7368182 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,10 @@ If you don't want people seeing your status, append the query param `hideStatus= If you don't want people seeing the elapsed time on an activity, append the query param `hideTimestamp=true` to the end of the URL. Elapsed time is shown by default. +### ___Hide Clan Tag___ + +If you don't want people seeing your Clan Tag (formerly known as Guilds), append the query param `hideClan=true` to the end of the URL. Clan Tag is shown by default. + ### ___Hide Badges___ If you don't want people seeing the badges you have on Discord, append the query param `hideBadges=true` to the end of the URL. Badges are shown by default. diff --git a/pages/api/[...id].ts b/pages/api/[...id].ts index 4810697..928c003 100644 --- a/pages/api/[...id].ts +++ b/pages/api/[...id].ts @@ -1,5 +1,4 @@ import type { NextApiRequest, NextApiResponse } from "next"; -import axios from "axios"; import renderCard from "../../src/renderCard"; import { isSnowflake } from "../../src/snowflake"; import redis from "../../src/redis"; @@ -21,7 +20,7 @@ type Parameters = { }; export default async function handler(req: NextApiRequest, res: NextApiResponse) { - let getUser; + let getUser: any = {}; if (!req.query.id) return res.send({ @@ -37,7 +36,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< }); try { - getUser = await axios(`https://api.lanyard.rest/v1/users/${userId}`); + getUser.data = await fetch(`https://api.lanyard.rest/v1/users/${userId}`).then(res => res.json()); } catch (error: any) { if (error.response.data && error.response.data.error.message) return res diff --git a/src/LanyardTypes.ts b/src/LanyardTypes.ts index ae96cb3..d09ef5c 100644 --- a/src/LanyardTypes.ts +++ b/src/LanyardTypes.ts @@ -37,6 +37,14 @@ export interface DiscordUser { avatar: string; global_name: string; display_name: string; + clan: ClanTag | null; +} + +export interface ClanTag { + tag: string; + badge: string; + identity_enabled: boolean; + identity_guild_id: number; } export interface Activity { diff --git a/src/renderCard.tsx b/src/renderCard.tsx index a8c1480..fdc5677 100644 --- a/src/renderCard.tsx +++ b/src/renderCard.tsx @@ -9,6 +9,7 @@ import escape from "escape-html"; type Parameters = { theme?: string; bg?: string; + clanbg?: string; animated?: string; hideDiscrim?: string; hideStatus?: string; @@ -17,6 +18,7 @@ type Parameters = { hideProfile?: string; hideActivity?: string; hideSpotify?: string; + hideClan?: string; ignoreAppId?: string; showDisplayName?: string; borderRadius?: string; @@ -71,12 +73,13 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise< let hideProfile = parseBool(params.hideProfile); let hideActivity = params.hideActivity ?? "false"; let hideSpotify = parseBool(params.hideSpotify); + let hideClan = parseBool(params.hideClan); let ignoreAppId = parseAppId(params.ignoreAppId); let hideDiscrim = parseBool(params.hideDiscrim); let showDisplayName = parseBool(params.showDisplayName); - if (parseBool(params.hideDiscrim) || body.data.discord_user.discriminator === "0") hideDiscrim = true; + if (!body.data.discord_user.clan) hideClan = true; if (data.activities[0]?.emoji?.animated) statusExtension = "gif"; if (data.discord_user.avatar && data.discord_user.avatar.startsWith("a_")) avatarExtension = "gif"; if (params.animated === "false") avatarExtension = "webp"; @@ -85,6 +88,8 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise< theme = "light"; } if (params.bg) backgroundColor = params.bg; + let clanBackgroundColor: string = theme === "light" ? "#e0dede" : "#111214"; + if (params.clanbg) clanBackgroundColor = params.clanbg; if (params.idleMessage) idleMessage = params.idleMessage; if (params.borderRadius) borderRadius = params.borderRadius; @@ -103,6 +108,13 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise< ); } + let clanBadge: string; + if (data.discord_user.clan) { + clanBadge = await encodeBase64( + `https://cdn.discordapp.com/clan-badges/${data.discord_user.clan.identity_guild_id}/${data.discord_user.clan.badge}.png?size=16` + ); + } + switch (data.discord_status) { case "online": avatarBorderColor = "#43B581"; @@ -230,6 +242,26 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise< } + ${hideClan ? "" : ` + + +

${escape(data.discord_user.clan!.tag)}

+
+ `} + ${hideBadges ? "" : flags.map(v => `