fix: 修复表情包打字时间

This commit is contained in:
SengokuCola
2025-04-05 12:28:43 +08:00
parent 0e23cb5f59
commit bd753acd2c
3 changed files with 11 additions and 2 deletions

View File

@@ -1,4 +1,8 @@
这里放置了测试版本的细节更新
## [test-0.6.1-snapshot-1] - 2025-4-5
- 修复pfc回复出错bug
## [test-0.6.0-snapshot-9] - 2025-4-4
- 可以识别gif表情包

View File

@@ -64,7 +64,7 @@ class Message_Sender:
logger.warning(f"消息“{message.processed_plain_text}”已被撤回,不发送")
break
if not is_recalled:
typing_time = calculate_typing_time(message.processed_plain_text)
typing_time = calculate_typing_time(message.processed_plain_text,message.is_emoji)
await asyncio.sleep(typing_time)
message_json = message.to_dict()

View File

@@ -334,16 +334,18 @@ def process_llm_response(text: str) -> List[str]:
return sentences
def calculate_typing_time(input_string: str, chinese_time: float = 0.2, english_time: float = 0.1) -> float:
def calculate_typing_time(input_string: str, chinese_time: float = 0.2, english_time: float = 0.1, is_emoji: bool = False) -> float:
"""
计算输入字符串所需的时间,中文和英文字符有不同的输入时间
input_string (str): 输入的字符串
chinese_time (float): 中文字符的输入时间默认为0.2秒
english_time (float): 英文字符的输入时间默认为0.1秒
is_emoji (bool): 是否为emoji默认为False
特殊情况:
- 如果只有一个中文字符将使用3倍的中文输入时间
- 在所有输入结束后额外加上回车时间0.3秒
- 如果is_emoji为True将使用固定1秒的输入时间
"""
# 如果输入是列表,将其连接成字符串
@@ -376,6 +378,9 @@ def calculate_typing_time(input_string: str, chinese_time: float = 0.2, english_
else: # 其他字符(如英文)
total_time += english_time
if is_emoji:
total_time = 0.7
return total_time + 0.3 # 加上回车时间