From aa692e073009bed81953d61e3fa3dbcad78520b7 Mon Sep 17 00:00:00 2001 From: barthofu Date: Tue, 30 Jan 2024 14:53:36 +0000 Subject: [PATCH] fix(#112): botOnline middleware useless http request --- src/api/middlewares/botOnline.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/api/middlewares/botOnline.ts b/src/api/middlewares/botOnline.ts index 4b8f3009..4bcdf2f5 100644 --- a/src/api/middlewares/botOnline.ts +++ b/src/api/middlewares/botOnline.ts @@ -1,23 +1,23 @@ import { Middleware } from "@tsed/common" import { InternalServerError } from "@tsed/exceptions" -import axios from "axios" - -import { apiConfig } from "@configs" - -const baseUrl = `http://127.0.0.1:${apiConfig.port}` +import { resolveDependencies } from "@utils/functions" +import { Client } from "discordx" @Middleware() export class BotOnline { - async use() { + private client: Client + + constructor() { - const { data } = await axios.get(`${baseUrl}/health/check`, { - params: { - logIgnore: true - } + resolveDependencies([Client]).then(([client]) => { + this.client = client }) - - if (!data?.online) throw new InternalServerError('Bot is offline') + } + + async use() { + + if (this.client.user?.presence.status === 'offline') throw new InternalServerError('Bot is offline') } } \ No newline at end of file