Updated hypixel api wrapper
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
// dprint-ignore-file
|
// dprint-ignore-file
|
||||||
export interface IGuild {
|
export interface IGuild {
|
||||||
data: {
|
|
||||||
success: boolean
|
success: boolean
|
||||||
guild: IGuildData
|
guild: IGuildData
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGuildData {
|
export interface IGuildData {
|
||||||
_id: string
|
_id: string
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
// dprint-ignore-file
|
// dprint-ignore-file
|
||||||
export interface IPlayer {
|
export interface IPlayer {
|
||||||
data: {
|
|
||||||
success: boolean
|
success: boolean
|
||||||
player: IPlayerData
|
player: IPlayerData
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export interface IPlayerData {
|
export interface IPlayerData {
|
||||||
_id?: string
|
_id?: string
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import fetch from "axios"
|
import axios from "axios"
|
||||||
import { IPlayer, IPlayerData } from "~/interfaces"
|
import { IPlayer, IPlayerData } from "~/interfaces"
|
||||||
import { IGuild, IGuildData } from "~/interfaces"
|
import { IGuild, IGuildData } from "~/interfaces"
|
||||||
import env from "~/utils/Env.js"
|
import env from "~/utils/Env.js"
|
||||||
@@ -10,25 +10,21 @@ const guild = "https://api.hypixel.net/guild"
|
|||||||
const minotar = "https://minotar.net/helm/"
|
const minotar = "https://minotar.net/helm/"
|
||||||
type GuildQueryType = "player" | "name" | "id"
|
type GuildQueryType = "player" | "name" | "id"
|
||||||
|
|
||||||
type Profile = {
|
type UUIDData = {
|
||||||
data: {
|
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
type Profile2 = {
|
type IGNData = {
|
||||||
data: {
|
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
properties: { name: string, value: string }[]
|
properties: { name: string, value: string }[]
|
||||||
profileActions: []
|
profileActions: []
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async function getUUID(ign: string): Promise<string | null> {
|
async function getUUID(ign: string): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
const req: Profile = await fetch(mojang + ign)
|
const req = await axios.get<UUIDData>(mojang + ign)
|
||||||
return req.data.id
|
return req.data.id
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -38,7 +34,7 @@ async function getUUID(ign: string): Promise<string | null> {
|
|||||||
|
|
||||||
async function getIGN(uuid: string): Promise<string | null> {
|
async function getIGN(uuid: string): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
const req: Profile2 = await fetch(mojanguuid + uuid)
|
const req = await axios.get<IGNData>(mojanguuid + uuid)
|
||||||
return req.data.name
|
return req.data.name
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -47,7 +43,8 @@ async function getIGN(uuid: string): Promise<string | null> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getPlayer(uuid: string): Promise<IPlayerData | null> {
|
async function getPlayer(uuid: string): Promise<IPlayerData | null> {
|
||||||
const playerReq: IPlayer = await fetch(hypixel, {
|
try {
|
||||||
|
const req = await axios.get<IPlayer>(hypixel, {
|
||||||
params: {
|
params: {
|
||||||
uuid: uuid
|
uuid: uuid
|
||||||
},
|
},
|
||||||
@@ -55,18 +52,22 @@ async function getPlayer(uuid: string): Promise<IPlayerData | null> {
|
|||||||
"API-Key": apikey
|
"API-Key": apikey
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if (!req.data.player) {
|
||||||
if (!playerReq.data.player) {
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return playerReq.data.player
|
return req.data.player
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
} catch (err) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGuild(query: string, type?: GuildQueryType): Promise<IGuildData | null> {
|
async function getGuild(query: string, type?: GuildQueryType): Promise<IGuildData | null> {
|
||||||
const reqType = type ? type : "player"
|
const reqType = type ? type : "player"
|
||||||
|
|
||||||
const guildReq: IGuild = await fetch(guild, {
|
try {
|
||||||
|
const req = await axios.get<IGuild>(guild, {
|
||||||
params: {
|
params: {
|
||||||
[reqType]: query
|
[reqType]: query
|
||||||
},
|
},
|
||||||
@@ -75,11 +76,15 @@ async function getGuild(query: string, type?: GuildQueryType): Promise<IGuildDat
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!guildReq.data.guild) {
|
if (!req.data.guild) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return guildReq.data.guild
|
return req.data.guild
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
} catch (err) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getHeadURL(ign: string): Promise<string | null> {
|
async function getHeadURL(ign: string): Promise<string | null> {
|
||||||
|
|||||||
Reference in New Issue
Block a user