-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#112): botOnline middleware useless http request
- Loading branch information
Showing
1 changed file
with
12 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
} | ||
|
||
} |