PartBot's layout can be broadly broken down into three 'core' modules and various 'helper' modules.
- PS
- Discord
- Web
and
- Globals
- Cache
- Database
- I18n (internationalization for translations)
- Secrets
- Sentinel
- Utils
The PS module has three parts - commands, handlers, and loaders.
The commands directory stores all PS commands. A single file can export one or multiple commands, and each
command has configuration options. Folders can be used when a single source has too much complexity to be one
file (eg: games).
Commands may be either .ts or .tsx files - the .tsx extension is required to enable JSX syntax in the code.
Commands that output JSX must use one of the *HTML methods to work! message.reply(JSX) will not work; use
message.replyHTML(JSX) instead.
The handlers directory contains all PS event handlers as well as permissions management. Read the source code for
more details.
The loaders directory contains code to load data into cache (such as entries from a database, or command cache).
This lets the bot synchronize data such as alts and roomconfigs.
The Discord module manages the bot's Discord integration using discord.js. Like PS, it has three main parts - commands, handlers, and loaders.
The commands directory stores all Discord slash commands. Each command file exports a command with configuration including the slash command builder, handler function, and permissions.
The handlers directory contains event handlers for Discord events, primarily interaction handling (slash commands, buttons, etc.).
The loaders directory contains code to load Discord commands and set up channels. Commands are automatically registered with Discord's API on startup.
The constants directory stores Discord-specific constants such as emotes and server-specific values like channel/guild/role IDs.
The Web module provides HTTP server functionality using Express.js. It serves static files, APIs, and UI components.
The loaders directory contains various loader modules that set up different aspects of the web server:
api.ts- Loads API endpointsbundles.ts- Loads webpack bundlesstatic.ts- Serves static files (images, CSS)ui.ts- Loads UI routeserrors.ts- Sets up error handlingmiddleware.ts- Configures middlewareutil.ts- Utility functions for web loaders
The api directory contains API endpoint handlers for various features like game data, GitHub webhooks, quotes, and the scrabble dictionary.
The ui directory contains server-side rendered UI components using JSX/TSX.
The static directory contains static assets like images for games (chess pieces, splendor cards, etc.).
The Globals module sets up global augmentations and patches to enhance built-in types and functionality.
augment.ts- Extends global types (eg: supporting stuff like psicon)patches.ts- Runtime patches for built-in objects (eg: patching console to remove React warnings)prototypes.ts- Prototype extensions for built-in types (might move this to pro-to-type eventually)
The Cache module provides in-memory and persistent caching for various data:
index.ts- Global cache objects (commands, games, timers, etc.)games.ts- Game backup caching using flat-cachepersisted.ts- Persistent cache utilitiesreset.ts- Cache reset utilities
There are both in-memory caches and caches for file-based persistence.
The Database module handles MongoDB connections using Mongoose. The database connection is optional and controlled by the IS_ENABLED.DB flag.
The Sentinel module provides hot-reloading capabilities by watching for file changes and automatically reloading affected modules.
create.ts- Creates the file watcher using chokidarhotpatch.ts- Handles hot-patching of modulesprocess.ts- Process signal handlerslive.ts- Live reload utilitiesregisters/- Defines patterns and reload handlers for different file types
When a file changes, Sentinel:
- Detects the change via chokidar
- Matches it against registered patterns
- Triggers the appropriate reload handler
- Emits events (start, complete, error) for monitoring
This allows the bot to update commands, handlers, and other modules without requiring a full restart.
The secrets submodule is handled by either of two linked repositories as submodules - PartBot itself uses https://github.com/PartMan7/PartBot-secrets, but owing to the need to keep private information, public sources instead use a public mirror of the same without private information, on https://github.com/PartMan7/PartBot-spoof. If you plan on contributing to the secrets repository, please check the docs for information on how to set this up.