What a mess
This commit is contained in:
@@ -14,7 +14,6 @@ All other functionality is organized in separate modules:
|
||||
import logging
|
||||
from telegram import Update
|
||||
from telegram.ext import ContextTypes
|
||||
from . import database
|
||||
from .message_utils import send_or_edit_with_image
|
||||
|
||||
# Import organized action handlers
|
||||
@@ -124,14 +123,18 @@ async def button_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) ->
|
||||
Main router for button callbacks.
|
||||
Delegates to specific handler functions based on action type.
|
||||
All handlers have a unified signature: (query, user_id, player, data=None)
|
||||
|
||||
Note: user_id passed to handlers is actually the player's unique DB id (not telegram_id)
|
||||
"""
|
||||
from .api_client import api_client
|
||||
|
||||
query = update.callback_query
|
||||
user_id = query.from_user.id
|
||||
telegram_id = query.from_user.id
|
||||
data = query.data.split(':')
|
||||
action_type = data[0]
|
||||
|
||||
# Check if player exists and is alive
|
||||
player = await database.get_player(user_id)
|
||||
# Get player by telegram_id and translate to unique id
|
||||
player = await api_client.get_player(telegram_id)
|
||||
if not player or player['is_dead']:
|
||||
await query.answer()
|
||||
await send_or_edit_with_image(
|
||||
@@ -141,8 +144,11 @@ async def button_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) ->
|
||||
)
|
||||
return
|
||||
|
||||
# From now on, use player's unique database id
|
||||
user_id = player['id']
|
||||
|
||||
# Check if player is in combat - restrict most actions
|
||||
combat = await database.get_combat(user_id)
|
||||
combat = await api_client.get_combat(user_id)
|
||||
allowed_in_combat = {
|
||||
'combat_attack', 'combat_flee', 'combat_use_item_menu',
|
||||
'combat_use_item', 'combat_back', 'no_op'
|
||||
|
||||
Reference in New Issue
Block a user