2020-06-07 20:46:37 +09:00
|
|
|
|
from typing import TYPE_CHECKING, Optional
|
|
|
|
|
|
|
|
|
|
from yandex_music import YandexMusicObject
|
2021-09-19 22:47:19 +09:00
|
|
|
|
from yandex_music.utils import model
|
2020-06-07 20:46:37 +09:00
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from yandex_music import Client, AlertButton
|
|
|
|
|
|
|
|
|
|
|
2021-09-19 22:47:19 +09:00
|
|
|
|
@model
|
2020-06-07 20:46:37 +09:00
|
|
|
|
class Alert(YandexMusicObject):
|
|
|
|
|
"""Класс, представляющий блок с предупреждением.
|
|
|
|
|
|
|
|
|
|
Note:
|
|
|
|
|
Данные предупреждения, скорее всего, только обкатываются. У них нет ID, вместо этого `xxx`, а еще присутствуют
|
|
|
|
|
слова "тест" в тексте.
|
|
|
|
|
|
|
|
|
|
Используют как предупреждение о конце подписки, так и о раздаче подарков.
|
|
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
|
alert_id (:obj:`str`): Уникальный идентификатор.
|
|
|
|
|
text (:obj:`str`): Текст предупреждения.
|
|
|
|
|
bg_color (:obj:`str`): Цвет заднего фона.
|
|
|
|
|
text_color (:obj:`str`): Цвет текста.
|
|
|
|
|
alert_type (:obj:`str`): Тип предупреждения.
|
|
|
|
|
button (:obj:`yandex_music.AlertButton`): Кнопка с ссылкой.
|
|
|
|
|
close_button (:obj:`bool`): Наличие кнопки "Закрыть".
|
|
|
|
|
client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.
|
|
|
|
|
"""
|
|
|
|
|
|
2021-09-19 22:47:19 +09:00
|
|
|
|
alert_id: str
|
|
|
|
|
text: str
|
|
|
|
|
bg_color: str
|
|
|
|
|
text_color: str
|
|
|
|
|
alert_type: str
|
|
|
|
|
button: 'AlertButton'
|
|
|
|
|
close_button: bool
|
|
|
|
|
client: Optional['Client'] = None
|
2020-06-07 20:46:37 +09:00
|
|
|
|
|
2021-09-19 22:47:19 +09:00
|
|
|
|
def __post_init__(self):
|
2020-06-07 20:46:37 +09:00
|
|
|
|
self._id_attrs = (self.alert_id,)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def de_json(cls, data: dict, client: 'Client') -> Optional['Alert']:
|
|
|
|
|
"""Десериализация объекта.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
data (:obj:`dict`): Поля и значения десериализуемого объекта.
|
|
|
|
|
client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
:obj:`yandex_music.Alert`: Сообщение о статусе подписки.
|
|
|
|
|
"""
|
|
|
|
|
if not data:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
from yandex_music import AlertButton
|
2021-02-03 21:28:10 +09:00
|
|
|
|
|
2020-06-07 20:46:37 +09:00
|
|
|
|
data = super(Alert, cls).de_json(data, client)
|
|
|
|
|
data['button'] = AlertButton.de_json(data.get('button'), client)
|
|
|
|
|
|
|
|
|
|
return cls(client=client, **data)
|