Setup elysia eden in bot

This commit is contained in:
Dominic Ferrando
2026-08-15 16:37:35 -04:00
parent 1b886e4744
commit a4e7060538
4 changed files with 47 additions and 4 deletions
+4 -1
View File
@@ -3,9 +3,12 @@
"module": "index.ts",
"type": "module",
"private": true,
"devDependencies": {},
"devDependencies": {
"@blade-and-brawn/api": "workspace:*"
},
"peerDependencies": {},
"dependencies": {
"@elysia/eden": "^1.4.10",
"discord.js": "^14.27.0"
},
"scripts": {
+3 -1
View File
@@ -1,7 +1,9 @@
import { Client, Events, GatewayIntentBits } from 'discord.js';
import { CommandService } from './services/cmd/service';
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});
// SERVICES
// -----------------------
+38
View File
@@ -0,0 +1,38 @@
import cluster from "node:cluster";
import { pino } from "pino";
import { treaty } from '@elysia/eden';
import { type API } from "@blade-and-brawn/api";
export const log = pino({
level: Bun.env.LOG_LEVEL ?? "info",
transport: Bun.env.NODE_ENV != "production"
? { target: "pino-pretty" }
: undefined,
});
export const env = {
PUBLIC_API_URL: requireEnv("PUBLIC_API_URL"),
BOT_TOKEN: requireEnv("BOT_TOKEN"),
};
export const api = treaty<API>(env.PUBLIC_API_URL ?? "");
function requireEnv(key: string): string {
const val = Bun.env[key];
if (!val) {
if (cluster.worker?.id === 1)
log.error({ name: key }, "Missing required environment variable");
throw new Error(`Missing required environment variable: ${key}`)
};
return val;
}
function optionEnv(key: string, fallback: string = ""): string {
const val = Bun.env[key];
if (!val) {
if (cluster.worker?.id === 1)
log.warn({ name: key }, `Missing optional environmental variable, falling back to "${fallback}"`)
return fallback
};
return val;
}