Skip to content

Commit 62e5422

Browse files
committed
Merge branch 'feature/nathen418/detect-containerization' of https://github.com/Antares-Network/CSSC-Bot into feature/nathen418/detect-containerization
2 parents b5dfd6e + b0cd0ff commit 62e5422

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

features/statuspage.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Client } from "discord.js";
33
import { isDocker } from "../utils/util";
44

55
export default (client: Client): void => {
6-
76
// Check if the bot is running in a docker container by checking if the env variable UPTIME_KUMA_CONTAINERIZED is true
87
if (isDocker()) return;
98
const updateStatus = async () => {

index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const client = new DiscordJs.Client({
2828
client.on("ready", async () => {
2929
if (client.user) {
3030
console.log(chalk.green(`Logged in as ${client.user.tag}!`));
31-
if (isDocker()) console.log(chalk.blueBright(`Running in a Docker container!`));
31+
if (isDocker())
32+
console.log(chalk.blueBright(`Running in a Docker container!`));
3233
console.log(
3334
chalk.yellow.bold(`I am running version: ${process.env.VERSION}`)
3435
);

utils/util.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
1-
import fs from 'node:fs';
1+
import fs from "node:fs";
22
export function sleep(ms: number) {
33
// Create new promise that resolves itself after a delay of <ms>
44
return new Promise((resolve: (args: void) => void) =>
55
setTimeout(resolve, ms)
66
);
77
}
88

9-
109
//! This code was taken from the package `is-docker` and modified to work here with esm
1110
//! Original repository: https://github.com/sindresorhus/is-docker
1211
let isDockerCached: boolean;
1312

1413
function hasDockerEnv() {
15-
try {
16-
fs.statSync('/.dockerenv');
17-
return true;
18-
} catch {
19-
return false;
20-
}
14+
try {
15+
fs.statSync("/.dockerenv");
16+
return true;
17+
} catch {
18+
return false;
19+
}
2120
}
2221

2322
function hasDockerCGroup() {
24-
try {
25-
return fs.readFileSync('/proc/self/cgroup', 'utf8').includes('docker');
26-
} catch {
27-
return false;
28-
}
23+
try {
24+
return fs.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
25+
} catch {
26+
return false;
27+
}
2928
}
3029

3130
export function isDocker() {
32-
// TODO: Use `??=` when targeting Node.js 16.
33-
if (isDockerCached === undefined) {
34-
isDockerCached = hasDockerEnv() || hasDockerCGroup();
35-
}
31+
// TODO: Use `??=` when targeting Node.js 16.
32+
if (isDockerCached === undefined) {
33+
isDockerCached = hasDockerEnv() || hasDockerCGroup();
34+
}
3635

37-
return isDockerCached;
38-
}
36+
return isDockerCached;
37+
}

0 commit comments

Comments
 (0)