Added ENV management

This commit is contained in:
fzzinchemical
2025-04-02 19:30:28 +02:00
parent e24bae3322
commit d00df57aea
3 changed files with 27 additions and 7 deletions

View File

@@ -1,12 +1,11 @@
import { createBot, Intents, startBot } from "npm:discordeno@18.0.1"; import { createBot, Intents, startBot } from "npm:discordeno@18.0.1";
import { messagehandler } from "./messages.ts"; import { messagehandler } from "./messages.ts";
import { EnvConst, loadConfig } from "@root/core/configLoader.ts";
const env: EnvConst = loadConfig()
const BOT_TOKEN = Deno.env.get("BOT_TOKEN") ?? "";
if (!BOT_TOKEN) {
throw new Error("BOT_TOKEN is missing!");
}
const bot = createBot({ const bot = createBot({
token: BOT_TOKEN, token: env.BOT_TOKEN,
intents: Intents.Guilds | Intents.GuildMessages | Intents.MessageContent | intents: Intents.Guilds | Intents.GuildMessages | Intents.MessageContent |
Intents.DirectMessages, Intents.DirectMessages,
events: { events: {

21
src/core/configLoader.ts Normal file
View File

@@ -0,0 +1,21 @@
export type EnvConst = {
ADMIN: string,
BOT_TOKEN: string,
// DB_LOCATION: string
}
export function loadConfig() {
return {
ADMIN: loadEnv("ADMIN"),
BOT_TOKEN: loadEnv("BOT_TOKEN"),
// DB_LOCATION: loadEnv("DB_LOCATION")
}
}
function loadEnv(name: string) {
const env = Deno.env.get(name)
if (env === undefined) {
throw new Error(`ENV ${name} is missing!`);
}
return env
}

View File

@@ -1,4 +1,4 @@
import { Bot, Message } from "npm:discordeno@18.0.1"; import { Bot, DiscordEmbedAuthor, Message } from "npm:discordeno@18.0.1";
import { drop, help, requestWorker } from "./plugin.ts"; import { drop, help, requestWorker } from "./plugin.ts";
import { logMessage } from "@root/logging.ts"; import { logMessage } from "@root/logging.ts";
import { defaultString } from "@root/defaultString.ts"; import { defaultString } from "@root/defaultString.ts";