Added ENV management
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import { createBot, Intents, startBot } from "npm:discordeno@18.0.1";
|
||||
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({
|
||||
token: BOT_TOKEN,
|
||||
token: env.BOT_TOKEN,
|
||||
intents: Intents.Guilds | Intents.GuildMessages | Intents.MessageContent |
|
||||
Intents.DirectMessages,
|
||||
events: {
|
||||
|
||||
21
src/core/configLoader.ts
Normal file
21
src/core/configLoader.ts
Normal 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
|
||||
}
|
||||
@@ -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 { logMessage } from "@root/logging.ts";
|
||||
import { defaultString } from "@root/defaultString.ts";
|
||||
@@ -26,4 +26,4 @@ export async function rule34MessageHandler(bot: Bot, message: Message) {
|
||||
} else {
|
||||
drop();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user