(
channel: discord.Thread | discord.TextChannel,
text: str,
max_length: int = 2000,
reply_to: discord.Message | None = None,
files: list[discord.File] | None = None,
mention_author: bool = True,
)
| 1357 | |
| 1358 | |
| 1359 | async def send_long_message( |
| 1360 | channel: discord.Thread | discord.TextChannel, |
| 1361 | text: str, |
| 1362 | max_length: int = 2000, |
| 1363 | reply_to: discord.Message | None = None, |
| 1364 | files: list[discord.File] | None = None, |
| 1365 | mention_author: bool = True, |
| 1366 | ): |
| 1367 | attachments = files[:10] if files else [] |
| 1368 | |
| 1369 | modified_text, tables = detect_and_parse_markdown_tables(text) |
| 1370 | |
| 1371 | for idx, (headers, rows, alignments) in enumerate(tables): |
| 1372 | placeholder = f"__TABLE_IMG_{idx}__" |
| 1373 | rendered = False |
| 1374 | if PIL_AVAILABLE: |
| 1375 | try: |
| 1376 | img_buffer, links = await render_table_image(headers, rows, alignments) |
| 1377 | if img_buffer: |
| 1378 | file = discord.File(img_buffer, filename=f"table_{idx}.png") |
| 1379 | attachments.append(file) |
| 1380 | replace_text = "\n*(Table image attached)*\n" |
| 1381 | if links: |
| 1382 | replace_text += "**References:**\n" + "\n".join(f"- {l}" for l in links) + "\n" |
| 1383 | modified_text = modified_text.replace(placeholder, replace_text) |
| 1384 | rendered = True |
| 1385 | except Exception as e: |
| 1386 | logger.error(f"Table rendering error: {e}") |
| 1387 | |
| 1388 | if not rendered: |
| 1389 | fallback_table = f"\n```\n{format_table_as_markdown(headers, rows)}\n```\n" |
| 1390 | modified_text = modified_text.replace(placeholder, fallback_table) |
| 1391 | |
| 1392 | latex_blocks = BLOCK_LATEX_PATTERN.findall(modified_text) |
| 1393 | for idx, latex_expr in enumerate(latex_blocks): |
| 1394 | placeholder = f"__LATEX_IMG_{idx}__" |
| 1395 | modified_text = modified_text.replace(latex_expr, placeholder) |
| 1396 | |
| 1397 | rendered = False |
| 1398 | try: |
| 1399 | latex_buffer, success = await convert_latex_to_png(latex_expr) |
| 1400 | if success and isinstance(latex_buffer, io.BytesIO): |
| 1401 | file = discord.File(latex_buffer, filename=f"equation_{idx}.png") |
| 1402 | attachments.append(file) |
| 1403 | modified_text = modified_text.replace(placeholder, "\n*(Equation rendered below)*\n") |
| 1404 | rendered = True |
| 1405 | except Exception as e: |
| 1406 | logger.error(f"LaTeX block rendering error: {e}") |
| 1407 | |
| 1408 | if not rendered: |
| 1409 | modified_text = modified_text.replace(placeholder, f"\n```latex\n{latex_expr.strip()}\n```\n") |
| 1410 | |
| 1411 | modified_text = replace_latex_with_unicode(modified_text) |
| 1412 | modified_text = truncate_long_decimals(modified_text) |
| 1413 | |
| 1414 | lines = modified_text.split("\n") |
| 1415 | output_lines = [] |
| 1416 | i = 0 |
no test coverage detected