mirror of
https://github.com/NohamR/lanyard-profile-readme.git
synced 2026-05-26 04:17:19 +00:00
Merge pull request #59 from hexaaagon/main
feat: add support of clan tag
This commit is contained in:
@@ -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.
|
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___
|
### ___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.
|
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.
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
import axios from "axios";
|
|
||||||
import renderCard from "../../src/renderCard";
|
import renderCard from "../../src/renderCard";
|
||||||
import { isSnowflake } from "../../src/snowflake";
|
import { isSnowflake } from "../../src/snowflake";
|
||||||
import redis from "../../src/redis";
|
import redis from "../../src/redis";
|
||||||
@@ -21,7 +20,7 @@ type Parameters = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse<Data>) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse<Data>) {
|
||||||
let getUser;
|
let getUser: any = {};
|
||||||
|
|
||||||
if (!req.query.id)
|
if (!req.query.id)
|
||||||
return res.send({
|
return res.send({
|
||||||
@@ -37,7 +36,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (error: any) {
|
||||||
if (error.response.data && error.response.data.error.message)
|
if (error.response.data && error.response.data.error.message)
|
||||||
return res
|
return res
|
||||||
|
|||||||
@@ -37,6 +37,14 @@ export interface DiscordUser {
|
|||||||
avatar: string;
|
avatar: string;
|
||||||
global_name: string;
|
global_name: string;
|
||||||
display_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 {
|
export interface Activity {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import escape from "escape-html";
|
|||||||
type Parameters = {
|
type Parameters = {
|
||||||
theme?: string;
|
theme?: string;
|
||||||
bg?: string;
|
bg?: string;
|
||||||
|
clanbg?: string;
|
||||||
animated?: string;
|
animated?: string;
|
||||||
hideDiscrim?: string;
|
hideDiscrim?: string;
|
||||||
hideStatus?: string;
|
hideStatus?: string;
|
||||||
@@ -17,6 +18,7 @@ type Parameters = {
|
|||||||
hideProfile?: string;
|
hideProfile?: string;
|
||||||
hideActivity?: string;
|
hideActivity?: string;
|
||||||
hideSpotify?: string;
|
hideSpotify?: string;
|
||||||
|
hideClan?: string;
|
||||||
ignoreAppId?: string;
|
ignoreAppId?: string;
|
||||||
showDisplayName?: string;
|
showDisplayName?: string;
|
||||||
borderRadius?: string;
|
borderRadius?: string;
|
||||||
@@ -71,12 +73,13 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
|||||||
let hideProfile = parseBool(params.hideProfile);
|
let hideProfile = parseBool(params.hideProfile);
|
||||||
let hideActivity = params.hideActivity ?? "false";
|
let hideActivity = params.hideActivity ?? "false";
|
||||||
let hideSpotify = parseBool(params.hideSpotify);
|
let hideSpotify = parseBool(params.hideSpotify);
|
||||||
|
let hideClan = parseBool(params.hideClan);
|
||||||
let ignoreAppId = parseAppId(params.ignoreAppId);
|
let ignoreAppId = parseAppId(params.ignoreAppId);
|
||||||
let hideDiscrim = parseBool(params.hideDiscrim);
|
let hideDiscrim = parseBool(params.hideDiscrim);
|
||||||
let showDisplayName = parseBool(params.showDisplayName);
|
let showDisplayName = parseBool(params.showDisplayName);
|
||||||
|
|
||||||
|
|
||||||
if (parseBool(params.hideDiscrim) || body.data.discord_user.discriminator === "0") hideDiscrim = true;
|
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.activities[0]?.emoji?.animated) statusExtension = "gif";
|
||||||
if (data.discord_user.avatar && data.discord_user.avatar.startsWith("a_")) avatarExtension = "gif";
|
if (data.discord_user.avatar && data.discord_user.avatar.startsWith("a_")) avatarExtension = "gif";
|
||||||
if (params.animated === "false") avatarExtension = "webp";
|
if (params.animated === "false") avatarExtension = "webp";
|
||||||
@@ -85,6 +88,8 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
|||||||
theme = "light";
|
theme = "light";
|
||||||
}
|
}
|
||||||
if (params.bg) backgroundColor = params.bg;
|
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.idleMessage) idleMessage = params.idleMessage;
|
||||||
if (params.borderRadius) borderRadius = params.borderRadius;
|
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) {
|
switch (data.discord_status) {
|
||||||
case "online":
|
case "online":
|
||||||
avatarBorderColor = "#43B581";
|
avatarBorderColor = "#43B581";
|
||||||
@@ -230,6 +242,26 @@ const renderCard = async (body: LanyardTypes.Root, params: Parameters): Promise<
|
|||||||
}
|
}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
|
${hideClan ? "" : `
|
||||||
|
<span style="
|
||||||
|
background-color: ${clanBackgroundColor};
|
||||||
|
border-radius: 0.375rem;
|
||||||
|
padding-left: 0.5rem;
|
||||||
|
padding-right: 0.5rem;
|
||||||
|
margin-left: -6px;
|
||||||
|
margin-right: 12px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.25rem;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
height: 100%;
|
||||||
|
">
|
||||||
|
<img src="data:image/png;base64,${clanBadge!}" />
|
||||||
|
<p style="margin-bottom: 1.1rem">${escape(data.discord_user.clan!.tag)}</p>
|
||||||
|
</span>
|
||||||
|
`}
|
||||||
|
|
||||||
${hideBadges ? "" : flags.map(v => `
|
${hideBadges ? "" : flags.map(v => `
|
||||||
<img src="data:image/png;base64,${Badges[v]}" style="
|
<img src="data:image/png;base64,${Badges[v]}" style="
|
||||||
width: auto;
|
width: auto;
|
||||||
|
|||||||
Reference in New Issue
Block a user