feat: implement branded discord embeds and versioning

This commit is contained in:
syntaxbullet
2026-01-14 16:10:23 +01:00
parent 6e57ab07e4
commit 4af2690bab
13 changed files with 291 additions and 9 deletions

View File

@@ -0,0 +1,30 @@
### Context & Goal
Currently, every command manually performs checks like user existence or maintenance mode, or these are hardcoded into the `CommandHandler`. Standardizing these requirements in the command definition itself makes the code cleaner and more declarative.
### Dependencies
- None
### Affected Files
- `shared/lib/types.ts`: Update `Command` interface to include a optional `requirements` object.
- `bot/lib/handlers/CommandHandler.ts`: Update to read and enforce these requirements.
- `bot/commands/economy/balance.ts`: Refactor to use the new requirements (example).
### Technical Constraints & Strategy
- Implementation: Use a standardized `requirements` object in the `Command` interface.
- Requirements could include: `userExists: boolean`, `permissions: string[]`, `devOnly: boolean`.
- Ensure `CommandHandler` provides clear error messages to the user when a requirement fails.
### Definition of Done (Binary)
- [ ] `Command` interface updated in `types.ts`.
- [ ] `CommandHandler.ts` enforces requirements before executing command.
- [ ] At least one command (e.g., `balance`) is refactored to use the new system.
- [ ] Clear error embeds are shown to the user when requirements aren't met.
### New Test Files
- None (Verification via manual testing of command execution).

View File

@@ -0,0 +1,31 @@
### Context & Goal
The bot currently relies on `console.error` which is hard to track and lacks context. A centralized error logging service will allow for better debugging, persistent error logs, and future integration with services like Sentry or Discord webhooks for alerts.
### Dependencies
- None
### Affected Files
- `shared/lib/logger.ts`: New file for the unified logger service.
- `bot/lib/handlers/CommandHandler.ts`: Update to use the new logger for command errors.
- `web/src/server.ts`: Update to use the new logger for API and WebSocket errors.
### Technical Constraints & Strategy
- Implementation: Create a `Logger` class/object in `shared/lib`.
- Support log levels: `info`, `warn`, `error`, `debug`.
- Errors should capture: timestamp, source (bot/web), error message, and stack trace if available.
- For now, logging to console and a local log file (e.g., `logs/error.log`) is sufficient.
### Definition of Done (Binary)
- [ ] `Logger` service implemented in `shared/lib/logger.ts`.
- [ ] Command errors are logged via the new service.
- [ ] Web server errors are logged via the new service.
- [ ] Log output is formatted consistently.
### New Test Files
- `shared/lib/logger.test.ts`: Verify logger output and file writing.

View File

@@ -0,0 +1,32 @@
### Context & Goal
The current `web/src/server.ts` is a monolithic file with a very long `fetch` handler. This makes it difficult to read and maintain. Modularizing the logic into separate route handlers and middleware-like functions will improve code quality and scalability.
### Dependencies
- None
### Affected Files
- `web/src/server.ts`: Refactor to use modular handlers.
- `web/src/routes/api.ts`: New file for API route definitions.
- `web/src/routes/static.ts`: New file for static file serving logic.
- `web/src/routes/websocket.ts`: New file for WebSocket event handling.
### Technical Constraints & Strategy
- Implementation: Move different responsibilities (API, Static, WS) into separate files.
- The main `serve` configuration should just call these modules.
- Ensure the SPA fallback logic remains intact.
### Definition of Done (Binary)
- [ ] `web/src/server.ts` length reduced by at least 50%.
- [ ] API routes moved to dedicated module.
- [ ] Static file serving moved to dedicated module.
- [ ] WebSocket logic moved to dedicated module.
- [ ] Dashboard still loads and functions correctly.
### New Test Files
- None (Verification via manual testing of the dashboard).

View File

@@ -0,0 +1,28 @@
### Context & Goal
Enhance the user experience by standardizing the look and feel of Discord embeds. Adding consistent branding like a custom footer (with version info) and using the bot's accent color will make the bot feel more professional.
### Dependencies
- None
### Affected Files
- `bot/lib/embeds.ts`: Update standard embed creators.
- `shared/lib/constants.ts`: Add branding-related constants (colors, footer text).
### Technical Constraints & Strategy
- Implementation: Update `createBaseEmbed` and other helpers to automatically include footers and standard colors.
- Use info from `package.json` for versioning in the footer.
- Ensure the changes don't break existing layouts where custom colors might be needed.
### Definition of Done (Binary)
- [x] All standard embeds now include a consistent footer.
- [x] Embeds use a predefined brand color by default.
- [x] Version number is automatically pulled for the footer.
### New Test Files
- None.

View File

@@ -0,0 +1,29 @@
### Context & Goal
The `exam` command currently contains a lot of business logic, including reward calculations, timer management, and complex database transactions. Moving this logic to a dedicated `ExamService` will improve testability, maintainability, and keep the command file focused on user interaction.
### Dependencies
- None
### Affected Files
- `shared/modules/economy/exam.service.ts`: New file for the exam logic.
- `bot/commands/economy/exam.ts`: Refactor to use the new service.
### Technical Constraints & Strategy
- Implementation: Create an `ExamService` that handles `getExamStatus`, `takeExam`, and `registerForExam`.
- The command should only handle user input and formatting the response embeds based on the service's result.
- Ensure the Drizzle transactions are correctly handled within the service.
### Definition of Done (Binary)
- [ ] `ExamService` implemented with methods for all exam-related operations.
- [ ] `bot/commands/economy/exam.ts` refactored to use the service.
- [ ] Logic is covered by unit tests in a new test file.
- [ ] Manual verification shows the exam command still works as expected.
### New Test Files
- `shared/modules/economy/exam.service.test.ts`: Unit tests for reward calculations and state transitions.