Skip to content

Commit

Permalink
修复\n在消息里被转义的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yym68686 committed May 19, 2023
1 parent bfa14b9 commit aebcea1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 2 additions & 6 deletions AI.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def getBing(self, message, update, context):
text = result
result = f"🤖️ Bing\n\n" + result
modifytime = modifytime + 1
if modifytime % 6 == 0 and lastresult != result:
if modifytime % 8 == 0 and lastresult != result:
await context.bot.edit_message_text(chat_id=update.message.chat_id, message_id=messageid, text=escape(result), parse_mode='MarkdownV2')
lastresult = result

Expand Down Expand Up @@ -129,17 +129,13 @@ async def getChatGPT(self, message, update, context):
tmpresult = result + "`"
if result.count("```") % 2 != 0:
tmpresult = result + "\n```"
if modifytime % 6 == 0:
if modifytime % 10 == 0:
await context.bot.edit_message_text(chat_id=update.message.chat_id, message_id=messageid, text=escape(tmpresult), parse_mode='MarkdownV2')
except Exception as e:
print('\033[31m')
print("response_msg", result)
print("error", e)
print('\033[0m')
if "overloaded" in str(e):
result = "OpenAI 服务器过载。"
else:
result = "ChatGPT 出错啦。"
self.ChatGPTbot.reset()
print("ChatGPT", result)
await context.bot.edit_message_text(chat_id=update.message.chat_id, message_id=messageid, text=escape(result), parse_mode='MarkdownV2')
Expand Down
5 changes: 3 additions & 2 deletions md2tgmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def escape(text):
# In all other places characters
# _ * [ ] ( ) ~ ` > # + - = | { } . !
# must be escaped with the preceding character '\'.
text = re.sub(r"\\", r"\\\\", text)
text = re.sub(r"_", '\_', text)
text = re.sub(r"\*{2}(.*?)\*{2}", '@@@\\1@@@', text)
text = re.sub(r"\n\*\s", '\n\n• ', text)
Expand All @@ -53,7 +54,7 @@ def escape(text):
text = re.sub(r"!", '\!', text)
return text

text = '''
text = r'''
# title
**bold**
Expand Down Expand Up @@ -81,7 +82,7 @@ def escape(text):
sudo apt install mesa-utils # 安装
```python
print("1.1")_
print("1.1\n")_
```
And simple text `with-ten` + some - **symbols**. # `with-ten`里面的`-`不会被转义
Expand Down

0 comments on commit aebcea1

Please sign in to comment.