From 4de819c1df54ee6f1408b8278b22a0161e06aca4 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 6 Dec 2016 22:52:58 +0100 Subject: [PATCH] Solved #38 (can't test) --- main.py | 20 ++++++++++++-------- strings.py | 4 ++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 931d7a7..a5e2eaf 100644 --- a/main.py +++ b/main.py @@ -629,16 +629,20 @@ def join(bot, update): if game.phase == 'Join': p = game.findplayerbyid(update.message.from_user['id']) if p is None: - p = Player(update.message.from_user['id'], update.message.from_user['username']) try: - p.message(bot, s.you_joined.format(game=game.name)) - except TelegramError: - game.message(bot, s.error_chat_unavailable) + p = Player(update.message.from_user['id'], update.message.from_user['username']) + except KeyError: + game.message(bot, s.error_no_username) else: - game.message(bot, s.player_joined.format(name=p.tusername)) - if len(game.players) == 0: - game.admin = p - game.players.append(p) + try: + p.message(bot, s.you_joined.format(game=game.name)) + except TelegramError: + game.message(bot, s.error_chat_unavailable) + else: + game.message(bot, s.player_joined.format(name=p.tusername)) + if len(game.players) == 0: + game.admin = p + game.players.append(p) else: game.message(bot, s.error_player_already_joined) else: diff --git a/strings.py b/strings.py index 64d3ee4..95cc43b 100644 --- a/strings.py +++ b/strings.py @@ -256,6 +256,10 @@ error_invalid_config = "\U000026A0 Configurazione non valida." error_chat_unavailable = "\U000026A0 Non hai mai scritto un messaggio in chat privata a @mifiabot!\n" \ "Scrivigli nella chat privata `/start` e riprova." +# Erorre: nessun username +error_no_username = "\U000026A0 Non hai nessun username di Telegram!\n" \ + "Specificane uno nelle opzioni!" + # Lista dei possibili nomi di una partita names_list = ["Cassata", "Cannoli",