diff --git a/src/plugins/chat/utils.py b/src/plugins/chat/utils.py index 9cf97e85..6b5af723 100644 --- a/src/plugins/chat/utils.py +++ b/src/plugins/chat/utils.py @@ -360,9 +360,12 @@ def calculate_typing_time(input_string: str, chinese_time: float = 0.2, english_ - 如果只有一个中文字符,将使用3倍的中文输入时间 - 在所有输入结束后,额外加上回车时间0.3秒 """ - # 回复、发送图片/表情包操作不计时 + # 回复、发送图片/表情包操作短暂计时 + total_time = 0.0 pattern = re.compile(r'\[[回复 ,表情包:,图片:][\s\S]*?\]') - input_string = re.sub(pattern, '', input_string) + if re.match(pattern, input_string): + input_string = re.sub(pattern, '', input_string) + total_time += random.randrange(1, 3, 0.1) mood_manager = MoodManager.get_instance() # 将0-1的唤醒度映射到-1到1 @@ -379,9 +382,8 @@ def calculate_typing_time(input_string: str, chinese_time: float = 0.2, english_ return chinese_time * 3 + 0.3 # 加上回车时间 # 正常计算所有字符的输入时间 - total_time = 0.0 for char in input_string: - if "\u4e00" <= char <= "\u9fff": # 判断是否为中文字符 + if not is_western_char(char): # 判断是否为中文字符 total_time += chinese_time else: # 其他字符(如英文) total_time += english_time