feat(bot): support concurrent drafts and reply-based edits with error resilience
This commit is contained in:
@@ -117,10 +117,11 @@ class BotContext:
|
||||
def admin_chat_ids(self) -> set[int]:
|
||||
return settings.admin_chat_ids
|
||||
|
||||
async def send(self, chat_id: int, text: str, reply_markup: dict | None = None) -> dict:
|
||||
async def send(self, chat_id: int, text: str, reply_markup: dict | None = None,
|
||||
reply_to: int | None = None) -> dict:
|
||||
"""Send + audit-log every outbound message."""
|
||||
try:
|
||||
message = await self.bale.send_message(chat_id, text, reply_markup=reply_markup)
|
||||
message = await self.bale.send_message(chat_id, text, reply_markup=reply_markup, reply_to=reply_to)
|
||||
except Exception:
|
||||
logger.exception("failed to send to chat %s", chat_id)
|
||||
message = {}
|
||||
@@ -137,6 +138,15 @@ class BotContext:
|
||||
except Exception:
|
||||
await self.send(chat_id, text, reply_markup=reply_markup)
|
||||
|
||||
async def delete(self, chat_id: int, message_id: int | None) -> bool:
|
||||
if not message_id:
|
||||
return False
|
||||
try:
|
||||
return await self.bale.delete_message(chat_id, message_id)
|
||||
except Exception:
|
||||
logger.exception("failed to delete message %s in chat %s", message_id, chat_id)
|
||||
return False
|
||||
|
||||
async def _log(self, chat_id: int, direction: str, kind: str, body: str | None = None) -> None:
|
||||
try:
|
||||
async with SessionLocal() as session:
|
||||
|
||||
Reference in New Issue
Block a user