@@ -3,7 +3,6 @@ import { readdirSync } from "node:fs"
33import process from "node:process"
44import { setInterval } from "node:timers"
55
6- import axios from "axios"
76import {
87 type ChatInputCommandInteraction ,
98 type GuildMember ,
@@ -21,6 +20,7 @@ import {
2120 LocaleString ,
2221} from "discord.js"
2322import puppeteer from "puppeteer"
23+ import { fetch , RequestInit } from "undici"
2424import { v4 } from "uuid"
2525
2626import { db } from "./dbclient"
@@ -33,7 +33,12 @@ import type { ResponseObject, TranslationStatusModel } from "@crowdin/crowdin-ap
3333
3434// #region Variables
3535
36- export const fetchSettings = { headers : { "User-Agent" : "Hypixel Translators Bot" } , timeout : 30_000 }
36+ export const fetchSettings : RequestInit = { headers : { "User-Agent" : "Hypixel Translators Bot" } }
37+
38+ export const postSettings : RequestInit = {
39+ headers : { "Content-Type" : "application/json" , ...fetchSettings . headers } ,
40+ method : "POST" ,
41+ }
3742
3843// Browser-related variables, not exported
3944let browser : puppeteer . Browser | null = null ,
@@ -303,17 +308,15 @@ export async function getInviteLink() {
303308 return `https://discord.gg/${ inviteCode } `
304309}
305310
306- export async function getMCProfile ( uuid : string ) {
307- return await axios
308- . get < MinecraftProfile > ( `https://sessionserver.mojang.com/session/minecraft/profile/${ uuid } ` , fetchSettings )
309- . then ( json => json . data )
311+ export function getMCProfile ( uuid : string ) {
312+ return fetch ( `https://sessionserver.mojang.com/session/minecraft/profile/${ uuid } ` , fetchSettings )
313+ . then ( res => res . json ( ) as Promise < MinecraftProfile > )
310314 . catch ( ( ) => null )
311315}
312316
313- export async function getUUID ( username : string ) : Promise < string | null > {
314- return await axios
315- . get ( `https://api.mojang.com/users/profiles/minecraft/${ username } ` , fetchSettings )
316- . then ( data => data . data . id ?? null )
317+ export function getUUID ( username : string ) {
318+ return fetch ( `https://api.mojang.com/users/profiles/minecraft/${ username } ` , fetchSettings )
319+ . then ( async res => ( ( await res . json ( ) ) as UUIDResponse ) . id ?? null )
317320 . catch ( ( ) => null )
318321}
319322
@@ -342,13 +345,14 @@ export function parseToNumberString(num: number, getString: GetStringFunction):
342345 return format ( num )
343346}
344347
345- export async function restart ( interaction ?: ChatInputCommandInteraction ) {
346- await axios . delete ( "https://api.heroku.com/apps/hypixel-translators/dynos" , {
348+ export function restart ( interaction ?: ChatInputCommandInteraction ) {
349+ return fetch ( "https://api.heroku.com/apps/hypixel-translators/dynos" , {
347350 headers : {
348351 "User-Agent" : `${ interaction ?. user . tag ?? client . user . tag } ` ,
349352 Authorization : `Bearer ${ process . env . HEROKU_API } ` ,
350353 Accept : "application/vnd.heroku+json; version=3" ,
351354 } ,
355+ method : "DELETE" ,
352356 } )
353357}
354358
@@ -620,4 +624,9 @@ export interface Stats {
620624 errorMessage ?: string
621625}
622626
627+ interface UUIDResponse {
628+ name : string
629+ id : string
630+ }
631+
623632// #endregion
0 commit comments