File tree Expand file tree Collapse file tree 6 files changed +41
-19
lines changed Expand file tree Collapse file tree 6 files changed +41
-19
lines changed Original file line number Diff line number Diff line change @@ -3,19 +3,4 @@ MONGODB_URI=
33BOT_DEFAULT_PREFIX=
44VERSION=
55UPTIME_KUMA_MONITOR_DOMAIN=
6- UPTIME_KUMA_MONITOR_ID=
7-
8-
9- # Fill out these values with the role id's of the roles you have in your server
10-
11- Prefrosh=
12- Freshman=
13- Sophomore=
14- Junior=
15- Senior=
16- Graduatestudent=
17- Alumni=
18- Sileader=
19- Ta=
20- Studentemployee=
21- Professor=
6+ UPTIME_KUMA_MONITOR_ID=
Original file line number Diff line number Diff line change 11import axios from "axios" ;
22import { Client } from "discord.js" ;
3+ import { isDocker } from "../utils/util" ;
34
45export default ( client : Client ) : void => {
6+ // Check if the bot is running in a docker container by checking if the env variable UPTIME_KUMA_CONTAINERIZED is true
7+ if ( isDocker ( ) ) return ;
58 const updateStatus = async ( ) => {
69 // This function is called every 1 minutes and pings the network status page for uptime monitoring
710 await axios . get (
Original file line number Diff line number Diff line change @@ -4,9 +4,10 @@ import WOKCommands from "wokcommands";
44import path from "path" ;
55import chalk from "chalk" ;
66import dotenv from "dotenv" ;
7+ import { isDocker } from "./utils/util" ;
78
89// import custom modules
9- import { checkForRoles , checkIfCollectionsExist } from "./rolesOps " ;
10+ import { checkForRoles , checkIfCollectionsExist } from "./utils/roleUtils " ;
1011import { classModel } from "./models/classModel" ;
1112import { staffModel } from "./models/staffModel" ;
1213import { yearModel } from "./models/yearModel" ;
@@ -27,6 +28,8 @@ const client = new DiscordJs.Client({
2728client . on ( "ready" , async ( ) => {
2829 if ( client . user ) {
2930 console . log ( chalk . green ( `Logged in as ${ client . user . tag } !` ) ) ;
31+ if ( isDocker ( ) )
32+ console . log ( chalk . blueBright ( `Running in a Docker container!` ) ) ;
3033 console . log (
3134 chalk . yellow . bold ( `I am running version: ${ process . env . VERSION } ` )
3235 ) ;
Original file line number Diff line number Diff line change 3131 "typescript" : " ^4.5.5" ,
3232 "wokcommands" : " ^1.5.3"
3333 }
34- }
34+ }
Original file line number Diff line number Diff line change 1+ import fs from "node:fs" ;
12export function sleep ( ms : number ) {
23 // Create new promise that resolves itself after a delay of <ms>
34 return new Promise ( ( resolve : ( args : void ) => void ) =>
45 setTimeout ( resolve , ms )
56 ) ;
67}
8+
9+ //! This code was taken from the package `is-docker` and modified to work here with esm
10+ //! Original repository: https://github.com/sindresorhus/is-docker
11+ let isDockerCached : boolean ;
12+
13+ function hasDockerEnv ( ) {
14+ try {
15+ fs . statSync ( "/.dockerenv" ) ;
16+ return true ;
17+ } catch {
18+ return false ;
19+ }
20+ }
21+
22+ function hasDockerCGroup ( ) {
23+ try {
24+ return fs . readFileSync ( "/proc/self/cgroup" , "utf8" ) . includes ( "docker" ) ;
25+ } catch {
26+ return false ;
27+ }
28+ }
29+
30+ export function isDocker ( ) {
31+ // TODO: Use `??=` when targeting Node.js 16.
32+ if ( isDockerCached === undefined ) {
33+ isDockerCached = hasDockerEnv ( ) || hasDockerCGroup ( ) ;
34+ }
35+
36+ return isDockerCached ;
37+ }
You can’t perform that action at this time.
0 commit comments