еще попытка фикса гцупа
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
585cc374ed
commit
f5b1643f53
1 changed files with 49 additions and 2 deletions
|
|
@ -169,11 +169,35 @@ def recreate_post(
|
||||||
disable_web_page_preview=True,
|
disable_web_page_preview=True,
|
||||||
reply_markup=markup,
|
reply_markup=markup,
|
||||||
)
|
)
|
||||||
|
log.info(f"recreate_post sent for task {task_id}, message_id={msg.message_id}")
|
||||||
# save_message_id сначала создаёт/обновляет строку, потом сохраняем события
|
# save_message_id сначала создаёт/обновляет строку, потом сохраняем события
|
||||||
database.save_message_id(task_id, msg.message_id, task_number, group_id, base_text)
|
database.save_message_id(task_id, msg.message_id, task_number, group_id, base_text)
|
||||||
if added:
|
if added:
|
||||||
database.save_stored_events(task_id, stored)
|
database.save_stored_events(task_id, stored)
|
||||||
except ApiTelegramException as e:
|
except ApiTelegramException as e:
|
||||||
|
err_text = str(e).lower()
|
||||||
|
is_markdown_error = any(x in err_text for x in (
|
||||||
|
"can't parse entities",
|
||||||
|
"can't find end of the entity",
|
||||||
|
"entity starting at byte offset",
|
||||||
|
))
|
||||||
|
if is_markdown_error:
|
||||||
|
log.error(f"recreate_post markdown failed for task {task_id}, fallback to plain text: {e}")
|
||||||
|
try:
|
||||||
|
msg = bot.send_message(
|
||||||
|
config.CHANNEL_ID,
|
||||||
|
full_text,
|
||||||
|
parse_mode=None,
|
||||||
|
disable_web_page_preview=True,
|
||||||
|
reply_markup=markup,
|
||||||
|
)
|
||||||
|
database.save_message_id(task_id, msg.message_id, task_number, group_id, base_text)
|
||||||
|
if added:
|
||||||
|
database.save_stored_events(task_id, stored)
|
||||||
|
log.warning(f"recreate_post sent without markdown for task {task_id}, message_id={msg.message_id}")
|
||||||
|
except ApiTelegramException as e2:
|
||||||
|
log.error(f"recreate_post fallback failed for task {task_id}: {e2}")
|
||||||
|
else:
|
||||||
log.error(f"recreate_post failed for task {task_id}: {e}")
|
log.error(f"recreate_post failed for task {task_id}: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -338,7 +362,18 @@ def _is_stale_error(e: Exception) -> bool:
|
||||||
"message to edit not found",
|
"message to edit not found",
|
||||||
"message is not modified",
|
"message is not modified",
|
||||||
"message can't be edited",
|
"message can't be edited",
|
||||||
"bad request",
|
"message to delete not found",
|
||||||
|
"message_id_invalid",
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
|
def _is_missing_message_error(e: Exception) -> bool:
|
||||||
|
"""True for Telegram errors when target message no longer exists."""
|
||||||
|
s = str(e).lower()
|
||||||
|
return any(x in s for x in (
|
||||||
|
"message to edit not found",
|
||||||
|
"message to delete not found",
|
||||||
|
"message_id_invalid",
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -376,6 +411,18 @@ def _refresh_responsible(call, task_id: int, task_number: str):
|
||||||
reply_markup=markup,
|
reply_markup=markup,
|
||||||
)
|
)
|
||||||
except ApiTelegramException as e:
|
except ApiTelegramException as e:
|
||||||
|
if _is_missing_message_error(e):
|
||||||
|
log.warning(
|
||||||
|
f"_refresh_responsible: message missing for task {task_id}, recreating post"
|
||||||
|
)
|
||||||
|
recreate_post(
|
||||||
|
task_id=task_id,
|
||||||
|
task_number=task_number,
|
||||||
|
base_text=data["base_text"],
|
||||||
|
group_id=data.get("group_id") or 0,
|
||||||
|
new_event_lines=None,
|
||||||
|
)
|
||||||
|
return
|
||||||
if not _is_stale_error(e):
|
if not _is_stale_error(e):
|
||||||
log.warning(f"_refresh_responsible failed: {e}")
|
log.warning(f"_refresh_responsible failed: {e}")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue