Skip to content

Commit

Permalink
Merge pull request #271 from Ikaros-521/owner
Browse files Browse the repository at this point in the history
念用户名时,删除用户名中存在的特殊符号
  • Loading branch information
Ikaros-521 authored Sep 1, 2023
2 parents b1d89c8 + 74026bf commit 8f316f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,7 @@ cmd运行`npm i docsify-cli -g`
- 新增 智谱AI的接入,支持上下文记忆。
- 修复智谱AI返回内容有\n时,也会进行语音合成的bug
- 删除部分违禁词
- 念用户名时,删除用户名中存在的特殊符号

</details>

Expand Down
2 changes: 2 additions & 0 deletions utils/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ def audio_synthesis(self, message):
tmp_message['type'] = "reply"
tmp_message['content'] = random.choice(self.config.get("read_user_name", "reply_before"))
if "{username}" in tmp_message['content']:
# 将用户名中特殊字符替换为空
message['user_name'] = self.common.replace_special_characters(message['user_name'], "!!@#¥$%^&*_-+/——=()()【】}|{:;<>~`\\")
tmp_message['content'] = tmp_message['content'].format(username=message['user_name'])
self.message_queue.put(tmp_message)

Expand Down
17 changes: 17 additions & 0 deletions utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,20 @@ def send_to_web_captions_printer(self, api_ip_port, data):
except Exception as e:
logging.info(e)
return False


def replace_special_characters(self, input_string, special_characters):
"""
将指定的特殊字符替换为空字符。
Args:
input_string (str): 要替换特殊字符的输入字符串。
special_characters (str): 包含要替换的特殊字符的字符串。
Returns:
str: 替换后的字符串。
"""
for char in special_characters:
input_string = input_string.replace(char, "")

return input_string

0 comments on commit 8f316f6

Please sign in to comment.