Setup elysia eden in bot
This commit is contained in:
@@ -3,9 +3,12 @@
|
|||||||
"module": "index.ts",
|
"module": "index.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {},
|
"devDependencies": {
|
||||||
|
"@blade-and-brawn/api": "workspace:*"
|
||||||
|
},
|
||||||
"peerDependencies": {},
|
"peerDependencies": {},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@elysia/eden": "^1.4.10",
|
||||||
"discord.js": "^14.27.0"
|
"discord.js": "^14.27.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { Client, Events, GatewayIntentBits } from 'discord.js';
|
import { Client, Events, GatewayIntentBits } from 'discord.js';
|
||||||
import { CommandService } from './services/cmd/service';
|
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
|
// 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;
|
||||||
|
}
|
||||||
@@ -37,10 +37,11 @@
|
|||||||
"apps/bot": {
|
"apps/bot": {
|
||||||
"name": "@blade-and-brawn/bot",
|
"name": "@blade-and-brawn/bot",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@elysia/eden": "^1.4.10",
|
||||||
"discord.js": "^14.27.0",
|
"discord.js": "^14.27.0",
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bun": "^1.3.14",
|
"@blade-and-brawn/api": "workspace:*",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"apps/portal": {
|
"apps/portal": {
|
||||||
@@ -59,7 +60,6 @@
|
|||||||
"@blade-and-brawn/api": "workspace:*",
|
"@blade-and-brawn/api": "workspace:*",
|
||||||
"@sveltejs/kit": "^2.70.2",
|
"@sveltejs/kit": "^2.70.2",
|
||||||
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
||||||
"@types/bun": "^1.3.14",
|
|
||||||
"elysia": "^1.4.29",
|
"elysia": "^1.4.29",
|
||||||
"svelte": "^5.56.9",
|
"svelte": "^5.56.9",
|
||||||
"svelte-adapter-bun": "^1.0.1",
|
"svelte-adapter-bun": "^1.0.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user