Add platform poster header text settings
This commit is contained in:
@@ -271,6 +271,7 @@ SETTING_ORDER = {
|
||||
"tg_poster_recent_window",
|
||||
"tg_poster_category_repeat_penalty",
|
||||
"tg_poster_source_repeat_penalty",
|
||||
"tg_poster_header_text",
|
||||
"tg_poster_footer_text",
|
||||
],
|
||||
"TG Reactor": [
|
||||
@@ -302,6 +303,7 @@ SETTING_ORDER = {
|
||||
"vk_poster_category_repeat_penalty",
|
||||
"vk_poster_source_repeat_penalty",
|
||||
"vk_poster_dry_run",
|
||||
"vk_poster_header_text",
|
||||
"vk_poster_footer_text",
|
||||
],
|
||||
"Publishing": [
|
||||
@@ -327,6 +329,8 @@ SETTING_ORDER = {
|
||||
"max_poster_auto_reaction",
|
||||
"max_poster_reaction_path_template",
|
||||
"max_poster_dry_run",
|
||||
"max_poster_header_text",
|
||||
"max_poster_footer_text",
|
||||
],
|
||||
"Site Poster": [
|
||||
"site_poster_provider",
|
||||
|
||||
@@ -56,6 +56,7 @@ def build_publication_text(
|
||||
source_tag: str,
|
||||
common_tags: object = "",
|
||||
footer_text: str = "",
|
||||
header_text: str = "",
|
||||
format_title: bool = False,
|
||||
parse_mode: str | None = None,
|
||||
) -> str:
|
||||
@@ -76,10 +77,11 @@ def build_publication_text(
|
||||
title_idx = idx
|
||||
break
|
||||
|
||||
header = str(header_text or "").strip()
|
||||
footer = str(footer_text or "").strip()
|
||||
hashtags = publication_hashtags(category_tag, source_tag, common_tags)
|
||||
if title_idx is None:
|
||||
return "\n\n".join(part for part in [footer, hashtags] if part)
|
||||
return "\n\n".join(part for part in [header, footer, hashtags] if part)
|
||||
|
||||
formatted_lines = []
|
||||
for idx, line in enumerate(cleaned_lines):
|
||||
@@ -104,7 +106,7 @@ def build_publication_text(
|
||||
raw_body = "\n".join(formatted_lines)
|
||||
# Collapse multiple consecutive blank lines to at most two newlines (\n\n)
|
||||
normalized_body = re.sub(r"\n{3,}", "\n\n", raw_body).strip()
|
||||
parts = [part for part in [normalized_body, footer, hashtags] if part]
|
||||
parts = [part for part in [header, normalized_body, footer, hashtags] if part]
|
||||
return "\n\n".join(parts)
|
||||
|
||||
|
||||
|
||||
@@ -219,6 +219,8 @@ class MAXPoster:
|
||||
self.reaction_path_template = "/messages/{message_id}/reactions"
|
||||
self.dry_run = False
|
||||
self.common_tags = ""
|
||||
self.header_text = ""
|
||||
self.footer_text = ""
|
||||
|
||||
async def init(self) -> None:
|
||||
self.pool = await get_pool()
|
||||
@@ -245,6 +247,8 @@ class MAXPoster:
|
||||
self.reaction_path_template = str(await fetch_setting("max_poster_reaction_path_template", self.reaction_path_template) or "").strip()
|
||||
self.dry_run = await fetch_bool_setting("max_poster_dry_run", False)
|
||||
self.common_tags = str(await fetch_setting("publication_common_tags", "") or "").strip()
|
||||
self.header_text = str(await fetch_setting("max_poster_header_text", "") or "").strip()
|
||||
self.footer_text = str(await fetch_setting("max_poster_footer_text", "") or "").strip()
|
||||
if not self.token:
|
||||
raise RuntimeError("max_poster_bot_token is empty")
|
||||
if not self.chat_id:
|
||||
@@ -378,6 +382,8 @@ class MAXPoster:
|
||||
category_tag,
|
||||
source_tag,
|
||||
self.common_tags,
|
||||
self.footer_text,
|
||||
self.header_text,
|
||||
)
|
||||
|
||||
async def download_media_to_temp(self, session: aiohttp.ClientSession, item: dict[str, Any]) -> Path | None:
|
||||
|
||||
@@ -112,6 +112,7 @@ class TelegramPoster:
|
||||
self.category_repeat_penalty = 3.0
|
||||
self.source_repeat_penalty = 4.0
|
||||
self.common_tags = ""
|
||||
self.header_text = ""
|
||||
self.footer_text = ""
|
||||
|
||||
async def init(self) -> None:
|
||||
@@ -140,6 +141,7 @@ class TelegramPoster:
|
||||
self.category_repeat_penalty = max(0.0, await fetch_float_setting("tg_poster_category_repeat_penalty", 3.0))
|
||||
self.source_repeat_penalty = max(0.0, await fetch_float_setting("tg_poster_source_repeat_penalty", 4.0))
|
||||
self.common_tags = str(await fetch_setting("publication_common_tags", "") or "").strip()
|
||||
self.header_text = str(await fetch_setting("tg_poster_header_text", "") or "").strip()
|
||||
self.footer_text = str(await fetch_setting("tg_poster_footer_text", "") or "").strip()
|
||||
logger.info("TG poster config: chat={} schedule={} caption_limit={}", self.chat_id, self.schedule, self.caption_limit)
|
||||
|
||||
@@ -335,6 +337,7 @@ class TelegramPoster:
|
||||
source_tag,
|
||||
self.common_tags,
|
||||
self.footer_text,
|
||||
self.header_text,
|
||||
format_title=True,
|
||||
parse_mode="html",
|
||||
)
|
||||
|
||||
@@ -73,6 +73,7 @@ class VKPoster:
|
||||
self.source_repeat_penalty = 4.0
|
||||
self.dry_run = False
|
||||
self.common_tags = ""
|
||||
self.header_text = ""
|
||||
self.footer_text = ""
|
||||
|
||||
async def init(self) -> None:
|
||||
@@ -161,6 +162,7 @@ class VKPoster:
|
||||
self.source_repeat_penalty = max(0.0, await fetch_float_setting("vk_poster_source_repeat_penalty", 4.0))
|
||||
self.dry_run = await fetch_bool_setting("vk_poster_dry_run", False)
|
||||
self.common_tags = str(await fetch_setting("publication_common_tags", "") or "").strip()
|
||||
self.header_text = str(await fetch_setting("vk_poster_header_text", "") or "").strip()
|
||||
self.footer_text = str(await fetch_setting("vk_poster_footer_text", "") or "").strip()
|
||||
if not self.token:
|
||||
raise RuntimeError("vk_poster_access_token, VK_GROUP_ACCESS_TOKEN and VK_ACCESS_TOKEN are empty")
|
||||
@@ -302,6 +304,7 @@ class VKPoster:
|
||||
source_tag,
|
||||
self.common_tags,
|
||||
self.footer_text,
|
||||
self.header_text,
|
||||
)[:VK_MESSAGE_LIMIT]
|
||||
|
||||
async def media_attachment(self, client: VKAPIClient, item: dict[str, Any]) -> str | None:
|
||||
|
||||
Reference in New Issue
Block a user