diff --git a/src/api/squaremap/parser.ts b/src/api/squaremap/parser.ts index cf178bd..549e2af 100644 --- a/src/api/squaremap/parser.ts +++ b/src/api/squaremap/parser.ts @@ -136,9 +136,14 @@ interface TownCoords { const isCapital = (marker: SquaremapArea) => { const desc = striptags(marker.tooltip.replaceAll('\n', '')).trim() - const bracketMatch = desc.match(/\((.*)\)/) + // Remove everything up to first space, then get everything inside first set of brackets. + const bracketMatch = desc.replace(/^[^\s]*\s*/, '').match(/\(([^()]+)\)/) + + // Given this example: ((Africa)) (Capital of Cuba) Some description (test) + // The following should become "Capital of Cuba" const tooltipBracketContent = bracketMatch ? bracketMatch[1].trim() : null + return tooltipBracketContent?.startsWith("Capital of") ?? false } diff --git a/src/types/oapi.ts b/src/types/oapi.ts index 0790da0..32e4083 100644 --- a/src/types/oapi.ts +++ b/src/types/oapi.ts @@ -263,8 +263,8 @@ export interface DiscordReqObject { } export interface DiscordResObject { - ID: string - UUID: string + id: string + uuid: string } export interface RawLocationResponseV3 { diff --git a/tests/oapi.test.ts b/tests/oapi.test.ts index a9adf14..28edf7f 100644 --- a/tests/oapi.test.ts +++ b/tests/oapi.test.ts @@ -25,6 +25,21 @@ describe('[v3] OfficialAPI', async () => { expect(info.stats.numNations).toBeGreaterThanOrEqual(100) }, 10000) + it('can get UUID from Discord ID', async () => { + const res = await OfficialAPI.V3.discord({ + type: "minecraft", + target: "263377802647175170" // My discord ID + }) + + console.log(res) + + expect(res).toBeDefined() + assertType<{ id: string, uuid: string }[]>(res) + + expect(res.length).toBe(1) + expect(res[0].uuid).toBe("d0a2565a-ad93-48d2-8310-81d06e198e53") + }) + it('can get player list', async () => { const playerList = await OfficialAPI.V3.playerList() diff --git a/tests/squaremap/nations.test.ts b/tests/squaremap/nations.test.ts index 62f26c3..b85dd0c 100644 --- a/tests/squaremap/nations.test.ts +++ b/tests/squaremap/nations.test.ts @@ -30,10 +30,10 @@ describe('[Squaremap/Aurora] Nations', () => { }) it('can get multiple nations', async () => { - const nations = await Aurora.Nations.get('SiBeRia', 'veNICE', 'verMOnt') as SquaremapNation[] + const nations = await Aurora.Nations.get('veNICE', 'vERMont') as SquaremapNation[] expect(nations).toBeTruthy() - expect(nations.length).toBe(3) + expect(nations.length).toBe(2) expect(nations.some(n => n instanceof NotFoundError)).toBe(false) assertType(nations) diff --git a/tests/squaremap/residents.test.ts b/tests/squaremap/residents.test.ts index 43c3bd8..d97c844 100644 --- a/tests/squaremap/residents.test.ts +++ b/tests/squaremap/residents.test.ts @@ -29,7 +29,7 @@ describe('[Squaremap/Aurora] Residents', () => { expect(res.name).toBe("3meraldK") expect(res.rank).toBe("Mayor") - expect(res.town).toBe("Krn") + expect(res.nation).toBe("Venice") //console.log(res) }) diff --git a/tests/squaremap/towns.test.ts b/tests/squaremap/towns.test.ts index 07c11cc..468c6d4 100644 --- a/tests/squaremap/towns.test.ts +++ b/tests/squaremap/towns.test.ts @@ -31,11 +31,11 @@ describe('[Squaremap/Aurora] Towns', () => { }) it('can get multiple towns', async () => { - const towns = await Aurora.Towns.get('veNICE', 'troSt_(KhaRkiv)', 'HuaNGyan_IsLANd') as SquaremapTown[] + const towns = await Aurora.Towns.get('tORinO', 'LonDoN') as SquaremapTown[] expect(towns).toBeTruthy() expect(towns.some(n => n instanceof NotFoundError)).toBe(false) - expect(towns.length).toBe(3) + expect(towns.length).toBe(2) //console.log(towns) diff --git a/vitest.config.ts b/vitest.config.ts index ff97680..b764015 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -16,6 +16,7 @@ export default defineConfig({ maxForks: 6 // 6 threads is enough } }, + include: ['tests/squaremap/**/*', 'tests/*'], typecheck: { include: ['**/*.{test,spec}.?(c|m)[jt]s?(x)'] },