diff --git a/ecosystem.config.cjs b/ecosystem.config.cjs index c0216ad8..06ff72a1 100644 --- a/ecosystem.config.cjs +++ b/ecosystem.config.cjs @@ -1,8 +1,9 @@ module.exports = { apps: [ { - name: "esmBot-manager", + name: "esmBot", script: "dist/cluster/node.js", + node_args: "--env-file-if-exists=.env", autorestart: true, exp_backoff_restart_delay: 1000, watch: false, diff --git a/package.json b/package.json index 300c19d1..9c69f9b9 100644 --- a/package.json +++ b/package.json @@ -48,18 +48,17 @@ "format": "oxfmt", "format:check": "oxfmt --check", "lint": "oxlint", - "start": "node dist/app.js", - "start:deno": "deno -P src/app.ts", - "start:debug": "DEBUG=true node dist/app.js", - "start:deno:debug": "DEBUG=true deno -P src/app.ts", + "start": "node --env-file-if-exists=.env dist/app.js", + "start:deno": "deno run -P --env-file src/app.ts", + "start:debug": "DEBUG=true node --env-file-if-exists=.env dist/app.js", + "start:deno:debug": "DEBUG=true deno run -P --env-file src/app.ts", "start-api": "node dist/api/index.js", - "start-api:deno": "deno -P src/api/index.ts", + "start-api:deno": "deno run -P src/api/index.ts", "start-api:debug": "DEBUG=true node dist/api/index.js", - "start-api:deno:debug": "DEBUG=true deno -P src/api/index.ts" + "start-api:deno:debug": "DEBUG=true deno run -P src/api/index.ts" }, "dependencies": { "bufferutil": "^4.1.0", - "dotenv": "^17.4.2", "file-type": "^22.0.1", "ipaddr.js": "^2.4.0", "node-addon-api": "^8.8.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0850ee31..71e29c69 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,9 +11,6 @@ importers: bufferutil: specifier: ^4.1.0 version: 4.1.0 - dotenv: - specifier: ^17.4.2 - version: 17.4.2 file-type: specifier: ^22.0.1 version: 22.0.1 @@ -449,10 +446,6 @@ packages: resolution: {integrity: sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==} engines: {node: '>=4.0.0'} - dotenv@17.4.2: - resolution: {integrity: sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw==} - engines: {node: '>=12'} - emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} @@ -984,8 +977,6 @@ snapshots: deep-extend@0.6.0: {} - dotenv@17.4.2: {} - emoji-regex@8.0.0: {} enabled@2.0.0: {} diff --git a/src/api/index.ts b/src/api/index.ts index 63808c85..9b7b18e9 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,4 +1,3 @@ -import "dotenv/config"; import { Buffer } from "node:buffer"; import EventEmitter from "node:events"; import { createServer } from "node:http"; diff --git a/src/app.ts b/src/app.ts index 391ef03c..5844b80a 100644 --- a/src/app.ts +++ b/src/app.ts @@ -18,9 +18,6 @@ esmBot will continue to run past this message in 5 seconds, but keep in mind tha await new Promise((resolve) => setTimeout(resolve, 5000)); } -// load config from .env file -import "dotenv/config"; - if (process.env.SENTRY_DSN && process.env.SENTRY_DSN !== "") await import("./utils/sentry.ts"); if (!process.env.TOKEN) { diff --git a/src/cluster/node.ts b/src/cluster/node.ts index a7b94969..3b033ee3 100644 --- a/src/cluster/node.ts +++ b/src/cluster/node.ts @@ -1,4 +1,3 @@ -import "dotenv/config"; import cluster, { type Worker } from "node:cluster"; import process from "node:process"; import detectRuntime from "#utils/detectRuntime.js"; diff --git a/src/database.ts b/src/database.ts index d68df9e4..c01ad058 100644 --- a/src/database.ts +++ b/src/database.ts @@ -1,5 +1,4 @@ // wrapper for the database drivers in ./database/ -import "dotenv/config"; import process from "node:process"; import detectRuntime from "#utils/detectRuntime.js"; import logger from "#utils/logger.js"; diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 40314e54..8b77ac60 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -1,7 +1,6 @@ import { execFile as baseExecFile } from "node:child_process"; import process from "node:process"; -import util, { promisify } from "node:util"; -import { type DotenvParseOutput, config } from "dotenv"; +import util from "node:util"; import { ActivityTypes, type AnyChannel, @@ -23,7 +22,7 @@ let broadcast = false; export async function getVers() { process.env.ESMBOT_VER = packageJson.version; - const execFile = promisify(baseExecFile); + const execFile = util.promisify(baseExecFile); process.env.GIT_REV = await execFile("git", ["rev-parse", "HEAD"]).then( (output) => output.stdout.substring(0, 7), @@ -66,6 +65,8 @@ const optionalReplace = (token: string) => { return token === undefined || token === "" ? "" : token === "true" || token === "false" ? token : ""; }; +const sensitiveVars = ["TOKEN", "DB", "KLIPY", "REST_PROXY", "SENTRY_DSN", "OUTPUT", "TEMPDIR"]; + // clean(text) to clean message of any private info or mentions export function clean(input: string | Error, remove: string[] = [], skipEnv = false) { let text = input; @@ -78,9 +79,6 @@ export function clean(input: string | Error, remove: string[] = [], skipEnv = fa text = text.replaceAll("`", `\`${String.fromCharCode(8203)}`).replaceAll("@", `@${String.fromCharCode(8203)}`); if (!skipEnv) { - let { parsed } = config({ quiet: true }); - if (!parsed) parsed = process.env as DotenvParseOutput; - if (servers.length !== 0) { for (const { server, auth } of servers) { text = text.replaceAll(server, optionalReplace(server)); @@ -88,8 +86,10 @@ export function clean(input: string | Error, remove: string[] = [], skipEnv = fa } } - for (const env of Object.keys(parsed)) { - text = text.replaceAll(parsed[env], optionalReplace(parsed[env])); + for (const env of sensitiveVars) { + if (process.env[env] && process.env[env].length > 0) { + text = text.replaceAll(process.env[env], optionalReplace(process.env[env])); + } } }