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