From 38cc96d0f3de26ac341365e76a63f30ddd468c0f Mon Sep 17 00:00:00 2001 From: SwissCorePy <51398037+SwissCorePy@users.noreply.github.com> Date: Mon, 20 Sep 2021 14:31:00 +0200 Subject: [PATCH] added property `user` to TeleBot class Added property `user` to TeleBot class. The idea is to have easy access to the user object representing the bot without doing an API call every time. --- telebot/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/telebot/__init__.py b/telebot/__init__.py index 49a24ca75..cdcbec29c 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -207,6 +207,16 @@ def __init__( self.threaded = threaded if self.threaded: self.worker_pool = util.ThreadPool(num_threads=num_threads) + + @property + def user(self) -> types.User: + """ + The User object representing this bot. + Equivalent to bot.get_me() but the result is cached so only one API call is needed + """ + if not hasattr(self, "_user"): + self._user = types.User.de_json(self.get_me()) + return self._user def enable_save_next_step_handlers(self, delay=120, filename="./.handler-saves/step.save"): """