How deyoyk/rankedbedwars works
Project type and purpose
• This is a Python-based Discord bot (“ranked bedwars discord bot”) that integrates with an external “rbw-hook” to pull in-game events from Bedwars (bedwars1058) and manages ranked game logic (queues, scoring, leaderboards, punishments) via Discord commands.
• Key use cases:
• Real-time game event handling via WebSocket
• Slash-command and prefix-command processing in Discord
• Persistent storage of players, games, queues, ELO scores, punishments, themes, etc.
File structure for architectural patterns
• Entry point: bot.py
• Core directories:
• commands/ – command handlers grouped by domain (admin, dev, game, party, player)
• events/ – listeners for Discord events (guild join, voice channel nuke, message nuke, queue join)
• actions/ – discrete units of logic (fix, score image, transcript creation, voiding, etc.)
• managers/ – façade or service classes that orchestrate high-level operations and state (API, database, command dispatch, event dispatch, mute, ban, strikes, party, queue processing, screenshare, permission, websocket)
• managers/websocket/ – WebSocket client, message models, handlers for game, player, queue, scoring, screenshare, voice
• utils/ – helper modules (ELO decay, embed builder, Discord utilities, error handler, daily resets)
• asserts/ – static assets (fonts, themes, games/punishments images)
• themes/ – embed/theme definitions (elite, lunar, rich, y2k)
• configs/ – YAML configuration (bot settings, permissions, season info)
• Persistence: requires MongoDB (recommended to run in same region), accessed via managers/database_manager.py
• Dependencies: Python 3.13.5, discord.py (or equivalent), PyMongo, websockets
Extract architecture hints from README
• Real-time integration: “rbw-hook-public” WebSocket feed
• Persists state in MongoDB
• Command/event-driven, modular architecture
Main components & interactions
A. External Services
• Discord Gateway & REST API
• rbw-hook WebSocket server (in-game events source)
• MongoDB instance
B. Bot Application
• bot.py (startup & orchestration)
• EventManager (registers listeners from events/)
• CommandManager (routes incoming commands to handlers in commands/)
• WebSocketManager (connects to in-game hook, dispatches to websocket/handlers/)
• DatabaseManager (CRUD operations for players, games, queues, etc.)
• APIManager (if any external HTTP calls)
• Other managers: BanManager, MuteManager, PermissionManager, PartyManager, QueueProcessor, StrikesManager, ScreenshareManager
C. Feature Modules
• Commands (admin, dev, game, party, player) invoking business logic
• Actions (self-contained units for scoring, transcripts, scoring images)
• Themes & Assets (embed templates & static resources)
• Utils (helper routines)
Relationships & data flow
1. Bot -> Discord Gateway: receives events (messages, reactions, voice updates), sends messages/embeds
2. Bot -> CommandManager: user invokes command → resolved to specific handler → calls the appropriate Manager(s) or Action(s) → may read/write to DatabaseManager → send response back to user
3. WebSocketManager -> rbw-hook WebSocket: receives real-time game events → dispatches to handlers (game_handler, scoring_handler, etc.) → may trigger Actions or update DB
4. DatabaseManager <-> MongoDB: persistent storage for player profiles, scores, queues, punishments
5. Managers <-> Utils & Themes: build embeds, handle errors, apply ELO decay, format output
Architectural patterns & principles
• Event-driven architecture: separation of event listeners (Discord vs WebSocket)
• Command pattern: encapsulating each slash/prefix command in its own module
• Manager/service layer: single responsibility services for domain logic
• Modular plugin-like structure: commands, actions, themes, websocket handlers can be extended independently
• Asynchronous I/O: nonblocking calls to Discord, WebSocket, DB
Final checklist
– All major components (Discord, WebSocket hook, Bot core, DB, Command/Event/Action modules)
– Clear boundaries (bot vs external systems vs persistence vs static assets)
– Notes on key patterns (async event loop, manager layer, command routing)