RESTfulMC/Lib/src/lib/restfulmc.ts

53 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-04-14 16:38:41 -04:00
import { MojangServerStatus } from "../types/mojang";
import type { CachedPlayer } from "../types/player";
import { Platform } from "../types/server";
import { CachedBedrockMinecraftServer } from "../types/server/bedrock-server";
import { CachedJavaMinecraftServer } from "../types/server/java-server";
2024-04-14 16:29:29 -04:00
import { makeWebRequest } from "./webRequest";
2024-04-14 14:03:02 -04:00
2024-04-14 13:34:34 -04:00
/**
* Get a player by their username or UUID.
*
* @param query the query to search for the player by
* @returns the promised player
*/
2024-04-14 16:29:29 -04:00
export const getPlayer = (query: string): Promise<CachedPlayer> =>
makeWebRequest<CachedPlayer>(`/player/${query}`);
/**
* Get a Minecraft server by its platform and hostname.
*
* @param platform the platform of the server
* @param hostname the hostname of the server
* @returns the promised server
*/
export const getMinecraftServer = (
platform: Platform,
hostname: string
2024-04-14 16:29:29 -04:00
): Promise<CachedJavaMinecraftServer | CachedBedrockMinecraftServer> =>
platform === "java"
? makeWebRequest<CachedJavaMinecraftServer>(
`/server/${platform}/${hostname}`
)
: makeWebRequest<CachedBedrockMinecraftServer>(
`/server/${platform}/${hostname}`
);
2024-04-14 15:56:45 -04:00
/**
* Check if the server with the
* given hostname is blocked by Mojang.
*
* @param hostname the server hostname to check
* @returns the promised blocked status
*/
2024-04-14 16:29:29 -04:00
export const isMojangBlocked = (hostname: string): Promise<boolean> =>
makeWebRequest<boolean>(`/server/blocked/${hostname}`);
2024-04-14 16:06:42 -04:00
/**
* Get the status of Mojang servers.
*
* @returns the promised status
*/
2024-04-14 16:29:29 -04:00
export const getMojangServerStatus = (): Promise<MojangServerStatus> =>
makeWebRequest<MojangServerStatus>("/mojang/status");