feat(publish): 30-min slot grid with silent slots and loud morning/evening anchors
This commit is contained in:
@@ -25,6 +25,7 @@ class Card(BaseModel):
|
||||
media: str | None = None # путь к локальному файлу (если есть)
|
||||
direction: str = "linux"
|
||||
lang: str = "ru"
|
||||
silent: bool = False # True → disable_notification (тихий слот)
|
||||
|
||||
|
||||
class PublishRequest(BaseModel):
|
||||
@@ -148,14 +149,16 @@ def publish(req: PublishRequest):
|
||||
media_path = _resolve_media(req.card.media)
|
||||
if media_path:
|
||||
# медиа первым (caption короткий: первые 1000 символов, т.к. лимит 1024)
|
||||
media_msg = telegram.send_media(ch, media_path, caption=req.card.text[:1000])
|
||||
media_msg = telegram.send_media(
|
||||
ch, media_path, caption=req.card.text[:1000], silent=req.card.silent
|
||||
)
|
||||
res.media_message_id = media_msg
|
||||
# ПОЛНЫЙ текст отдельным сообщением (без предпросмотра ссылки)
|
||||
msg = telegram.send_message(ch, req.card.text)
|
||||
msg = telegram.send_message(ch, req.card.text, silent=req.card.silent)
|
||||
res.message_id = msg
|
||||
else:
|
||||
# без медиа: текст вторым; предпросмотр ссылки отключён (богатый репост)
|
||||
msg = telegram.send_message(ch, req.card.text)
|
||||
msg = telegram.send_message(ch, req.card.text, silent=req.card.silent)
|
||||
res.message_id = msg
|
||||
res.views = telegram.get_views(ch, res.message_id)
|
||||
except telegram.TelegramError as e:
|
||||
|
||||
@@ -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