Class method get defined.

This commit is contained in:
Davte 2019-07-16 16:38:53 +02:00
parent b0149da520
commit d53051e6f3

View File

@ -218,6 +218,18 @@ class Bot(TelegramBot, ObjectWithDatabase):
"""Set instance path attribute."""
self._path = path
@classmethod
def get(cls, token, *args, **kwargs):
"""Given a `token`, return class instance with that token.
If no instance is found, instantiate it.
Positional and keyword arguments may be passed as well.
"""
for bot in cls.bots:
if bot.token == token:
return bot
return cls(token, *args, **kwargs)
@property
def hostname(self):
"""Hostname for the webhook URL.