Setup elysia eden in bot
This commit is contained in:
@@ -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
|
||||
// -----------------------
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user