|
4 | 4 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
5 | 5 |
|
6 | 6 | import re
|
| 7 | +import html |
7 | 8 | import configparser
|
8 | 9 | import os
|
9 | 10 | import sys
|
@@ -714,7 +715,14 @@ async def handle_message(bot, update: Update, context: CallbackContext, logger)
|
714 | 715 | # View the output (i.e. for markdown etc formatting debugging)
|
715 | 716 | logger.info(f"[Debug] Reply message before escaping: {bot_reply}")
|
716 | 717 |
|
717 |
| - escaped_reply = markdown_to_html(bot_reply) |
| 718 | + # escaped_reply = markdown_to_html(bot_reply) |
| 719 | + |
| 720 | + try: |
| 721 | + escaped_reply = markdown_to_html(bot_reply) |
| 722 | + except Exception as e: |
| 723 | + bot.logger.error(f"markdown_to_html failed: {e}") |
| 724 | + escaped_reply = html.escape(bot_reply) # Safe fallback |
| 725 | + |
718 | 726 | # escaped_reply = bot_reply
|
719 | 727 | logger.info(f"[Debug] Reply message after escaping: {escaped_reply}")
|
720 | 728 |
|
@@ -788,7 +796,12 @@ async def handle_message(bot, update: Update, context: CallbackContext, logger)
|
788 | 796 | # return content
|
789 | 797 |
|
790 | 798 | # Convert markdown to HTML
|
791 |
| - escaped_reply = markdown_to_html(bot_reply) |
| 799 | + # escaped_reply = markdown_to_html(bot_reply) |
| 800 | + try: |
| 801 | + escaped_reply = markdown_to_html(bot_reply) |
| 802 | + except Exception as e: |
| 803 | + bot.logger.error(f"markdown_to_html failed: {e}") |
| 804 | + escaped_reply = html.escape(bot_reply) # Safe fallback |
792 | 805 |
|
793 | 806 | # Sanitize the HTML to remove any unsupported tags
|
794 | 807 | escaped_reply = sanitize_html(escaped_reply)
|
@@ -860,7 +873,13 @@ async def handle_message(bot, update: Update, context: CallbackContext, logger)
|
860 | 873 | # return content
|
861 | 874 |
|
862 | 875 | # Convert markdown to HTML
|
863 |
| - escaped_reply = markdown_to_html(bot_reply) |
| 876 | + # escaped_reply = markdown_to_html(bot_reply) |
| 877 | + |
| 878 | + try: |
| 879 | + escaped_reply = markdown_to_html(bot_reply) |
| 880 | + except Exception as e: |
| 881 | + bot.logger.error(f"markdown_to_html failed: {e}") |
| 882 | + escaped_reply = html.escape(bot_reply) # Safe fallback |
864 | 883 |
|
865 | 884 | # Sanitize the HTML to remove any unsupported tags
|
866 | 885 | escaped_reply = sanitize_html(escaped_reply)
|
@@ -946,7 +965,13 @@ async def handle_message(bot, update: Update, context: CallbackContext, logger)
|
946 | 965 | # View the output (i.e. for markdown etc formatting debugging)
|
947 | 966 | logger.info(f"[Debug] Reply message before escaping: {bot_reply}")
|
948 | 967 |
|
949 |
| - escaped_reply = markdown_to_html(bot_reply) |
| 968 | + # escaped_reply = markdown_to_html(bot_reply) |
| 969 | + try: |
| 970 | + escaped_reply = markdown_to_html(bot_reply) |
| 971 | + except Exception as e: |
| 972 | + bot.logger.error(f"markdown_to_html failed: {e}") |
| 973 | + escaped_reply = html.escape(bot_reply) # Safe fallback |
| 974 | + |
950 | 975 | logger.info(f"[Debug] Reply message after escaping: {escaped_reply}")
|
951 | 976 |
|
952 | 977 | # Log the bot's response
|
@@ -1116,7 +1141,13 @@ async def handle_message(bot, update: Update, context: CallbackContext, logger)
|
1116 | 1141 | # Ensure the bot has a substantive response to send
|
1117 | 1142 | if bot_reply:
|
1118 | 1143 | # escaped_reply = bot_reply
|
1119 |
| - escaped_reply = markdown_to_html(bot_reply) |
| 1144 | + # escaped_reply = markdown_to_html(bot_reply) |
| 1145 | + |
| 1146 | + try: |
| 1147 | + escaped_reply = markdown_to_html(bot_reply) |
| 1148 | + except Exception as e: |
| 1149 | + bot.logger.error(f"markdown_to_html failed: {e}") |
| 1150 | + escaped_reply = html.escape(bot_reply) # Safe fallback |
1120 | 1151 |
|
1121 | 1152 | # Log the bot's response from Perplexity API
|
1122 | 1153 | bot.log_message(
|
@@ -1300,7 +1331,13 @@ async def handle_message(bot, update: Update, context: CallbackContext, logger)
|
1300 | 1331 | # view the output (i.e. for markdown etc formatting debugging)
|
1301 | 1332 | logger.info(f"[Debug] Reply message before escaping: {bot_reply}")
|
1302 | 1333 |
|
1303 |
| - escaped_reply = markdown_to_html(bot_reply) |
| 1334 | + # escaped_reply = markdown_to_html(bot_reply) |
| 1335 | + try: |
| 1336 | + escaped_reply = markdown_to_html(bot_reply) |
| 1337 | + except Exception as e: |
| 1338 | + bot.logger.error(f"markdown_to_html failed: {e}") |
| 1339 | + escaped_reply = html.escape(bot_reply) # Safe fallback |
| 1340 | + |
1304 | 1341 | # escaped_reply = bot_reply
|
1305 | 1342 | logger.info(f"[Debug] Reply message after escaping: {escaped_reply}")
|
1306 | 1343 |
|
|
0 commit comments