Directory Tree
Module Responsibilities
Entry Point
src/index.ts
Main application entry point that orchestrates bot startup.
Responsibilities:
- Validate environment variables (Discord token)
- Create and configure the Discord client
- Register commands and events
- Login to Discord
- Handle uncaught errors
~/workspace/source/src/index.ts
Client Layer
src/client/StreamerBot.ts
Extended Discord.js client with custom functionality.
Properties:
commands: Collection<string, Command>- Registered slash commands
updateActivity()- Update bot status with streamer/server countstartActivityRotation(intervalMs)- Auto-refresh bot statusregisterCommand(command)- Add command to collectiongetCommand(name)- Retrieve command by name
~/workspace/source/src/client/StreamerBot.ts:15-76
Commands
Slash commands registered with Discord’s application command system.src/commands/streamer/add.ts
Command: /streamer add <platform> <username>
Flow:
- Validate platform and username
- Fetch current stream status
- Show channel selector embed
- User selects notification channel
- Save streamer to database
- Show success embed
ManageChannels
src/commands/streamer/remove.ts
Command: /streamer remove
Flow:
- Fetch guild’s tracked streamers
- Show streamer selector menu
- User selects streamer to remove
- Show confirmation buttons (Yes/Cancel)
- Remove from database
- Show success embed
ManageChannels
src/commands/streamer/list.ts
Command: /streamer list
Flow:
- Fetch all tracked streamers for guild
- Generate paginated embed (10 per page)
- Show navigation buttons if multiple pages
- Display: platform emoji, username, channel, live status
src/commands/util/help.ts
Command: /help
Interactive help menu with platform selector showing supported streaming services.
src/commands/util/ping.ts
Command: /ping
Shows bot latency (WebSocket heartbeat).
All commands use ephemeral responses (visible only to command user) until final confirmation.
Components
Reusable Discord UI components.src/components/embeds.ts
Embed builders for consistent styling:
createLiveEmbed(status)- Live alert embed with platform colorscreateSuccessEmbed(message)- Green success messagecreateErrorEmbed(message)- Red error messagecreateInfoEmbed(message)- Blue informational messagecreateStreamerListEmbed(streamers, page)- Paginated list view
src/components/buttons.ts
Button components:
createWatchButtonRow(url, platform)- “Watch on [Platform]” link buttoncreateConfirmationButtons()- Yes/Cancel action buttonscreatePaginationButtons(page, total)- Previous/Next navigation
src/components/menus.ts
Select menu components:
createChannelSelectMenu()- Channel picker for notificationscreateStreamerSelectMenu(streamers)- Streamer removal menucreatePlatformSelectMenu()- Help menu platform selector
Database
src/database/index.ts
JSON file-based storage with in-memory cache.
Data Structure:
| Function | Description |
|---|---|
getGuildSettings(guildId) | Get or create guild settings |
getStreamers(guildId) | Get all streamers for guild |
getStreamer(guildId, streamerId) | Get single streamer |
addStreamer(guildId, streamer) | Add new streamer (no duplicates) |
removeStreamer(guildId, streamerId) | Remove streamer |
updateStreamer(guildId, id, data) | Update single streamer |
updateStreamers(guildId, streamers) | Batch update all streamers |
createStreamerId(platform, username) | Generate ID: “platform:username” |
parseStreamerId(id) | Parse ID into parts |
getAllGuildsWithStreamers() | Get all guilds with tracked streamers |
getTotalStreamerCount() | Count streamers across all guilds |
- Load from
data/guilds.jsonon module import - Maintain in-memory
Map<string, GuildSettings> - Save to disk on every write operation
- Auto-create data directory if missing
~/workspace/source/src/database/index.ts
Events
src/events/ready.ts
Handles Discord ready event when bot comes online.
Actions:
- Log bot username and guild count
- Start activity rotation (30s interval)
- Create and start stream poller (60s interval)
~/workspace/source/src/events/ready.ts
src/events/interactionCreate.ts
Routes Discord interactions to appropriate handlers:
- ChatInputCommand → Command execution
- Button → Button handler
- SelectMenu → Select menu handler
Handlers
src/handlers/buttons.ts
Handles button click interactions:
- Confirmation buttons (Yes/Cancel for removals)
- Pagination buttons (Previous/Next for lists)
src/handlers/selectMenus.ts
Handles select menu interactions:
- Channel selection (for adding streamers)
- Streamer selection (for removing streamers)
- Platform selection (for help menu)
Platforms
src/platforms/index.ts
Platform checker registry and factory.
Exports:
Individual Platform Checkers
Each platform module exports a checker function:kick.ts- Kick.com HTML parsertwitch.ts- Twitch GraphQL APIyoutube.ts- YouTube HTML parserrumble.ts- Rumble HTML parsertiktok.ts- TikTok HTML parser
Services
src/services/StreamPoller.ts
Polling engine that checks stream status periodically.
Class: StreamPoller
Methods:
start()- Begin polling loopstop()- Stop polling looppoll()- Execute single poll cycle (private)checkGuildStreamers(guildId, streamers)- Check all streamers for a guild (private)checkStreamer(streamer)- Fetch status for one streamer (private)processStatus(guildId, streamer, status)- Handle status update and send alerts (private)
~/workspace/source/src/services/StreamPoller.ts
src/services/AlertService.ts
Alert sending service.
Function: sendLiveAlert(client, channelId, status)
Process:
- Fetch Discord channel
- Validate channel is text-based
- Create live embed
- Create watch button
- Send message
- Log result
~/workspace/source/src/services/AlertService.ts:10-39
Types
src/types/streamer.ts
Streamer data types:
src/types/discord.ts
Discord.js extension types:
Utilities
src/utils/constants.ts
Application-wide constants.
Exports:
PLATFORMS- Platform metadata (name, color, emoji, URL template)POLL_INTERVAL- 60000ms (60 seconds)ITEMS_PER_PAGE- 10 (for pagination)Colors- Embed color schemeFOOTER- Standard embed footerPLATFORM_CHOICES- Slash command choices
~/workspace/source/src/utils/constants.ts:50-52
src/utils/formatters.ts
Display formatting utilities:
- Number formatting (1234 → “1,234”)
- Time formatting (“2 hours ago”)
- Username sanitization
src/utils/logger.ts
Structured logging utility:
The project follows a domain-driven structure where related functionality is grouped into logical modules (commands, services, platforms, etc.).
Build and Output
TypeScript Compilation
- Target: ES2020
- Module: ESNext
- Module Resolution: Node16 (for
.jsimports) - Strict mode enabled
Runtime Files
node dist/index.js
Configuration Files
.env
package.json
Key scripts:
The project uses ES modules (
.js file extensions in imports) for modern Node.js compatibility.