diff --git a/bot/example/conf.json5 b/bot/example/conf.json5 index d0023f53a..360e88067 100644 --- a/bot/example/conf.json5 +++ b/bot/example/conf.json5 @@ -11,7 +11,6 @@ CLIENT_SECRET: "CSfoobar", CLIENT_ID: "CIfoobar", }, - MONGO_URL: "mongodb://127.0.0.1:27017", DISCORD: { TOKEN: "foobar", SERVER_ID: "123123123", diff --git a/bot/example/example.env b/bot/example/example.env new file mode 100644 index 000000000..c7c7311d9 --- /dev/null +++ b/bot/example/example.env @@ -0,0 +1,2 @@ +MONGO_URL="127.0.0.1:27017/tachi_bot_db" +NODE_ENV="dev" \ No newline at end of file diff --git a/bot/src/config.ts b/bot/src/config.ts index 09516182c..33d876f87 100644 --- a/bot/src/config.ts +++ b/bot/src/config.ts @@ -29,7 +29,6 @@ export interface BotConfig { CLIENT_SECRET: string; CLIENT_ID: string; }; - MONGO_URL: string; DISCORD: { TOKEN: string; SERVER_ID: string; @@ -93,6 +92,7 @@ function ParseBotConfig(fileLoc = "conf.json5"): BotConfig { export interface ProcessEnvironment { nodeEnv: "production" | "dev" | "staging" | "test"; + mongoUrl: string; } function ParseEnvVars() { @@ -100,9 +100,11 @@ function ParseEnvVars() { process.env, { NODE_ENV: p.isIn("production", "dev", "staging", "test"), + // mei implicitly reads this. LOG_LEVEL: p.optional( p.isIn("debug", "verbose", "info", "warn", "error", "severe", "crit") ), + MONGO_URL: "string", }, {}, { allowExcessKeys: true } @@ -116,6 +118,7 @@ function ParseEnvVars() { return { nodeEnv: process.env.NODE_ENV, + mongoUrl: process.env.MONGO_URL, } as ProcessEnvironment; } diff --git a/bot/src/database/mongo.ts b/bot/src/database/mongo.ts index 9637f114b..6568e0418 100644 --- a/bot/src/database/mongo.ts +++ b/bot/src/database/mongo.ts @@ -1,15 +1,15 @@ import { Snowflake } from "discord.js/typings/index.js"; import monk from "monk"; import { integer } from "tachi-common"; +import { ProcessEnv } from "../config"; import { LoggerLayers } from "../data/data"; -import { BotConfig } from "../config"; import { CreateLayeredLogger } from "../utils/logger"; const logger = CreateLayeredLogger(LoggerLayers.database); -logger.info(`Connecting to ${BotConfig.MONGO_URL}...`); +logger.info(`Connecting to ${ProcessEnv.mongoUrl}...`); -const monkDB = monk(BotConfig.MONGO_URL); +const monkDB = monk(ProcessEnv.mongoUrl); monkDB .then(() => { diff --git a/bot/src/interactionHandlers/handleIsCommand.ts b/bot/src/interactionHandlers/handleIsCommand.ts index 956369f98..d426eb721 100644 --- a/bot/src/interactionHandlers/handleIsCommand.ts +++ b/bot/src/interactionHandlers/handleIsCommand.ts @@ -1,7 +1,7 @@ import { CommandInteraction } from "discord.js"; +import { SLASH_COMMANDS } from "../commands/commands"; import { LoggerLayers } from "../data/data"; import { DiscordUserMapDocument } from "../database/mongo"; -import { SLASH_COMMANDS } from "../slashCommands/register"; import { CreateLayeredLogger } from "../utils/logger"; const logger = CreateLayeredLogger(LoggerLayers.slashCommands);