а
This commit is contained in:
@@ -33,6 +33,7 @@ HELP_TEXT = (
|
||||
"/start или /panel - открыть панель\n"
|
||||
"/help - показать справку\n"
|
||||
"/refresh - перерисовать пост в канале\n"
|
||||
"/post_test - отправить текущий пост себе в личку для проверки\n"
|
||||
"/cancel - сбросить текущий ввод\n"
|
||||
"/post - сохранить шаблон поста\n"
|
||||
"/template_dump - показать HTML из сообщения-реплая\n\n"
|
||||
@@ -204,13 +205,14 @@ 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,
|
||||
)
|
||||
|
||||
text = build_channel_text(app_config, state)
|
||||
try:
|
||||
await bot.edit_message_text(
|
||||
chat_id=settings.channel_id,
|
||||
@@ -229,9 +231,9 @@ async def update_channel_post(bot: Bot, app_config: dict, state_storage: JsonSta
|
||||
if not template:
|
||||
raise
|
||||
|
||||
state["template"]["text"] = sanitize_template_html(template)
|
||||
state_storage.save(state)
|
||||
fallback_text = build_channel_text(app_config, state)
|
||||
fallback_state = dict(state)
|
||||
fallback_state["template"] = {"text": sanitize_template_html(template)}
|
||||
fallback_text = build_channel_text(app_config, fallback_state)
|
||||
await bot.edit_message_text(
|
||||
chat_id=settings.channel_id,
|
||||
message_id=settings.channel_message_id,
|
||||
@@ -264,10 +266,28 @@ async def apply_status_update(
|
||||
|
||||
def save_post_template(state_storage: JsonStateStorage, template: str) -> None:
|
||||
payload = state_storage.load()
|
||||
payload["template"] = {"text": sanitize_template_html(normalize_template_placeholders(template))}
|
||||
payload["template"] = {"text": normalize_template_placeholders(template)}
|
||||
state_storage.save(payload)
|
||||
|
||||
|
||||
async def send_test_post(bot: Bot, chat_id: int, app_config: dict, state_storage: JsonStateStorage) -> 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,
|
||||
)
|
||||
|
||||
await bot.send_message(
|
||||
chat_id=chat_id,
|
||||
text=text,
|
||||
parse_mode=ParseMode.HTML,
|
||||
link_preview_options=link_preview_options,
|
||||
)
|
||||
|
||||
|
||||
@router.message(CommandStart())
|
||||
@router.message(Command("panel"))
|
||||
async def start_handler(message: Message, state: FSMContext, app_config: dict, actor_lookup: dict, settings) -> None:
|
||||
@@ -312,6 +332,29 @@ async def refresh_handler(
|
||||
await message.answer("Сообщение канала обновлено.")
|
||||
|
||||
|
||||
@router.message(Command("post_test"))
|
||||
async def post_test_handler(
|
||||
message: Message,
|
||||
bot: Bot,
|
||||
app_config: dict,
|
||||
state_storage: JsonStateStorage,
|
||||
actor_lookup: dict,
|
||||
settings,
|
||||
) -> None:
|
||||
user_id = message.from_user.id
|
||||
if not is_allowed(user_id, actor_lookup, settings.admin_ids):
|
||||
await message.answer("У вас нет доступа к тестовой отправке.")
|
||||
return
|
||||
|
||||
try:
|
||||
await send_test_post(bot, message.chat.id, app_config, state_storage)
|
||||
except TelegramBadRequest as exc:
|
||||
await message.answer(f"Тестовая отправка не удалась:\n{exc}")
|
||||
return
|
||||
|
||||
await message.answer("Тестовый пост отправлен.")
|
||||
|
||||
|
||||
@router.message(Command("template_dump"))
|
||||
async def template_dump_handler(message: Message, actor_lookup: dict, settings) -> None:
|
||||
user_id = message.from_user.id
|
||||
|
||||
Reference in New Issue
Block a user