# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

Discord.ts-Buddy is a TypeScript helper library for Discord.js bot development. It provides abstractions for common bot functionality including command handling, permission systems, auto-restart capabilities, and multi-guild bot management.

## Development Commands

### Build & Test
- `npm run build` - Compile TypeScript to JavaScript (production build)
- `npm run build-prod` - Same as build, for production
- `npm run clean` - Remove build artifacts, coverage, tmp, logs, and data directories
- `npm run lint` - Run ESLint on TypeScript files
- `npm run test` - Run full test suite with coverage (includes lint as pretest)
- `npm run test-only` - Run tests without linting
- `npm run test:watch` - Run tests in watch mode
- `npm run test-basic` - Run tests without coverage
- `npm run test-bots` - Run bot-specific tests using separate Jest config

### Publishing
- `npm run publish-npm` - Clean, build, and publish to npm

## Architecture Overview

### Core Components

**BotManager** (`src/logic/botmanager.logic.ts`)
- Handles bot lifecycle management with auto-restart capabilities
- Manages retry attempts and cooldown periods
- Uses RxJS Subjects for event-driven architecture

**MultiGuildBot** (`src/logic/bots/multi-guild-bot.ts`)
- Base class for multi-guild Discord bots
- Implements command parsing for both text messages and slash commands
- Handles permission systems, settings management, and interaction registration
- Uses command design pattern for extensible command system

**Command System**
- Commands implement `ICommand` interface
- Support both message-based and interaction-based input
- Built-in permission system with configurable feedback types
- Settings system allows per-guild configuration

### Key Services

- **MessengerService** - Handles Discord message sending with embed formatting
- **CommandPermissionsService** - Manages command permission validation
- **InteractionRegistryService** - Manages slash command registration with hash-based change detection
- **SoundService** - Handles voice channel audio playback
- **FileObjectService** - File-based storage utilities

### Models & Types

The `src/models/` directory contains TypeScript interfaces and types that define the system's contracts:
- `Command.ts` - Command system interfaces and types
- `DiscordBot.ts` - Bot interface definitions and status enums  
- `CommandPermission.ts` - Permission system types
- `GuildCollection.ts` - Generic guild-keyed collection utilities

## TypeScript Configuration

- Target: ES2020, CommonJS modules
- Strict mode disabled for compatibility
- Source maps enabled for debugging
- Includes both `src/` and `__tests__/` directories

## Testing Setup

- Jest with ts-jest transformer
- Separate configurations for different test types:
  - Main tests: `jest.config.js`
  - Bot tests: `jest/jest.bots.config.js`
  - Azure tests: `jest/jest.azure.config.js`
- Test files use `.spec.ts` or `.test.ts` extensions
- Coverage collection from `src/` directory

## Dependencies

Core dependencies include:
- `discord.js` v14.18.0 - Discord API library
- `@discordjs/voice` - Voice channel support
- `rxjs` v5.5.6 - Reactive extensions for event handling
- `nconf` - Configuration management
- `azure-storage` - Azure Table Storage integration
- `ffmpeg-static` - Audio processing
- `moment` - Date/time utilities

## Development Notes

When extending this library:
1. Follow the command design pattern for new commands
2. Use the permission system for access control
3. Implement proper error handling and logging
4. Test with both message and interaction contexts
5. Consider multi-guild scenarios in your implementations