🐛 fix(ChatProcess.py): handle empty name by falling back to msg.author.name to prevent empty names in the chat

🔧 chore(ChatProcess.py): improve regex pattern to remove non-alphanumeric characters from name to match ^[a-zA-Z0-9_-]{1,64}$ pattern
This commit is contained in:
2023-09-02 21:14:22 +02:00
parent 1d2f5a3eed
commit e264d5f654

View File

@@ -117,8 +117,10 @@ class Chat:
else:
role = "user"
name = msg.author.global_name
# use re not make name match ^[a-zA-Z0-9_-]{1,64}$ by removing all non-alphanumeric characters
name = re.sub(r"[^a-zA-Z0-9_-]", "", name, flags=re.UNICODE)
# use re not make name match ^[a-zA-Z0-9_-]{1,64}$ by removing all non-alphanumeric characters
name = re.sub(r"[^a-zA-Z0-9_-]", "", name, flags=re.UNICODE)
if name == "":
name = msg.author.name
if not await moderate(self.openai_api_key, msg.content):
self.context.append(
{