# Joel Discord Bot A Discord bot with AI-powered responses and message tracking. ## Project Structure ``` src/ ├── index.ts # Main entry point ├── core/ # Core infrastructure │ ├── client.ts # Extended Discord client │ ├── config.ts # Configuration management │ └── logger.ts # Logging utility ├── commands/ # Slash commands │ ├── types.ts # Command interfaces │ ├── registry.ts # Command loading │ ├── register.ts # Discord API registration │ ├── handler.ts # Command execution │ └── definitions/ # Command implementations │ ├── ping.ts │ ├── spyware.ts │ ├── sex.ts │ ├── vemgillarjoel.ts │ ├── jaggillarjoel.ts │ └── jaghatarjoel.ts ├── events/ # Discord event handlers │ ├── types.ts # Event interfaces │ ├── register.ts # Event registration │ └── handlers/ # Event implementations │ ├── ready.ts │ ├── message-create.ts │ ├── interaction-create.ts │ └── guild.ts ├── features/ # Feature modules │ ├── joel/ # Joel AI personality │ │ ├── responder.ts # Main response logic │ │ ├── personalities.ts │ │ ├── mentions.ts # Random mention feature │ │ └── typing.ts # Typing indicator │ └── message-logger/ # Message tracking ├── services/ # External services │ └── ai/ # AI provider abstraction │ ├── types.ts # Provider interface │ ├── replicate.ts # Replicate implementation │ └── index.ts # Service facade ├── database/ # Database layer │ ├── schema.ts # Drizzle schema │ ├── connection.ts # DB connection │ ├── migrate.ts # Migration runner │ └── repositories/ # Data access │ ├── guild.repository.ts │ ├── user.repository.ts │ ├── message.repository.ts │ └── memory.repository.ts └── utils/ # Shared utilities ├── discord.ts # Discord helpers ├── random.ts # Random utilities └── time.ts # Time utilities ``` ## Getting Started ### Prerequisites - [Bun](https://bun.sh/) runtime - Discord bot token - Replicate API token ### Environment Variables Create a `.env` file: ```env DISCORD_TOKEN=your_discord_token REPLICATE_API_TOKEN=your_replicate_token ``` ### Installation ```bash bun install ``` ### Database Setup ```bash # Generate migrations bun run db:generate # Run migrations bun run db:migrate ``` ### Running ```bash # Development (with hot reload) bun run dev # Production bun run start # Build bun run build ``` ## Adding New Features ### Adding a Command 1. Create a new file in `src/commands/definitions/`: ```typescript import { SlashCommandBuilder } from "discord.js"; import type { Command } from "../types"; const command: Command = { data: new SlashCommandBuilder() .setName("mycommand") .setDescription("Description"), category: "fun", execute: async (interaction) => { await interaction.reply("Hello!"); }, }; export default command; ``` Commands are auto-loaded from the `definitions/` folder. ### Adding an Event Handler 1. Create a new file in `src/events/handlers/`: ```typescript import { Events } from "discord.js"; import type { EventHandler } from "../types"; export const myEventHandler: EventHandler<"eventName"> = { name: Events.EventName as "eventName", once: false, execute: async (client, ...args) => { // Handle event }, }; ``` 2. Register it in `src/events/register.ts` ### Adding a New AI Provider 1. Implement the `AiProvider` interface in `src/services/ai/`: ```typescript import type { AiProvider, AiResponse, AskOptions } from "./types"; export class MyProvider implements AiProvider { async health(): Promise { return true; } async ask(options: AskOptions): Promise { // Implementation } } ``` 2. Use it in `AiService` constructor ## Architecture Principles - **Separation of Concerns**: Each module has a single responsibility - **Dependency Injection**: Services can be swapped via interfaces - **Repository Pattern**: Database access through repositories - **Event-Driven**: Discord events are handled by dedicated handlers - **Feature Modules**: Related functionality grouped together