From 95f9bb723f7fed1ab5ea8ac69026575830e92996 Mon Sep 17 00:00:00 2001 From: Taken Date: Thu, 20 Mar 2025 23:41:18 +0100 Subject: [PATCH] Added new tryCatch wrapper --- scripts/delete-commands.ts | 8 +- scripts/deploy-commands.ts | 8 +- scripts/dev-deploy.ts | 8 +- src/commands/unban.ts | 11 ++- .../buttons/guildapplicationaccept.ts | 13 ++- src/components/buttons/guildapply.ts | 23 +++--- src/components/buttons/guildinactivitylog.ts | 27 +++--- src/components/buttons/staffapply.ts | 23 +++--- src/components/modals/denyreasonbox.ts | 11 +-- src/utils/Events/autocomplete.ts | 34 ++++---- src/utils/Events/button.ts | 66 +++++++-------- src/utils/Events/command.ts | 66 +++++++-------- src/utils/Events/contextmenu.ts | 66 +++++++-------- src/utils/Events/modal.ts | 64 +++++++-------- src/utils/Functions/trycatch.ts | 14 ++++ src/utils/HypixelFunctions/account.ts | 82 +++++++------------ 16 files changed, 255 insertions(+), 269 deletions(-) create mode 100644 src/utils/Functions/trycatch.ts diff --git a/scripts/delete-commands.ts b/scripts/delete-commands.ts index 40dcdad..ab56789 100644 --- a/scripts/delete-commands.ts +++ b/scripts/delete-commands.ts @@ -1,16 +1,18 @@ import { REST, Routes } from "discord.js" import env from "../src/utils/Env" +import tryCatch from "../src/utils/Functions/trycatch" import { log } from "../src/utils/Logger" const rest = new REST({ version: "10" }).setToken(env.dev.DEVTOKEN) -try { +const [error] = await tryCatch(deleteCommands()) +if (error) log(error, "error") + +async function deleteCommands() { log("Started deleting application (/) commands.", "info") await rest.put( Routes.applicationGuildCommands(env.dev.DEVID, env.dev.GUILDID), { body: [] } ) log("Successfully deleted application (/) commands.", "info") -} catch (error) { - console.error(error) } diff --git a/scripts/deploy-commands.ts b/scripts/deploy-commands.ts index 797b6e9..e149a40 100644 --- a/scripts/deploy-commands.ts +++ b/scripts/deploy-commands.ts @@ -2,6 +2,7 @@ import { REST, RESTPutAPIApplicationCommandsJSONBody, Routes } from "discord.js" import fs from "node:fs" import { ICommand } from "../src/typings" import env from "../src/utils/Env" +import tryCatch from "../src/utils/Functions/trycatch" import { log } from "../src/utils/Logger" const rest = new REST({ version: "10" }).setToken(env.prod.TOKEN) @@ -18,7 +19,10 @@ for (const file of contentMenuCommands) { commands.push(command.data.toJSON()) } -try { +const [error] = await tryCatch(updateCommands()) +if (error) log(error, "error") + +async function updateCommands() { log(`Started refreshing ${commands.length} application (/) commands.`, "info", { type: "preset", color: "green" }) const commandsString = commands.map(command => " " + command.name) @@ -31,6 +35,4 @@ try { log(`Successfully reloaded ${commands.length} application (/) commands.`, "info", { type: "preset", color: "green" }) process.exit(0) }) -} catch (error) { - console.error(error) } diff --git a/scripts/dev-deploy.ts b/scripts/dev-deploy.ts index eb8327b..9844668 100644 --- a/scripts/dev-deploy.ts +++ b/scripts/dev-deploy.ts @@ -2,6 +2,7 @@ import { REST, RESTPutAPIApplicationCommandsJSONBody, Routes } from "discord.js" import fs from "fs" import { ICommand } from "../src/typings" import env from "../src/utils/Env" +import tryCatch from "../src/utils/Functions/trycatch" import { log } from "../src/utils/Logger" const rest = new REST({ version: "10" }).setToken(env.dev.DEVTOKEN) @@ -22,7 +23,10 @@ for (const file of contentMenuCommands) { } } -try { +const [error] = await tryCatch(updateCommands()) +if (error) log(error, "error") + +async function updateCommands() { log(`Started refreshing ${commands.length} application (/) commands.`, "info") await rest.put( @@ -32,6 +36,4 @@ try { log(`Successfully reloaded ${commands.length} application (/) commands.`, "info") process.exit(0) }) -} catch (error) { - console.error(error) } diff --git a/src/commands/unban.ts b/src/commands/unban.ts index 3d939c4..6a5c633 100644 --- a/src/commands/unban.ts +++ b/src/commands/unban.ts @@ -1,7 +1,8 @@ -import { InteractionContextType, PermissionFlagsBits, SlashCommandBuilder, User, userMention } from "discord.js" +import { InteractionContextType, PermissionFlagsBits, SlashCommandBuilder, userMention } from "discord.js" import { devMessage, embedColor } from "~/config/options" import { ICommand } from "~/typings" import logToChannel from "~/utils/Functions/logtochannel" +import tryCatch from "~/utils/Functions/trycatch" export default { name: "unban", @@ -34,7 +35,6 @@ export default { const userid = interaction.options.getString("user")! const reason = interaction.options.getString("reason") || "No reason provided" const mod = interaction.user - let user: User if (userid === "none") { await interaction.editReply({ @@ -46,10 +46,9 @@ export default { return } - try { - user = await interaction.client.users.fetch(userid) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (error) { + const [e, user] = await tryCatch(interaction.client.users.fetch(userid)) + + if (e) { await interaction.editReply({ embeds: [{ description: "The user you specified is not valid", diff --git a/src/components/buttons/guildapplicationaccept.ts b/src/components/buttons/guildapplicationaccept.ts index b07bd5c..1dcb162 100644 --- a/src/components/buttons/guildapplicationaccept.ts +++ b/src/components/buttons/guildapplicationaccept.ts @@ -4,6 +4,7 @@ import { addWaitingList, getWaitingLists, removeWaitingList } from "src/drizzle/ import { embedColor, hypixelGuildID, waitingListChannel, waitingListMessage } from "~/config/options" import { waitingListRole } from "~/config/roles" import { IButton } from "~/typings" +import tryCatch from "~/utils/Functions/trycatch" import { getGuild, getIGN } from "~/utils/Hypixel" import { log } from "~/utils/Logger" @@ -82,7 +83,11 @@ export default { }) if (process.env.NODE_ENV === "dev") return - try { + + const [error] = await tryCatch(updateWaitingList()) + if (error) return log("Error while trying to update waiting list.", "error") + + async function updateWaitingList() { const channel = guild.channels.cache.get(waitingListChannel) as TextChannel const wlmessage = await channel!.messages.fetch(waitingListMessage) @@ -125,12 +130,6 @@ export default { timestamp: new Date().toISOString() }] }) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (err) { - log( - "Error while trying to update waiting list.", - "error" - ) } } } as IButton diff --git a/src/components/buttons/guildapply.ts b/src/components/buttons/guildapply.ts index b9549d5..5e06f44 100644 --- a/src/components/buttons/guildapply.ts +++ b/src/components/buttons/guildapply.ts @@ -6,6 +6,7 @@ import { guild as guildQuestions } from "~/config/questions" import { guildRole } from "~/config/roles" import { IButton } from "~/typings" import applicationQuestions from "~/utils/Functions/applicationquestions" +import tryCatch from "~/utils/Functions/trycatch" export default { name: "guildapply", @@ -37,18 +38,16 @@ export default { return } - try { - await user.send({ - embeds: [{ - title: "Guild Application", - description: "If you wish to proceed with your application, please type `yes` otherwise type `cancel`.\n\n" + - "**Do not upload images, videos, or GIFS.**\n" + - "You have a minute to respond to this message.", - color: embedColor - }] - }) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (error) { + const [error] = await tryCatch(user.send({ + embeds: [{ + title: "Guild Application", + description: "If you wish to proceed with your application, please type `yes` otherwise type `cancel`.\n\n" + + "**Do not upload images, videos, or GIFS.**\n" + + "You have a minute to respond to this message.", + color: embedColor + }] + })) + if (error) { await interaction.editReply("Please enable your DMs.") return } diff --git a/src/components/buttons/guildinactivitylog.ts b/src/components/buttons/guildinactivitylog.ts index b7acece..e271973 100644 --- a/src/components/buttons/guildinactivitylog.ts +++ b/src/components/buttons/guildinactivitylog.ts @@ -5,6 +5,7 @@ import { inactivity } from "~/config/questions" import { beast, gm, guildRole, guildStaff, leader, member, staff } from "~/config/roles" import { IButton } from "~/typings" import applicationQuestions from "~/utils/Functions/applicationquestions" +import tryCatch from "~/utils/Functions/trycatch" const guildRoles = [gm, leader, staff, beast, member, guildStaff, guildRole] export default { @@ -32,20 +33,18 @@ export default { return inactivity[n - 1].r } - try { - await user.send({ - embeds: [{ - title: "Guild Inactivity Log", - description: "Please answer the following questions to submit an inactivity log for the guild.\n" + - "If you wish to cancel your form, please press type `cancel` at any time.\n" + - "If you wish to proceed with your form, please type `yes`.\n\n" + - "**Do not upload images, videos, or GIFS.**\n" + - "You have a minute to respond to this message.", - color: embedColor - }] - }) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (error) { + const [error] = await tryCatch(user.send({ + embeds: [{ + title: "Guild Inactivity Log", + description: "Please answer the following questions to submit an inactivity log for the guild.\n" + + "If you wish to cancel your form, please press type `cancel` at any time.\n" + + "If you wish to proceed with your form, please type `yes`.\n\n" + + "**Do not upload images, videos, or GIFS.**\n" + + "You have a minute to respond to this message.", + color: embedColor + }] + })) + if (error) { await interaction.reply({ content: "Please enable your DMs.", flags: MessageFlags.Ephemeral diff --git a/src/components/buttons/staffapply.ts b/src/components/buttons/staffapply.ts index cde7cd8..cef4637 100644 --- a/src/components/buttons/staffapply.ts +++ b/src/components/buttons/staffapply.ts @@ -7,6 +7,7 @@ import { guildRole, guildStaff } from "~/config/roles" import { IButton } from "~/typings" import env from "~/utils/Env" import applicationQuestions from "~/utils/Functions/applicationquestions" +import tryCatch from "~/utils/Functions/trycatch" export default { name: "staffapply", @@ -54,18 +55,16 @@ export default { return } - try { - await user.send({ - embeds: [{ - title: "Staff Application", - description: "If you wish to proceed with your application, please type `yes` otherwise type `cancel`.\n\n" + - "**Do not upload images, videos, or GIFS.**\n" + - "You have a minute to respond to this message.", - color: embedColor - }] - }) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (error) { + const [error] = await tryCatch(user.send({ + embeds: [{ + title: "Staff Application", + description: "If you wish to proceed with your application, please type `yes` otherwise type `cancel`.\n\n" + + "**Do not upload images, videos, or GIFS.**\n" + + "You have a minute to respond to this message.", + color: embedColor + }] + })) + if (error) { await interaction.editReply("Please enable your DMs.") return } diff --git a/src/components/modals/denyreasonbox.ts b/src/components/modals/denyreasonbox.ts index 2625cc6..ce97a01 100644 --- a/src/components/modals/denyreasonbox.ts +++ b/src/components/modals/denyreasonbox.ts @@ -1,7 +1,8 @@ -import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, GuildMember, Message } from "discord.js" +import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, Message } from "discord.js" import { removeGuildApp } from "src/drizzle/functions" import { embedColor } from "~/config/options" import { IModal } from "~/typings" +import tryCatch from "~/utils/Functions/trycatch" export default { name: "denyreasonbox", @@ -38,13 +39,7 @@ export default { ] }) - let applicant: GuildMember | null - try { - applicant = await guild.members.fetch(applicantId) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (error) { - applicant = null - } + const [, applicant] = await tryCatch(guild.members.fetch(applicantId)) const dmMessage = new EmbedBuilder() .setDescription( diff --git a/src/utils/Events/autocomplete.ts b/src/utils/Events/autocomplete.ts index 6fce3a8..102b5af 100644 --- a/src/utils/Events/autocomplete.ts +++ b/src/utils/Events/autocomplete.ts @@ -5,6 +5,7 @@ import { embedColor } from "~/config/options" import { IAutocomplete } from "~/typings" import { ExtendedClient as Client } from "~/utils/Client" import logToChannel from "~/utils/Functions/logtochannel" +import tryCatch from "../Functions/trycatch" import { log } from "../Logger" type FileType = "js" | "ts" @@ -28,23 +29,22 @@ export default async function loadAutocompleteEvents(client: Client, ft: FileTyp return } - try { - await autocomplete.execute({ interaction, client }) - } catch (error) { - if (process.env.NODE_ENV !== "dev") { - await logToChannel("error", { - embeds: [{ - title: "Autocomplete error occured", - description: "```" + error + "```", - color: embedColor, - footer: { - icon_url: interaction.guild!.iconURL() || undefined, - text: interaction.user.username + " | " + interaction.commandName - } - }] - }) - } - log(error, "error") + const [error] = await tryCatch(autocomplete.execute({ interaction, client })) + if (!error) return + + if (process.env.NODE_ENV !== "dev") { + await logToChannel("error", { + embeds: [{ + title: "Autocomplete error occured", + description: "```" + error + "```", + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL() || undefined, + text: interaction.user.username + " | " + interaction.commandName + } + }] + }) } + log(error, "error") }) } diff --git a/src/utils/Events/button.ts b/src/utils/Events/button.ts index fd0a96a..c72516d 100644 --- a/src/utils/Events/button.ts +++ b/src/utils/Events/button.ts @@ -5,6 +5,7 @@ import { embedColor } from "~/config/options" import { IButton } from "~/typings" import { ExtendedClient as Client } from "~/utils/Client" import logToChannel from "~/utils/Functions/logtochannel" +import tryCatch from "../Functions/trycatch" import { log } from "../Logger" type FileType = "js" | "ts" @@ -35,40 +36,39 @@ export default async function loadButtonEvents(client: Client, ft: FileType) { return } - try { - await button.execute({ interaction, client }) - } catch (error) { - if (process.env.NODE_ENV !== "dev") { - await logToChannel("error", { - embeds: [{ - title: "Button error occured", - description: "```" + error + "```", - color: embedColor, - footer: { - icon_url: interaction.guild!.iconURL() || undefined, - text: interaction.user.username + " | " + interaction.customId - } - }] - }) - } + const [error] = await tryCatch(button.execute({ interaction, client })) + if (!error) return - log(error, "error") - if (!interaction.deferred) { - await interaction.reply({ - embeds: [{ - description: "There was an error while executing this button!", - color: embedColor - }], - flags: MessageFlags.Ephemeral - }) - } else { - await interaction.editReply({ - embeds: [{ - description: "There was an error while executing this button! 2", - color: embedColor - }] - }) - } + if (process.env.NODE_ENV !== "dev") { + await logToChannel("error", { + embeds: [{ + title: "Button error occured", + description: "```" + error + "```", + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL() || undefined, + text: interaction.user.username + " | " + interaction.customId + } + }] + }) + } + + log(error, "error") + if (!interaction.deferred) { + await interaction.reply({ + embeds: [{ + description: "There was an error while executing this button!", + color: embedColor + }], + flags: MessageFlags.Ephemeral + }) + } else { + await interaction.editReply({ + embeds: [{ + description: "There was an error while executing this button! 2", + color: embedColor + }] + }) } }) } diff --git a/src/utils/Events/command.ts b/src/utils/Events/command.ts index 49221f0..b878e5e 100644 --- a/src/utils/Events/command.ts +++ b/src/utils/Events/command.ts @@ -5,6 +5,7 @@ import { embedColor } from "~/config/options" import { ICommand } from "~/typings" import { ExtendedClient as Client } from "~/utils/Client" import logToChannel from "~/utils/Functions/logtochannel" +import tryCatch from "../Functions/trycatch" import { log } from "../Logger" type FileType = "js" | "ts" @@ -33,40 +34,39 @@ export default async function loadSlashCommandsEvents(client: Client, ft: FileTy return } - try { - await command.execute({ interaction, client }) - } catch (error) { - if (process.env.NODE_ENV !== "dev") { - await logToChannel("error", { - embeds: [{ - title: "Command error occured", - description: "```" + error + "```", - color: embedColor, - footer: { - icon_url: interaction.guild!.iconURL() || undefined, - text: interaction.user.username + " | " + interaction.commandName - } - }] - }) - } + const [error] = await tryCatch(command.execute({ interaction, client })) + if (!error) return - log(error, "error") - if (!interaction.deferred) { - await interaction.reply({ - embeds: [{ - description: "There was an error while executing this command!", - color: embedColor - }], - flags: MessageFlags.Ephemeral - }) - } else { - await interaction.editReply({ - embeds: [{ - description: "There was an error while executing this command!", - color: embedColor - }] - }) - } + if (process.env.NODE_ENV !== "dev") { + await logToChannel("error", { + embeds: [{ + title: "Command error occured", + description: "```" + error + "```", + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL() || undefined, + text: interaction.user.username + " | " + interaction.commandName + } + }] + }) + } + + log(error, "error") + if (!interaction.deferred) { + await interaction.reply({ + embeds: [{ + description: "There was an error while executing this command!", + color: embedColor + }], + flags: MessageFlags.Ephemeral + }) + } else { + await interaction.editReply({ + embeds: [{ + description: "There was an error while executing this command!", + color: embedColor + }] + }) } }) } diff --git a/src/utils/Events/contextmenu.ts b/src/utils/Events/contextmenu.ts index 848ccfb..227ca8c 100644 --- a/src/utils/Events/contextmenu.ts +++ b/src/utils/Events/contextmenu.ts @@ -5,6 +5,7 @@ import { embedColor } from "~/config/options" import { IContextMenu } from "~/typings" import { ExtendedClient as Client } from "~/utils/Client" import logToChannel from "~/utils/Functions/logtochannel" +import tryCatch from "../Functions/trycatch" import { log } from "../Logger" type FileType = "js" | "ts" @@ -33,40 +34,39 @@ export default async function loadContextMenuEvents(client: Client, ft: FileType return } - try { - await command.execute({ interaction, client }) - } catch (error) { - if (process.env.NODE_ENV !== "dev") { - await logToChannel("error", { - embeds: [{ - title: "Contextmenu error occured", - description: "```" + error + "```", - color: embedColor, - footer: { - icon_url: interaction.guild!.iconURL() || undefined, - text: interaction.user.username + " | " + interaction.commandName - } - }] - }) - } + const [error] = await tryCatch(command.execute({ interaction, client })) + if (!error) return - log(error, "error") - if (!interaction.deferred) { - await interaction.reply({ - embeds: [{ - description: "There was an error while executing this contextmenu command!", - color: embedColor - }], - flags: MessageFlags.Ephemeral - }) - } else { - await interaction.editReply({ - embeds: [{ - description: "There was an error while executing this contextmenu command!", - color: embedColor - }] - }) - } + if (process.env.NODE_ENV !== "dev") { + await logToChannel("error", { + embeds: [{ + title: "Contextmenu error occured", + description: "```" + error + "```", + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL() || undefined, + text: interaction.user.username + " | " + interaction.commandName + } + }] + }) + } + + log(error, "error") + if (!interaction.deferred) { + await interaction.reply({ + embeds: [{ + description: "There was an error while executing this contextmenu command!", + color: embedColor + }], + flags: MessageFlags.Ephemeral + }) + } else { + await interaction.editReply({ + embeds: [{ + description: "There was an error while executing this contextmenu command!", + color: embedColor + }] + }) } }) } diff --git a/src/utils/Events/modal.ts b/src/utils/Events/modal.ts index 0be5f7c..1a05a66 100644 --- a/src/utils/Events/modal.ts +++ b/src/utils/Events/modal.ts @@ -5,6 +5,7 @@ import { embedColor } from "~/config/options" import { IModal } from "~/typings" import { ExtendedClient as Client } from "~/utils/Client" import logToChannel from "~/utils/Functions/logtochannel" +import tryCatch from "../Functions/trycatch" import { log } from "../Logger" type FileType = "js" | "ts" @@ -32,39 +33,38 @@ export default async function loadModalEvents(client: Client, ft: FileType) { return } - try { - await modal.execute({ interaction, client }) - } catch (error) { - if (process.env.NODE_ENV !== "dev") { - await logToChannel("error", { - embeds: [{ - title: "Button error occured", - description: "```" + error + "```", - color: embedColor, - footer: { - icon_url: interaction.guild!.iconURL() || undefined, - text: interaction.user.username + " | " + interaction.customId - } - }] - }) - } + const [error] = await tryCatch(modal.execute({ interaction, client })) + if (!error) return - log(error, "error") - if (!interaction.deferred) { - await interaction.reply({ - embeds: [{ - description: "There was an error while executing this modal!", - color: embedColor - }] - }) - } else { - await interaction.editReply({ - embeds: [{ - description: "There was an error while executing this modal!", - color: embedColor - }] - }) - } + if (process.env.NODE_ENV !== "dev") { + await logToChannel("error", { + embeds: [{ + title: "Button error occured", + description: "```" + error + "```", + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL() || undefined, + text: interaction.user.username + " | " + interaction.customId + } + }] + }) + } + + log(error, "error") + if (!interaction.deferred) { + await interaction.reply({ + embeds: [{ + description: "There was an error while executing this modal!", + color: embedColor + }] + }) + } else { + await interaction.editReply({ + embeds: [{ + description: "There was an error while executing this modal!", + color: embedColor + }] + }) } }) } diff --git a/src/utils/Functions/trycatch.ts b/src/utils/Functions/trycatch.ts new file mode 100644 index 0000000..66d2594 --- /dev/null +++ b/src/utils/Functions/trycatch.ts @@ -0,0 +1,14 @@ +type Success = [null, T] + +type Failure = [E, null] + +type Result = Success | Failure + +export default async function tryCatch(promise: Promise): Promise> { + try { + const data = await promise + return [null, data] + } catch (error) { + return [error as E, null] + } +} diff --git a/src/utils/HypixelFunctions/account.ts b/src/utils/HypixelFunctions/account.ts index 6306ece..bb1757e 100644 --- a/src/utils/HypixelFunctions/account.ts +++ b/src/utils/HypixelFunctions/account.ts @@ -1,6 +1,7 @@ -import axios from "axios" +import axios, { AxiosError, AxiosResponse } from "axios" import { IGuild, IGuildData, IPlayer, IPlayerData } from "~/typings" import env from "~/utils/Env" +import tryCatch from "../Functions/trycatch" const apikey = env.prod.HYPIXELAPIKEY const mojang = "https://api.mojang.com/users/profiles/minecraft/" const mojanguuid = "https://sessionserver.mojang.com/session/minecraft/profile/" @@ -22,70 +23,45 @@ type IGNData = { } async function getUUID(ign: string): Promise { - try { - const req = await axios.get(mojang + ign) - return req.data.id - // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (err) { - return null - } + const [e, d] = await tryCatch, AxiosError>(axios.get(mojang + ign)) + if (e) return null + return d.data.id } async function getIGN(uuid: string): Promise { - try { - const req = await axios.get(mojanguuid + uuid) - return req.data.name - // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (err) { - return null - } + const [e, d] = await tryCatch, AxiosError>(axios.get(mojanguuid + uuid)) + if (e) return null + return d.data.name } async function getPlayer(uuid: string): Promise { - try { - const req = await axios.get(hypixel, { - params: { - uuid: uuid - }, - headers: { - "API-Key": apikey - } - }) - if (!req.data.player) { - return null + const [e, d] = await tryCatch, AxiosError>(axios.get(hypixel, { + params: { + uuid: uuid + }, + headers: { + "API-Key": apikey } - - return req.data.player - // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (err) { - return null - } + })) + if (e) return null + if (!d.data.player) return null + return d.data.player } async function getGuild(query: string, reqType: GuildQueryType = "player"): Promise { - try { - const req = await axios.get(guild, { - params: { - [reqType]: query - }, - headers: { - "API-Key": apikey - } - }) - - if (!req.data.guild) { - return null + const [e, d] = await tryCatch, AxiosError>(axios.get(guild, { + params: { + [reqType]: query + }, + headers: { + "API-Key": apikey } - - return req.data.guild - // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (err) { - return null - } + })) + if (e) return null + if (!d.data.guild) return null + return d.data.guild } -function getHeadURL(ign: string): string { - return minotar + ign -} +const getHeadURL = (ign: string) => minotar + ign export { getGuild, getHeadURL, getIGN, getPlayer, getUUID }