diff --git a/src/OAPI.ts b/src/OAPI.ts index 93aca4a..f72c177 100644 --- a/src/OAPI.ts +++ b/src/OAPI.ts @@ -1,12 +1,10 @@ import type { - RawTown, - RawNation, - RawResident, - OAPITown, - OAPIResident, - OAPINation, - RawServerInfoV2, - RawServerInfoV3 + RawTown, RawNation, RawResident, + OAPITown, OAPIResident, OAPINation, + RawServerInfoV2, RawServerInfoV3, + RawQuarterResponseV3, RawEntityV3, + DiscordReqObject, DiscordResObject, + RawLocationResponseV3 } from './types/index.js' import { townyData } from './utils/endpoint.js' @@ -92,33 +90,24 @@ const parseNation = (nation: RawNation) => { const ParamErr = () => new SyntaxError(`Parameter 'name' is invalid. Must be of type string!`) const FetchErr = (type: string, name: string) => new FetchError(`Could not fetch ${type} '${name}'. Invalid response received!`) -interface DiscordReqObject { - type: 'minecraft' | 'discord' - target: string -} - -interface DiscordResObject { - ID: string - UUID: string -} - export class OAPIV3 { - static serverInfo = async (): Promise => await townyData('', 'v3') + static serverInfo = (): Promise => townyData('', 'v3') + + static location = (...objs: [number, number][]): Promise => + townyData('location', 'v3', { query: objs }) - static discord = async (...objs: DiscordReqObject[]): Promise => - await townyData('/discord', 'v3', { query: objs }) + static discord = (...objs: DiscordReqObject[]): Promise => + townyData('/discord', 'v3', { query: objs }) - static playerList = async (): Promise<{ name: string, uuid: string }[]> => - await townyData('/players', 'v3') + static quarters = (...ids: string[]): Promise => townyData('/quarters', 'v3', { query: ids }) + static quarterList = (): Promise => townyData('/quarters', 'v3') - static players = async (...ids: string[]): Promise => - await townyData('/players', 'v3', { query: ids }) + static players = (...ids: string[]): Promise => townyData('/players', 'v3', { query: ids }) + static playerList = (): Promise => townyData('/players', 'v3') } export class OAPIV2 { - static serverInfo = async (): Promise => { - return townyData('', 'v2') - } + static serverInfo = (): Promise => townyData('', 'v2') static resident = async (name: string) => { if (!name) throw ParamErr() diff --git a/src/types/oapi.ts b/src/types/oapi.ts index 9c8f856..7234a16 100644 --- a/src/types/oapi.ts +++ b/src/types/oapi.ts @@ -1,7 +1,8 @@ import type { Location, NestedOmit, - Prettify + Prettify, + StrictPoint2D } from '../types/index.js' //#region V2 @@ -36,8 +37,6 @@ export type OAPIResident = NestedOmit & { - name: string - uuid: string title?: string surname?: string town?: string @@ -199,6 +198,11 @@ export interface RawServerInfoV2 { //#endregion //#region V3 +export interface RawEntityV3 { + name: string + uuid: string +} + export interface RawServerInfoV3 { version: string moonPhase: string @@ -228,4 +232,45 @@ export interface RawServerInfoV3 { numRemaining: number } } + +export interface RawQuarterResponseV3 { + uuid: string + type: "APARTMENT" | "COMMONS" | "PUBLIC" | "SHOP" | "STATION" | "WORKSITE" + owner: Partial + town: RawEntityV3 + timestamps: { + registered: number + claimedAt?: number + } + status: { + isEmbassy: boolean + } + stats: { + price?: number + volume: number + numCuboids: number + } + color: [number, number, number] + trusted: RawEntityV3[] + cuboids: { + [key: string]: [number, number, number] + }[] +} + +export interface DiscordReqObject { + type: 'minecraft' | 'discord' + target: string +} + +export interface DiscordResObject { + ID: string + UUID: string +} + +export interface RawLocationResponseV3 { + isWilderness: boolean + location: Partial + town?: RawEntityV3 + nation?: RawEntityV3 +} //#endregion \ No newline at end of file