лооо
This commit is contained in:
@@ -12,7 +12,7 @@ from aiogram.filters import Command, CommandStart
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.fsm.state import State, StatesGroup
|
||||
from aiogram.fsm.storage.memory import MemoryStorage
|
||||
from aiogram.types import CallbackQuery, Message
|
||||
from aiogram.types import CallbackQuery, LinkPreviewOptions, Message
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
from session_bot.config import load_actor_config, load_settings
|
||||
@@ -205,15 +205,23 @@ async def show_actor_status_menu(callback: CallbackQuery, actor: dict[str, Any],
|
||||
async def update_channel_post(bot: Bot, app_config: dict, state_storage: JsonStateStorage, settings) -> None:
|
||||
state = state_storage.load()
|
||||
text = build_channel_text(app_config, state)
|
||||
link_preview_options = None
|
||||
if app_config.get("hidden_link_url", "").strip():
|
||||
link_preview_options = LinkPreviewOptions(
|
||||
url=app_config["hidden_link_url"].strip(),
|
||||
show_above_text=True,
|
||||
)
|
||||
try:
|
||||
await bot.edit_message_text(
|
||||
chat_id=settings.channel_id,
|
||||
message_id=settings.channel_message_id,
|
||||
text=text,
|
||||
parse_mode=ParseMode.HTML,
|
||||
disable_web_page_preview=False,
|
||||
link_preview_options=link_preview_options,
|
||||
)
|
||||
except TelegramBadRequest as exc:
|
||||
if "message is not modified" in str(exc).lower():
|
||||
return
|
||||
if "Invalid custom emoji identifier specified" not in str(exc):
|
||||
raise
|
||||
|
||||
@@ -229,7 +237,7 @@ async def update_channel_post(bot: Bot, app_config: dict, state_storage: JsonSta
|
||||
message_id=settings.channel_message_id,
|
||||
text=fallback_text,
|
||||
parse_mode=ParseMode.HTML,
|
||||
disable_web_page_preview=False,
|
||||
link_preview_options=link_preview_options,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -9,11 +9,7 @@ PLAIN_LINK_RE = re.compile(r"(?P<label>[^\n<>()]+?) \((?P<url>https?://[^\s)]+)\
|
||||
|
||||
|
||||
def build_hidden_link(config: dict) -> str:
|
||||
url = config.get("hidden_link_url", "").strip()
|
||||
if not url:
|
||||
return ""
|
||||
invisible = config.get("hidden_link_char", "​")
|
||||
return f'<a href="{escape(url, quote=True)}">{invisible}</a>'
|
||||
return ""
|
||||
|
||||
|
||||
def convert_plain_links_to_html(template: str) -> str:
|
||||
@@ -110,11 +106,8 @@ def build_channel_text(config: dict, state: dict) -> str:
|
||||
template = convert_plain_links_to_html(template)
|
||||
template, used_keys = replace_actor_placeholders(template, config, state)
|
||||
actors_block = build_actor_lines(config, state, skip_keys=used_keys)
|
||||
hidden_link = build_hidden_link(config)
|
||||
|
||||
text = template.replace("{{actors}}", actors_block)
|
||||
text = text.replace("{{hidden_link}}", "")
|
||||
if hidden_link:
|
||||
text = f"{hidden_link}{text}"
|
||||
|
||||
return text
|
||||
|
||||
@@ -23,7 +23,7 @@ def test_build_channel_text_includes_phrase() -> None:
|
||||
|
||||
text = build_channel_text(config, state)
|
||||
|
||||
assert text.startswith('<a href="https://example.com/image.png">')
|
||||
assert not text.startswith('<a href="https://example.com/image.png">')
|
||||
assert '<a href="https://t.me/example"><b>ASTAT</b></a>' in text
|
||||
assert "готов к игре" in text
|
||||
|
||||
|
||||
Reference in New Issue
Block a user