2222
Some checks failed
CI / Lint (ruff + mypy) (push) Failing after 32s
CI / Run tests (push) Has been skipped
CI / Docker build test (push) Successful in 10s

This commit is contained in:
2026-04-02 21:20:24 +07:00
parent 0626454253
commit e7bd488551

View File

@@ -213,6 +213,10 @@ def save_post_template(state_storage: JsonStateStorage, template: str) -> None:
state_storage.save(payload) state_storage.save(payload)
def count_actor_placeholders(template: str) -> int:
return normalize_template_placeholders(template).count("{{actors}}")
@router.message(CommandStart()) @router.message(CommandStart())
@router.message(Command("panel")) @router.message(Command("panel"))
async def start_handler(message: Message, state: FSMContext, app_config: dict, actor_lookup: dict, settings) -> None: async def start_handler(message: Message, state: FSMContext, app_config: dict, actor_lookup: dict, settings) -> None:
@@ -277,12 +281,25 @@ async def post_handler(
normalized = normalize_template_placeholders(template) normalized = normalize_template_placeholders(template)
save_post_template(state_storage, normalized) save_post_template(state_storage, normalized)
await state.clear() await state.clear()
if "{{actors}}" not in normalized: placeholder_count = count_actor_placeholders(normalized)
if placeholder_count == 0:
await message.answer( await message.answer(
"Шаблон сохранен, но в нем нет {{actors}}.\n" "Шаблон сохранен, но в нем нет {{actors}}.\n"
"Плейсхолдер должен быть именно {{actors}} в любом регистре." "Плейсхолдер должен быть именно {{actors}} в любом регистре."
) )
return return
if placeholder_count > 1:
await message.answer(
"Шаблон сохранен, но в нем несколько {{actors}}.\n"
"Нужен только один общий {{actors}} на месте всего блока актеров, иначе список будет дублироваться."
)
return
if message.text and message.text.startswith("/post "):
await message.answer(
"Шаблон сохранен.\n"
"Но если нужна разметка, ссылки и premium emoji, лучше использовать /post ответом на уже оформленное сообщение, а не вставлять шаблон текстом после команды."
)
return
await message.answer("Шаблон поста сохранен.") await message.answer("Шаблон поста сохранен.")
return return
@@ -493,12 +510,19 @@ async def post_template_handler(
save_post_template(state_storage, normalized) save_post_template(state_storage, normalized)
await state.clear() await state.clear()
if "{{actors}}" not in normalized: placeholder_count = count_actor_placeholders(normalized)
if placeholder_count == 0:
await message.answer( await message.answer(
"Шаблон сохранен, но в нем нет {{actors}}.\n" "Шаблон сохранен, но в нем нет {{actors}}.\n"
"Плейсхолдер должен быть именно {{actors}} в любом регистре." "Плейсхолдер должен быть именно {{actors}} в любом регистре."
) )
return return
if placeholder_count > 1:
await message.answer(
"Шаблон сохранен, но в нем несколько {{actors}}.\n"
"Нужен только один общий {{actors}} на месте всего блока актеров, иначе список будет дублироваться."
)
return
await message.answer("Шаблон поста сохранен.") await message.answer("Шаблон поста сохранен.")