feat(publish): 30-min slot grid with silent slots and loud morning/evening anchors
This commit is contained in:
@@ -55,7 +55,8 @@ def _call(method: str, **params) -> dict:
|
||||
return data.get("result", {})
|
||||
|
||||
|
||||
def send_message(chat_id: str, text: str, parse_mode: str | None = None) -> int:
|
||||
def send_message(chat_id: str, text: str, parse_mode: str | None = None,
|
||||
silent: bool = False) -> int:
|
||||
"""Отправляет текст. По умолчанию — plain (карточка репоста: исходный текст поста
|
||||
с сырыми символами <,>,&; ссылки Telegram распознаёт сам).
|
||||
link_preview_options={is_disabled:True} — НЕ показывать предпросмотр ссылки
|
||||
@@ -67,10 +68,12 @@ def send_message(chat_id: str, text: str, parse_mode: str | None = None) -> int:
|
||||
}
|
||||
if parse_mode:
|
||||
params["parse_mode"] = parse_mode
|
||||
if silent:
|
||||
params["disable_notification"] = True
|
||||
return _call("sendMessage", **params)["message_id"]
|
||||
|
||||
|
||||
def send_photo(chat_id: str, photo_path: str, caption: str = "") -> int:
|
||||
def send_photo(chat_id: str, photo_path: str, caption: str = "", silent: bool = False) -> int:
|
||||
"""Отправляет фото (медиа первым). Возвращает message_id."""
|
||||
if not photo_path:
|
||||
raise TelegramError("photo_path пуст", http_code=400)
|
||||
@@ -78,7 +81,7 @@ def send_photo(chat_id: str, photo_path: str, caption: str = "") -> int:
|
||||
with _client() as c, open(photo_path, "rb") as f:
|
||||
r = c.post(
|
||||
_url("sendPhoto"),
|
||||
data={"chat_id": chat_id, "caption": caption[:1024]},
|
||||
data=_media_data(chat_id, caption, silent),
|
||||
files={"photo": f},
|
||||
timeout=TIMEOUT,
|
||||
)
|
||||
@@ -99,7 +102,7 @@ def send_photo(chat_id: str, photo_path: str, caption: str = "") -> int:
|
||||
return data["result"]["message_id"]
|
||||
|
||||
|
||||
def send_video(chat_id: str, video_path: str, caption: str = "") -> int:
|
||||
def send_video(chat_id: str, video_path: str, caption: str = "", silent: bool = False) -> int:
|
||||
"""Отправляет видео (медиа первым). Возвращает message_id."""
|
||||
if not video_path:
|
||||
raise TelegramError("video_path пуст", http_code=400)
|
||||
@@ -107,7 +110,7 @@ def send_video(chat_id: str, video_path: str, caption: str = "") -> int:
|
||||
with _client() as c, open(video_path, "rb") as f:
|
||||
r = c.post(
|
||||
_url("sendVideo"),
|
||||
data={"chat_id": chat_id, "caption": caption[:1024]},
|
||||
data=_media_data(chat_id, caption, silent),
|
||||
files={"video": f},
|
||||
timeout=TIMEOUT,
|
||||
)
|
||||
@@ -128,11 +131,19 @@ def send_video(chat_id: str, video_path: str, caption: str = "") -> int:
|
||||
return data["result"]["message_id"]
|
||||
|
||||
|
||||
def send_media(chat_id: str, media_path: str, caption: str = "") -> int:
|
||||
def _media_data(chat_id: str, caption: str, silent: bool) -> dict:
|
||||
"""Поля multipart-формы для sendPhoto/sendVideo: подпись + тихий режим."""
|
||||
data = {"chat_id": chat_id, "caption": caption[:1024]}
|
||||
if silent:
|
||||
data["disable_notification"] = "true"
|
||||
return data
|
||||
|
||||
|
||||
def send_media(chat_id: str, media_path: str, caption: str = "", silent: bool = False) -> int:
|
||||
"""Отправляет медиа по расширению: фото или видео. Возвращает message_id."""
|
||||
if str(media_path).lower().endswith((".mp4", ".mov", ".avi", ".mkv")):
|
||||
return send_video(chat_id, media_path, caption)
|
||||
return send_photo(chat_id, media_path, caption)
|
||||
return send_video(chat_id, media_path, caption, silent=silent)
|
||||
return send_photo(chat_id, media_path, caption, silent=silent)
|
||||
|
||||
|
||||
def get_views(chat_id: str, message_id: int) -> int:
|
||||
|
||||
Reference in New Issue
Block a user