checking for keys in msg dictionary

Signed-off-by: klux2 <k.lux.gm@gmail.com>
This commit is contained in:
klux2 2019-06-25 10:39:05 +02:00
parent 84ba13f77c
commit a4b42c945c

View file

@ -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