Bot getter in TelegramObject.

This commit is contained in:
Alex Root Junior 2017-09-27 16:18:55 +03:00
parent 14d250bfbd
commit d98566bf7f

View file

@ -3,6 +3,7 @@ import typing
import ujson
from typing import TypeVar
from ..utils.context import get_value
from .fields import BaseField
PROPS_ATTR_NAME = '_props'
@ -126,6 +127,13 @@ class TelegramObject(metaclass=MetaTelegramObject):
"""
return cls(**data)
@property
def bot(self):
bot = get_value('bot')
if bot is None:
raise RuntimeError('Can not found bot instance in current context!')
return bot
def to_python(self) -> typing.Dict:
"""
Get object as JSON serializable