refactor: Refactor interaction handling and event management

- Updated interactionCreate event to improve error handling and logging.
- Enhanced ready event to ensure client user is available before proceeding.
- Refactored voiceStateUpdate event for better clarity and error handling.
- Adjusted index.ts to improve client initialization and command/event loading.
- Improved Shoukaku event handling and initialization in ShoukakuEvents.ts.
- Enhanced logger utility for better message formatting.
- Updated TypeScript configuration for better compatibility and strictness.
- Created a new botClient type definition for improved type safety.
This commit is contained in:
2025-04-24 23:42:36 +08:00
parent c42e0931d6
commit 72a59bbcdd
18 changed files with 1088 additions and 984 deletions

View File

@@ -8,6 +8,7 @@ Discord music bot template written in TypeScript using `discord.js` and `shoukak
- `shoukaku` integration for robust Lavalink audio playback
- Modular command and event handlers written in TypeScript
- Basic Docker support (`Dockerfile`, `docker-compose.yml`)
- Comprehensive test suite with Jest
## Prerequisites
@@ -83,6 +84,51 @@ Discord music bot template written in TypeScript using `discord.js` and `shoukak
pnpm start # Check package.json for the exact start script (might run compiled JS or use ts-node)
```
## Testing
The project includes a comprehensive test suite using Jest. The tests cover commands, events, and utilities.
### Running Tests
```bash
# Run all tests with coverage report
pnpm test
# Run tests in watch mode during development
pnpm test:watch
# Run tests in CI environment
pnpm test:ci
```
### Test Structure
```
tests/
├── commands/ # Tests for bot commands
│ ├── join.test.ts
│ ├── leave.test.ts
│ ├── ping.test.ts
│ └── play.test.ts
├── events/ # Tests for event handlers
│ ├── interactionCreate.test.ts
│ ├── ready.test.ts
│ └── voiceStateUpdate.test.ts
└── utils/ # Test utilities and mocks
├── setup.ts # Jest setup and global mocks
├── testUtils.ts # Common test utilities
└── types.ts # TypeScript types for tests
```
### Coverage Requirements
The project maintains high test coverage requirements:
- Branches: 80%
- Functions: 80%
- Lines: 80%
- Statements: 80%
## Docker
A `Dockerfile` and `docker-compose.yml` are provided for containerized deployment.
@@ -100,22 +146,20 @@ A `Dockerfile` and `docker-compose.yml` are provided for containerized deploymen
.
├── src/ # Source code directory
│ ├── commands/ # Slash command modules (.ts)
│ ├── events/ # Discord.js and Shoukaku event handlers (.ts)
│ ├── structures/ # Custom structures or base classes (e.g., Shoukaku event handlers)
── utils/ # Utility functions (e.g., logger.ts)
│ └── index.ts # Main application entry point
├── plugins/ # Lavalink plugins (e.g., youtube-plugin-*.jar)
├── tests/ # Test files
├── .env.example # Example environment variables
├── .gitignore
├── application.yml # Lavalink server configuration
├── deploy-commands.ts # Script to register slash commands
├── docker-compose.yml # Docker Compose configuration for bot + Lavalink
├── Dockerfile # Dockerfile for building the bot image
├── LICENSE # Project License (GPLv3)
── package.json # Node.js project manifest
├── tsconfig.json # TypeScript compiler options
└── update-plugin.sh # Script to update Lavalink plugins (example)
│ ├── events/ # Discord.js and Shoukaku event handlers (.ts)
│ ├── structures/ # Custom structures or base classes (e.g., Shoukaku event handlers)
── utils/ # Utility functions (e.g., logger.ts)
├── tests/ # Test files (see Testing section)
├── plugins/ # Lavalink plugins (e.g., youtube-plugin-*.jar)
├── .env.example # Example environment variables
├── application.yml # Lavalink server configuration
├── deploy-commands.ts # Script to register slash commands
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Dockerfile for building the bot image
├── jest.config.ts # Jest test configuration
├── package.json # Node.js project manifest
├── tsconfig.json # TypeScript compiler options
── update-plugin.sh # Script to update Lavalink plugins
```
## License