4.7 KiB
4.7 KiB
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 runtime
- Discord bot token
- Replicate API token
Environment Variables
Create a .env file:
DISCORD_TOKEN=your_discord_token
REPLICATE_API_TOKEN=your_replicate_token
Installation
bun install
Database Setup
# Generate migrations
bun run db:generate
# Run migrations
bun run db:migrate
Running
# Development (with hot reload)
bun run dev
# Production
bun run start
# Build
bun run build
Adding New Features
Adding a Command
- Create a new file in
src/commands/definitions/:
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
- Create a new file in
src/events/handlers/:
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
},
};
- Register it in
src/events/register.ts
Adding a New AI Provider
- Implement the
AiProviderinterface insrc/services/ai/:
import type { AiProvider, AiResponse, AskOptions } from "./types";
export class MyProvider implements AiProvider {
async health(): Promise<boolean> {
return true;
}
async ask(options: AskOptions): Promise<AiResponse> {
// Implementation
}
}
- Use it in
AiServiceconstructor
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