From 6c90da793ec9e8b1021a0500a3598ee30009afae Mon Sep 17 00:00:00 2001 From: David256 Date: Thu, 1 Apr 2021 14:56:08 -0500 Subject: [PATCH] New property full_name --- telebot/types.py | 7 +++++++ tests/test_types.py | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/telebot/types.py b/telebot/types.py index 94316c0..21c43aa 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -179,6 +179,13 @@ class User(JsonDeserializable, Dictionaryable, JsonSerializable): self.can_read_all_group_messages = can_read_all_group_messages self.supports_inline_queries = supports_inline_queries + @property + def full_name(self): + full_name = self.first_name + if self.last_name: + full_name += f' {self.last_name}' + return full_name + def to_json(self): return json.dumps(self.to_dict()) diff --git a/tests/test_types.py b/tests/test_types.py index 173cda9..355f690 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -6,9 +6,10 @@ from telebot import types def test_json_user(): - jsonstring = r'{"id":101176298,"first_name":"RDSSBOT","username":"rdss_bot","is_bot":true}' + jsonstring = r'{"id":101176298,"first_name":"RDSSBOT","last_name":")))","username":"rdss_bot","is_bot":true}' u = types.User.de_json(jsonstring) assert u.id == 101176298 + assert u.full_name == 'RDSSBOT )))' def test_json_message():