diff --git a/Lib/src/lib/restfulmc.ts b/Lib/src/lib/restfulmc.ts index c0030d8..b349492 100644 --- a/Lib/src/lib/restfulmc.ts +++ b/Lib/src/lib/restfulmc.ts @@ -67,7 +67,7 @@ export const isMojangBlocked = (hostname: string): Promise => { return new Promise(async (resolve, reject) => { const response: Response = await fetch( `${ENDPOINT}/server/blocked/${hostname}` - ); // Request the server + ); // Request the server's blocked status const json: any = await response.json(); // Resolve the blocked status @@ -78,3 +78,22 @@ export const isMojangBlocked = (hostname: string): Promise => { } }); }; + +/** + * Get the status of Mojang servers. + * + * @returns the promised status + */ +export const getMojangServerStatus = (): Promise => { + return new Promise(async (resolve, reject) => { + const response: Response = await fetch(`${ENDPOINT}/mojang/status`); // Request the statuses + const json: any = await response.json(); + + // Resolve the blocked status + if (response.ok) { + resolve(json as MojangServerStatus); + } else { + reject(json as ErrorResponse); // The request failed + } + }); +}; diff --git a/Lib/src/types/mojang.d.ts b/Lib/src/types/mojang.d.ts new file mode 100644 index 0000000..a3a1265 --- /dev/null +++ b/Lib/src/types/mojang.d.ts @@ -0,0 +1,7 @@ +/** + * Represents the status of + * a service provided by Mojang. + */ +type MojangServerStatus = { + [key: string]: string; +}; diff --git a/Lib/test/index.test.ts b/Lib/test/index.test.ts index 50085c5..83aff40 100644 --- a/Lib/test/index.test.ts +++ b/Lib/test/index.test.ts @@ -1,5 +1,5 @@ import { describe, it } from "bun:test"; -import { getMinecraftServer, getPlayer } from "../src"; +import { getMinecraftServer, getMojangServerStatus, getPlayer } from "../src"; import { CachedPlayer } from "../src/types/player"; import { BedrockMinecraftServer } from "../src/types/server/bedrock-server"; import { JavaMinecraftServer } from "../src/types/server/java-server"; @@ -21,3 +21,10 @@ describe("server", () => { console.log(server.ip); }); }); + +describe("mojang", () => { + it("status", async () => { + const status: MojangServerStatus = await getMojangServerStatus(); + console.log(status["https://sessionserver.mojang.com"]); + }); +});