66 lines
1.9 KiB
Markdown
66 lines
1.9 KiB
Markdown
# Kyoko - Discord Rpg
|
|
|
|
A Discord bot built with [Bun](https://bun.sh), [Discord.js](https://discord.js.org/), and [Drizzle ORM](https://orm.drizzle.team/).
|
|
|
|
## Architecture
|
|
|
|
This project uses a modular architecture:
|
|
|
|
- **`src/index.ts`**: Entry point. initializes the client.
|
|
- **`src/lib/KyokoClient.ts`**: Custom Discord Client wrapper handling command loading and events.
|
|
- **`src/lib/env.ts`**: **Centralized Environment Configuration**. Validates environment variables using `zod` at startup.
|
|
- **`src/lib/DrizzleClient.ts`**: Database client instance.
|
|
- **`src/commands/`**: Command files.
|
|
- **`src/db/`**: Database schema and migrations.
|
|
|
|
## Setup
|
|
|
|
1. **Install Dependencies**:
|
|
```bash
|
|
bun install
|
|
```
|
|
|
|
2. **Environment Variables**:
|
|
Copy `.env.example` to `.env` (create one if it doesn't exist) and fill in the required values:
|
|
```env
|
|
DISCORD_BOT_TOKEN=your_token_here
|
|
DISCORD_CLIENT_ID=your_client_id
|
|
DISCORD_GUILD_ID=your_guild_id_optional
|
|
DATABASE_URL=postgres://user:pass@localhost:5432/db_name
|
|
```
|
|
*Note: The app will fail to start if `DISCORD_BOT_TOKEN` or `DATABASE_URL` are missing or invalid.*
|
|
|
|
3. **Run Development**:
|
|
```bash
|
|
bun run dev
|
|
```
|
|
|
|
4. **Database Migrations**:
|
|
```bash
|
|
bun run db:push # Apply schema changes
|
|
bun run generate # Generate migrations
|
|
```
|
|
|
|
## Deployment
|
|
|
|
### Manual Command Registration
|
|
Since command registration is decoupled from startup, you must run this manually when you add or change commands.
|
|
|
|
**Option 1: Using Docker (Recommended)**
|
|
Uses the credentials configured in `docker-compose.yml`.
|
|
```bash
|
|
docker compose run --rm app bun run deploy
|
|
```
|
|
|
|
**Option 2: Running Locally**
|
|
Requires valid `.env` file with `DISCORD_CLIENT_ID`.
|
|
```bash
|
|
bun run deploy
|
|
```
|
|
|
|
## Development Features
|
|
|
|
- **Type Safety**: Full TypeScript support.
|
|
- **Env Validation**: `zod` ensures all required env vars are present.
|
|
- **Hot Reloading**: `bun --watch` for fast development.
|