File tree Expand file tree Collapse file tree 5 files changed +39
-21
lines changed Expand file tree Collapse file tree 5 files changed +39
-21
lines changed Original file line number Diff line number Diff line change 11import axios from "axios" ;
22import { Client } from "discord.js" ;
3+ import { isDocker } from "../util" ;
34
45export default ( client : Client ) : void => {
6+
7+ // Check if the bot is running in a docker container by checking if the env variable UPTIME_KUMA_CONTAINERIZED is true
8+ if ( isDocker ( ) ) return ;
59 const updateStatus = async ( ) => {
610 // This function is called every 1 minutes and pings the network status page for uptime monitoring
711 await axios . get (
812 `https://${ process . env . UPTIME_KUMA_MONITOR_DOMAIN } /api/push/${ process . env . UPTIME_KUMA_MONITOR_ID } ?msg=OK&ping=${ client . ws . ping } `
913 ) ;
14+ console . log ( "ping anyways" )
1015 setTimeout ( updateStatus , 1000 * 60 ) ;
1116 } ;
1217 updateStatus ( ) . catch ( ( err ) => console . log ( err ) ) ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import WOKCommands from "wokcommands";
44import path from "path" ;
55import chalk from "chalk" ;
66import dotenv from "dotenv" ;
7+ import { isDocker } from "./util" ;
78
89// import custom modules
910import { checkForRoles , checkIfCollectionsExist } from "./rolesOps" ;
@@ -27,6 +28,7 @@ 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 ( ) ) console . log ( chalk . blueBright ( `Running in a Docker container!` ) ) ;
3032 console . log (
3133 chalk . yellow . bold ( `I am running version: ${ process . env . VERSION } ` )
3234 ) ;
Original file line number Diff line number Diff line change 2424 "axios" : " ^0.27.2" ,
2525 "chalk" : " 4.1.2" ,
2626 "discord.js" : " ^13.9.2" ,
27- "is-docker" : " ^3.0.0" ,
2827 "mongoose" : " ^6.5.4" ,
2928 "path" : " ^0.12.7" ,
3029 "prettier" : " ^2.7.1" ,
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+
10+ //! This code was taken from the package `is-docker` and modified to work here with esm
11+ //! Original repository: https://github.com/sindresorhus/is-docker
12+ let isDockerCached : boolean ;
13+
14+ function hasDockerEnv ( ) {
15+ try {
16+ fs . statSync ( '/.dockerenv' ) ;
17+ return true ;
18+ } catch {
19+ return false ;
20+ }
21+ }
22+
23+ function hasDockerCGroup ( ) {
24+ try {
25+ return fs . readFileSync ( '/proc/self/cgroup' , 'utf8' ) . includes ( 'docker' ) ;
26+ } catch {
27+ return false ;
28+ }
29+ }
30+
31+ export function isDocker ( ) {
32+ // TODO: Use `??=` when targeting Node.js 16.
33+ if ( isDockerCached === undefined ) {
34+ isDockerCached = hasDockerEnv ( ) || hasDockerCGroup ( ) ;
35+ }
36+
37+ return isDockerCached ;
38+ }
You can’t perform that action at this time.
0 commit comments