mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-01 21:32:35 +02:00
Discord stats
This commit is contained in:
@@ -2,6 +2,7 @@ const formatter = Intl.NumberFormat('en-US', {
|
|||||||
notation: 'compact',
|
notation: 'compact',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let discordStats: any = null;
|
||||||
export async function getDiscordInfo(): Promise<{
|
export async function getDiscordInfo(): Promise<{
|
||||||
url: string;
|
url: string;
|
||||||
total: number;
|
total: number;
|
||||||
@@ -9,15 +10,32 @@ export async function getDiscordInfo(): Promise<{
|
|||||||
online: number;
|
online: number;
|
||||||
onlineFormatted: string;
|
onlineFormatted: string;
|
||||||
}> {
|
}> {
|
||||||
|
if (discordStats) {
|
||||||
|
return discordStats;
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
'https://discord.com/api/v9/invites/cJpEt5Qbwa?with_counts=true'
|
'https://discord.com/api/v9/invites/cJpEt5Qbwa?with_counts=true',
|
||||||
);
|
);
|
||||||
const json = await response.json();
|
try {
|
||||||
return {
|
const json: any = await response.json();
|
||||||
url: `https://discord.gg/${json.code}`,
|
|
||||||
total: json.approximate_member_count,
|
discordStats = {
|
||||||
totalFormatted: formatter.format(json.approximate_member_count),
|
url: `https://discord.gg/${json.code}`,
|
||||||
online: json.approximate_presence_count,
|
total: json.approximate_member_count,
|
||||||
onlineFormatted: formatter.format(json.approximate_presence_count),
|
totalFormatted: formatter.format(json.approximate_member_count),
|
||||||
};
|
online: json.approximate_presence_count,
|
||||||
|
onlineFormatted: formatter.format(json.approximate_presence_count),
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
discordStats = {
|
||||||
|
url: `https://discord.gg/cJpEt5Qbwa`,
|
||||||
|
total: 17000,
|
||||||
|
totalFormatted: '17k',
|
||||||
|
online: 0,
|
||||||
|
onlineFormatted: formatter.format(0),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return discordStats;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user