From a4b42c945c6813934450bb3bb056cff159c1d541 Mon Sep 17 00:00:00 2001 From: klux2 Date: Tue, 25 Jun 2019 10:39:05 +0200 Subject: [PATCH] checking for keys in msg dictionary Signed-off-by: klux2 --- HSMensaW_botA.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/HSMensaW_botA.py b/HSMensaW_botA.py index 498ce0b..67bd57c 100644 --- a/HSMensaW_botA.py +++ b/HSMensaW_botA.py @@ -210,10 +210,15 @@ def get_bot_id() -> int: def get_chat_name(msg: dict) -> str: + chat = "" if msg["chat"]["type"] == "group": chat = msg["chat"]["title"] + " (g)" elif msg["chat"]["type"] == "private": - chat = msg["chat"]["first_name"] + " " + msg["chat"]["last_name"] + " (p)" + if "first_name" in msg["chat"].keys(): + chat = msg["chat"]["first_name"] + " " + if "last_name" in msg["chat"].keys(): + chat += msg["chat"]["last_name"] + " " + chat += "(p)" else: chat = "null" return chat