@@ -3,7 +3,6 @@ import { readdirSync } from "node:fs"
3
3
import process from "node:process"
4
4
import { setInterval } from "node:timers"
5
5
6
- import axios from "axios"
7
6
import {
8
7
type ChatInputCommandInteraction ,
9
8
type GuildMember ,
@@ -21,6 +20,7 @@ import {
21
20
LocaleString ,
22
21
} from "discord.js"
23
22
import puppeteer from "puppeteer"
23
+ import { fetch , RequestInit } from "undici"
24
24
import { v4 } from "uuid"
25
25
26
26
import { db } from "./dbclient"
@@ -33,7 +33,12 @@ import type { ResponseObject, TranslationStatusModel } from "@crowdin/crowdin-ap
33
33
34
34
// #region Variables
35
35
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
+ }
37
42
38
43
// Browser-related variables, not exported
39
44
let browser : puppeteer . Browser | null = null ,
@@ -303,17 +308,15 @@ export async function getInviteLink() {
303
308
return `https://discord.gg/${ inviteCode } `
304
309
}
305
310
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 > )
310
314
. catch ( ( ) => null )
311
315
}
312
316
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 )
317
320
. catch ( ( ) => null )
318
321
}
319
322
@@ -342,13 +345,14 @@ export function parseToNumberString(num: number, getString: GetStringFunction):
342
345
return format ( num )
343
346
}
344
347
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" , {
347
350
headers : {
348
351
"User-Agent" : `${ interaction ?. user . tag ?? client . user . tag } ` ,
349
352
Authorization : `Bearer ${ process . env . HEROKU_API } ` ,
350
353
Accept : "application/vnd.heroku+json; version=3" ,
351
354
} ,
355
+ method : "DELETE" ,
352
356
} )
353
357
}
354
358
@@ -620,4 +624,9 @@ export interface Stats {
620
624
errorMessage ?: string
621
625
}
622
626
627
+ interface UUIDResponse {
628
+ name : string
629
+ id : string
630
+ }
631
+
623
632
// #endregion
0 commit comments