Player embed colors
All checks were successful
Deploy Frontend / docker (17, 3.8.5) (push) Successful in 1m5s
All checks were successful
Deploy Frontend / docker (17, 3.8.5) (push) Successful in 1m5s
This commit is contained in:
parent
bc769651c3
commit
b26718df8b
@ -70,9 +70,26 @@ const PlayerPage = async ({ params }: PageProps): Promise<ReactElement> => {
|
|||||||
export const generateMetadata = async ({
|
export const generateMetadata = async ({
|
||||||
params,
|
params,
|
||||||
}: PageProps): Promise<Metadata> => {
|
}: PageProps): Promise<Metadata> => {
|
||||||
const embed: Metadata | undefined = await getPlayerEmbed(
|
const query: string | undefined = trimQuery(params.slug?.[0]);
|
||||||
trimQuery(params.slug?.[0])
|
let embed: Metadata | undefined;
|
||||||
); // Get the page embed
|
if (query) {
|
||||||
|
try {
|
||||||
|
embed = await getPlayerEmbed(query); // Get the player embed
|
||||||
|
} catch (err) {
|
||||||
|
const code: number = (err as RestfulMCAPIError).code; // Get the error status code
|
||||||
|
if (code === 400) {
|
||||||
|
return Embed({
|
||||||
|
title: "Invalid Player",
|
||||||
|
description: `The player ${query} is invalid.`,
|
||||||
|
});
|
||||||
|
} else if (code === 404) {
|
||||||
|
return Embed({
|
||||||
|
title: "Player Not Found",
|
||||||
|
description: `The player ${query} was not found.`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Return the page embed
|
// Return the page embed
|
||||||
return embed
|
return embed
|
||||||
@ -92,10 +109,16 @@ export const generateMetadata = async ({
|
|||||||
export const generateViewport = async ({
|
export const generateViewport = async ({
|
||||||
params,
|
params,
|
||||||
}: PageProps): Promise<Viewport> => {
|
}: PageProps): Promise<Viewport> => {
|
||||||
const embed: Metadata | undefined = await getPlayerEmbed(
|
const query: string | undefined = trimQuery(params.slug?.[0]);
|
||||||
trimQuery(params.slug?.[0])
|
if (query) {
|
||||||
); // Get the page embed
|
try {
|
||||||
return embed ? {} : { themeColor: "#AA0000" };
|
await getPlayerEmbed(query); // Try and get the player embed
|
||||||
|
return { themeColor: "#55FF55" }; // Online
|
||||||
|
} catch (err) {
|
||||||
|
return { themeColor: "#AA0000" }; // Error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -124,27 +147,12 @@ const getPlayerEmbed = async (
|
|||||||
if (!query) {
|
if (!query) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
const player: CachedPlayer = await getPlayer(query); // Get the player to embed
|
const player: CachedPlayer = await getPlayer(query); // Get the player to embed
|
||||||
return Embed({
|
return Embed({
|
||||||
title: `${player.username}'s Profile`,
|
title: `${player.username}'s Profile`,
|
||||||
description: `UUID: ${player.uniqueId}\n\nClick to view data about this player.`,
|
description: `UUID: ${player.uniqueId}\n\nClick to view data about this player.`,
|
||||||
thumbnail: player.skin.parts.HEAD,
|
thumbnail: player.skin.parts.HEAD,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
|
||||||
const code: number = (err as RestfulMCAPIError).code; // Get the error status code
|
|
||||||
if (code === 400) {
|
|
||||||
return Embed({
|
|
||||||
title: "Invalid Player",
|
|
||||||
description: `The player ${query} is invalid.`,
|
|
||||||
});
|
|
||||||
} else if (code === 404) {
|
|
||||||
return Embed({
|
|
||||||
title: "Player Not Found",
|
|
||||||
description: `The player ${query} was not found.`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default PlayerPage;
|
export default PlayerPage;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user