bug fixed text add player
This commit is contained in:
parent
d1e8d343ba
commit
9011b3015b
1 changed files with 18 additions and 19 deletions
|
|
@ -205,6 +205,9 @@ class LichessBot:
|
||||||
logger.info(f"addgamer_start called for user {update.effective_user.id}")
|
logger.info(f"addgamer_start called for user {update.effective_user.id}")
|
||||||
lang = self.get_user_language_from_update(update)
|
lang = self.get_user_language_from_update(update)
|
||||||
try:
|
try:
|
||||||
|
# Mark that we are awaiting a username reply
|
||||||
|
if context and hasattr(context, "user_data"):
|
||||||
|
context.user_data['awaiting_addgamer_username'] = True
|
||||||
await update.message.reply_text(t('addgamer_prompt', lang))
|
await update.message.reply_text(t('addgamer_prompt', lang))
|
||||||
logger.info(f"Addgamer prompt sent to user {update.effective_user.id}")
|
logger.info(f"Addgamer prompt sent to user {update.effective_user.id}")
|
||||||
self.counters.increment('addgamer')
|
self.counters.increment('addgamer')
|
||||||
|
|
@ -212,7 +215,8 @@ class LichessBot:
|
||||||
logger.error(f"Error sending addgamer prompt: {e}")
|
logger.error(f"Error sending addgamer prompt: {e}")
|
||||||
import traceback
|
import traceback
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
return WAITING_FOR_USERNAME
|
# No conversation state returned; handler-based flow
|
||||||
|
return
|
||||||
|
|
||||||
async def addtoken_start(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
async def addtoken_start(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
"""Start addtoken command - token required"""
|
"""Start addtoken command - token required"""
|
||||||
|
|
@ -297,6 +301,9 @@ class LichessBot:
|
||||||
|
|
||||||
async def handle_username(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
async def handle_username(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
"""Handle username input for /addgamer"""
|
"""Handle username input for /addgamer"""
|
||||||
|
# Only handle if we are awaiting an addgamer username
|
||||||
|
if not (context and hasattr(context, "user_data") and context.user_data.get('awaiting_addgamer_username')):
|
||||||
|
return
|
||||||
username = update.message.text.strip()
|
username = update.message.text.strip()
|
||||||
user_id = update.effective_user.id
|
user_id = update.effective_user.id
|
||||||
|
|
||||||
|
|
@ -305,7 +312,7 @@ class LichessBot:
|
||||||
await update.message.reply_text(
|
await update.message.reply_text(
|
||||||
t('empty_username', lang)
|
t('empty_username', lang)
|
||||||
)
|
)
|
||||||
return WAITING_FOR_USERNAME
|
return
|
||||||
|
|
||||||
# Check if user exists on Lichess
|
# Check if user exists on Lichess
|
||||||
user_exists = await self.lichess_api.check_user_exists(username)
|
user_exists = await self.lichess_api.check_user_exists(username)
|
||||||
|
|
@ -350,8 +357,12 @@ class LichessBot:
|
||||||
await update.message.reply_text(
|
await update.message.reply_text(
|
||||||
t('gamer_added', lang, username=username)
|
t('gamer_added', lang, username=username)
|
||||||
)
|
)
|
||||||
|
# Clear awaiting flag
|
||||||
return ConversationHandler.END
|
try:
|
||||||
|
context.user_data['awaiting_addgamer_username'] = False
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return
|
||||||
|
|
||||||
async def getgamers(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
async def getgamers(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
"""Get all gamers for the current user and allow selection"""
|
"""Get all gamers for the current user and allow selection"""
|
||||||
|
|
@ -953,19 +964,6 @@ class LichessBot:
|
||||||
"""Setup all handlers"""
|
"""Setup all handlers"""
|
||||||
self.application = application # Store application reference
|
self.application = application # Store application reference
|
||||||
|
|
||||||
# Conversation handler for addgamer (simple username only)
|
|
||||||
addgamer_conv = ConversationHandler(
|
|
||||||
entry_points=[
|
|
||||||
CommandHandler("addgamer", self.addgamer_start),
|
|
||||||
CommandHandler("start", self.start_and_addgamer) # Also handle /start to start addgamer flow
|
|
||||||
],
|
|
||||||
states={
|
|
||||||
WAITING_FOR_USERNAME: [MessageHandler(filters.TEXT & ~filters.COMMAND, self.handle_username)],
|
|
||||||
},
|
|
||||||
fallbacks=[CommandHandler("cancel", lambda u, c: ConversationHandler.END)],
|
|
||||||
name="addgamer_conversation"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Conversation handler for addtoken (token required)
|
# Conversation handler for addtoken (token required)
|
||||||
addtoken_conv = ConversationHandler(
|
addtoken_conv = ConversationHandler(
|
||||||
entry_points=[CommandHandler("addtoken", self.addtoken_start)],
|
entry_points=[CommandHandler("addtoken", self.addtoken_start)],
|
||||||
|
|
@ -975,8 +973,9 @@ class LichessBot:
|
||||||
fallbacks=[CommandHandler("cancel", lambda u, c: ConversationHandler.END)]
|
fallbacks=[CommandHandler("cancel", lambda u, c: ConversationHandler.END)]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add conversation handlers
|
# Add handlers
|
||||||
application.add_handler(addgamer_conv)
|
application.add_handler(CommandHandler("addgamer", self.addgamer_start))
|
||||||
|
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, self.handle_username))
|
||||||
application.add_handler(addtoken_conv)
|
application.add_handler(addtoken_conv)
|
||||||
application.add_handler(CommandHandler("getgamers", self.getgamers))
|
application.add_handler(CommandHandler("getgamers", self.getgamers))
|
||||||
application.add_handler(CommandHandler("delgamer", self.delgamer))
|
application.add_handler(CommandHandler("delgamer", self.delgamer))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue