Unify all handler signatures and simplify router
- Standardize all handlers to signature: (query, user_id, player, data=None) - Replace 125-line if/elif chain with HANDLER_MAP dictionary - Reduce router code by 90 lines (72% reduction) - Add HANDLER_MAP registry for cleaner organization - Enable future auto-discovery and decorator patterns - Maintain full backward compatibility - Document changes in HANDLER_REFACTORING_V2.md Benefits: - O(1) handler lookup vs O(n) if/elif chain - Add new handlers by just updating the map - Consistent signature makes code easier to understand - Opens doors for middleware and hooks
This commit is contained in:
@@ -9,8 +9,9 @@ from data.world_loader import game_world
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def handle_profile(query, user_id: int, player: dict):
|
||||
"""Show player profile and stats."""
|
||||
async def handle_profile(query, user_id: int, player: dict, data: list = None):
|
||||
"""Display player profile with stats and level info."""
|
||||
from .utils import format_stat_bar
|
||||
await query.answer()
|
||||
from bot import combat
|
||||
from .utils import format_stat_bar, create_progress_bar
|
||||
@@ -70,8 +71,8 @@ async def handle_profile(query, user_id: int, player: dict):
|
||||
)
|
||||
|
||||
|
||||
async def handle_spend_points_menu(query, user_id: int, player: dict):
|
||||
"""Show stat point spending menu."""
|
||||
async def handle_spend_points_menu(query, user_id: int, player: dict, data: list = None):
|
||||
"""Show menu for spending attribute points."""
|
||||
await query.answer()
|
||||
unspent = player.get('unspent_points', 0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user