Skip to content

Commit

Permalink
fix(#112): botOnline middleware useless http request
Browse files Browse the repository at this point in the history
  • Loading branch information
barthofu committed Jan 30, 2024
1 parent 6f83ffb commit 8060043
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/api/middlewares/botOnline.ts
Original file line number Diff line number Diff line change
@@ -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')
}

}

0 comments on commit 8060043

Please # to comment.