добавлена проверка на существование добавляемого игрока
This commit is contained in:
parent
a5d6481495
commit
ecd252cdad
2 changed files with 45 additions and 18 deletions
|
|
@ -166,29 +166,37 @@ class LichessBot:
|
|||
username = update.message.text.strip()
|
||||
user_id = update.effective_user.id
|
||||
|
||||
if username:
|
||||
# Add gamer to database (without token)
|
||||
gamer_id = self.db.add_gamer(username)
|
||||
# Link user to gamer (without token)
|
||||
self.db.add_user_gamer(user_id, gamer_id, None)
|
||||
|
||||
# Set default period to 1 hour (60 minutes) for new gamer
|
||||
self.db.set_user_gamer_period(user_id, gamer_id, 60)
|
||||
|
||||
# If this is the first gamer for this user, make it active
|
||||
user_gamers = self.db.get_user_gamers(user_id)
|
||||
if len(user_gamers) == 1:
|
||||
self.db.set_user_active_gamer(user_id, gamer_id)
|
||||
|
||||
await update.message.reply_text(
|
||||
f"✅ Игрок {username} успешно добавлен!"
|
||||
)
|
||||
else:
|
||||
if not username:
|
||||
await update.message.reply_text(
|
||||
"❌ Username не может быть пустым. Попробуйте еще раз."
|
||||
)
|
||||
return WAITING_FOR_USERNAME
|
||||
|
||||
# Check if user exists on Lichess
|
||||
user_exists = await self.lichess_api.check_user_exists(username)
|
||||
if not user_exists:
|
||||
await update.message.reply_text(
|
||||
f"❌ Игрок {username} не найден на Lichess. Проверьте правильность написания имени."
|
||||
)
|
||||
return WAITING_FOR_USERNAME
|
||||
|
||||
# Add gamer to database (without token)
|
||||
gamer_id = self.db.add_gamer(username)
|
||||
# Link user to gamer (without token)
|
||||
self.db.add_user_gamer(user_id, gamer_id, None)
|
||||
|
||||
# Set default period to 1 hour (60 minutes) for new gamer
|
||||
self.db.set_user_gamer_period(user_id, gamer_id, 60)
|
||||
|
||||
# If this is the first gamer for this user, make it active
|
||||
user_gamers = self.db.get_user_gamers(user_id)
|
||||
if len(user_gamers) == 1:
|
||||
self.db.set_user_active_gamer(user_id, gamer_id)
|
||||
|
||||
await update.message.reply_text(
|
||||
f"✅ Игрок {username} успешно добавлен!"
|
||||
)
|
||||
|
||||
return ConversationHandler.END
|
||||
|
||||
async def getgamers(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue