Beispiel #1
0
    def self_from_object(self, object: TelegramObject):
        if hasattr(object, 'bot') and isinstance(object.bot, Bot):
            self._bot = object.bot

        for key, value in self._get_dict_from_object(self, object).items():
            self.__setattr__(key, value)

        if hasattr(self, 'original_object') and isinstance(
                self._fields.get('original_object'), DictField):
            self.original_object = object.to_dict()
Beispiel #2
0
def prepare_params(attachment: TelegramObject, at: str, reply_to_id: int) -> Optional[dict]:
    """Функция-помощник, которая подготовит данные для всех методов бота по шаблону ``send_*``."""
    if isinstance(attachment, list):
        if len(attachment) > 0:
            attachment = attachment[0]
        else:
            return None

    params = attachment.to_dict()

    logger.debug(json.dumps(params))

    file_id = params.pop("file_id", None)
    if file_id is not None:
        params[at] = file_id

    params["chat_id"] = reply_to_id

    return params
def prepare_params(attachment: TelegramObject, at: str,
                   reply_to_id: int) -> Optional[dict]:
    """prepare params for bots' ``send_*``."""
    if isinstance(attachment, list):
        if len(attachment) > 0:
            attachment = attachment[0]
        else:
            return None

    params = attachment.to_dict()

    logger.debug(json.dumps(params))

    file_id = params.pop("file_id", None)
    if file_id is not None:
        params[at] = file_id

    params["chat_id"] = reply_to_id

    return params
def tgoToJson(tgo: TelegramObject):
    return json.dumps(tgo.to_dict(), sort_keys=True, indent=2)