From d6ca059f6cf352641e9f0bc58bace488047e04b1 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Sat, 15 Apr 2023 17:33:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=8D=95=E4=BC=9A=E8=AF=9D=E5=86=85=E5=90=8C=E6=97=B6=E4=BB=85?= =?UTF-8?q?=E5=A4=84=E7=90=86=E4=B8=80=E6=9D=A1=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config-template.py | 10 ++++++++-- pkg/qqbot/process.py | 8 +++++--- tips-custom-template.py | 5 +++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/config-template.py b/config-template.py index f52b48b3..0f16e021 100644 --- a/config-template.py +++ b/config-template.py @@ -212,6 +212,12 @@ blob_message_threshold = 256 # - "forward": 将长消息转换为转发消息组件发送 blob_message_strategy = "forward" +# 允许等待 +# 同一会话内,是否等待上一条消息处理完成后再处理下一条消息 +# 若设置为False,若上一条未处理完时收到了新消息,将会丢弃新消息 +# 丢弃消息时的提示信息可以在tips.py中修改 +wait_last_done = True + # 文字转图片时使用的字体文件路径 # 当策略为"image"时生效 # 若在Windows系统下,程序会自动使用Windows自带的微软雅黑字体 @@ -233,11 +239,11 @@ hide_exce_info_to_user = False sys_pool_num = 8 # 执行管理员请求和指令的线程池并行线程数量,一般和管理员数量相等 -admin_pool_num = 2 +admin_pool_num = 4 # 执行用户请求和指令的线程池并行线程数量 # 如需要更高的并发,可以增大该值 -user_pool_num = 6 +user_pool_num = 8 # 每个会话的过期时间,单位为秒 # 默认值20分钟 diff --git a/pkg/qqbot/process.py b/pkg/qqbot/process.py index bf45c8a9..672696c8 100644 --- a/pkg/qqbot/process.py +++ b/pkg/qqbot/process.py @@ -59,6 +59,11 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes logging.info("根据忽略规则忽略消息: {}".format(text_message)) return [] + import config + + if not config.wait_last_done and session_name in processing: + return MessageChain([Plain(tips_custom.message_drop_tip)]) + # 检查是否被禁言 if launcher_type == 'group': result = mgr.bot.member_info(target=launcher_id, member_id=mgr.bot.qq).get() @@ -79,9 +84,6 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes # 处理消息 try: - if session_name in processing: - pkg.openai.session.get_session(session_name).release_response_lock() - return MessageChain([Plain("[bot]err:正在处理中,请稍后再试")]) config = pkg.utils.context.get_config() diff --git a/tips-custom-template.py b/tips-custom-template.py index 105566a2..6605baa5 100644 --- a/tips-custom-template.py +++ b/tips-custom-template.py @@ -9,6 +9,11 @@ alter_tip_message = '[bot]err:出错了,请稍后再试' # 若设置为空字符串,则不发送提示信息 rate_limit_drop_tip = "本分钟对话次数超过限速次数,此对话被丢弃" +# 只允许同时处理一条消息时,新消息被丢弃时的提示信息 +# 当config.py中的wait_last_done为False时生效 +# 若设置为空字符串,则不发送提示信息 +message_drop_tip = "[bot]当前有一条消息正在处理,请等待处理完成" + # 指令!help帮助消息 help_message = """此机器人通过调用大型语言模型生成回复,不具有情感。 你可以用自然语言与其交流,回复的消息中[GPT]开头的为模型生成的语言,[bot]开头的为程序提示。