all repos — stealth-developers @ 2b8e1cb8074eaf0e6088ab69e8de711b416bb7ef

src/utils/roblox.ts (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
import config from "@/config";
import type {
	BLApiResponse,
	GetUserResponse,
	ThumbnailResponse,
} from "@/types/roblox";

export async function getRobloxUser(userId: string): Promise<{
	user: GetUserResponse;
	thumbnail: ThumbnailResponse;
}> {
	if (!config.data.roblox) throw new Error("roblox API key is not configured");

	const getUserUrl = `https://apis.roblox.com/cloud/v2/users/${userId}`;
	const getThumbnailUrl = `https://apis.roblox.com/cloud/v2/users/${userId}:generateThumbnail`;
	const [userRes, thumbnailRes] = await Promise.all([
		fetch(getUserUrl, {
			headers: {
				"Content-Type": "application/json",
				"x-api-key": config.data.roblox.apiKey,
			},
		}),
		fetch(getThumbnailUrl, {
			headers: {
				"Content-Type": "application/json",
				"x-api-key": config.data.roblox.apiKey,
			},
		}),
	]);

	const [userData, thumbnailData] = await Promise.all([
		userRes.json(),
		thumbnailRes.json(),
	]);

	return { user: userData, thumbnail: thumbnailData };
}

export async function getConnectedRobloxUser(
	discordId: string,
): Promise<BLApiResponse> {
	if (!config.data.bloxlink)
		throw new Error("bloxlink token is not configured");

	const response = await fetch(
		`https://api.blox.link/v4/public/discord-to-roblox/${discordId}`,
		{
			headers: {
				Authorization: config.data.bloxlink.token,
			},
		},
	);

	return await response.json();
}