From ac1fb4a63ac7619f248b035f063f8d34723cc30a Mon Sep 17 00:00:00 2001 From: 26751 <2675174581@qq.com> Date: Sat, 1 Apr 2023 00:52:35 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=8F=90=E7=A4=BA=E8=AF=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/cmds/mgr.py | 7 +++++-- pkg/qqbot/command.py | 2 +- pkg/qqbot/manager.py | 5 +++-- pkg/qqbot/message.py | 3 ++- pkg/qqbot/process.py | 3 ++- tips_custom.py | 41 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 tips_custom.py diff --git a/pkg/qqbot/cmds/mgr.py b/pkg/qqbot/cmds/mgr.py index da45d160..b1022cf7 100644 --- a/pkg/qqbot/cmds/mgr.py +++ b/pkg/qqbot/cmds/mgr.py @@ -9,6 +9,9 @@ import json __command_list__ = {} + +import tips_custom + """命令树 结构: @@ -262,7 +265,7 @@ def execute(context: Context) -> list: # 检查权限 if ctx.privilege < node['privilege']: - raise CommandPrivilegeError('权限不足: {}'.format(path)) + raise CommandPrivilegeError(tips_custom.command_admin_message) # 执行 execed, reply = node['cls'].process(ctx) @@ -275,7 +278,7 @@ def execute(context: Context) -> list: path = path + '.' + ctx.crt_command except KeyError: traceback.print_exc() - raise CommandPrivilegeError('找不到指令: {}'.format(path)) + raise CommandPrivilegeError(tips_custom.command_err_message) def register_all(): diff --git a/pkg/qqbot/command.py b/pkg/qqbot/command.py index 3527c5a8..1e01bab3 100644 --- a/pkg/qqbot/command.py +++ b/pkg/qqbot/command.py @@ -54,7 +54,7 @@ def process_command(session_name: str, text_message: str, mgr, config, try: reply = cmdmgr.execute(context) except cmdmgr.CommandPrivilegeError as e: - reply = ["[bot]err:{}".format(e)] + reply = [format(e)] return reply except Exception as e: diff --git a/pkg/qqbot/manager.py b/pkg/qqbot/manager.py index 300edca8..bfb9b747 100644 --- a/pkg/qqbot/manager.py +++ b/pkg/qqbot/manager.py @@ -19,6 +19,7 @@ import pkg.utils.context import pkg.plugin.host as plugin_host import pkg.plugin.models as plugin_models +import tips_custom # 检查消息是否符合泛响应匹配机制 @@ -268,7 +269,7 @@ class QQBotManager: if failed == self.retry: pkg.openai.session.get_session('person_{}'.format(event.sender.id)).release_response_lock() self.notify_admin("{} 请求超时".format("person_{}".format(event.sender.id))) - reply = ["[bot]err:请求超时"] + reply = tips_custom.reply_message if reply: return self.send(event, reply, check_quote=False) @@ -308,7 +309,7 @@ class QQBotManager: if failed == self.retry: pkg.openai.session.get_session('group_{}'.format(event.group.id)).release_response_lock() self.notify_admin("{} 请求超时".format("group_{}".format(event.group.id))) - replys = ["[bot]err:请求超时"] + replys = tips_custom.replys_message return replys diff --git a/pkg/qqbot/message.py b/pkg/qqbot/message.py index 9d124fc3..bb8c640c 100644 --- a/pkg/qqbot/message.py +++ b/pkg/qqbot/message.py @@ -7,6 +7,7 @@ import pkg.openai.session import pkg.plugin.host as plugin_host import pkg.plugin.models as plugin_models import pkg.qqbot.blob as blob +import tips_custom def handle_exception(notify_admin: str = "", set_reply: str = "") -> list: @@ -15,7 +16,7 @@ def handle_exception(notify_admin: str = "", set_reply: str = "") -> list: pkg.utils.context.get_qqbot_manager().notify_admin(notify_admin) if hasattr(config, 'hide_exce_info_to_user') and config.hide_exce_info_to_user: if hasattr(config, 'alter_tip_message'): - return [config.alter_tip_message] if config.alter_tip_message else [] + return [tips_custom.alter_tip_message] if tips_custom.alter_tip_message else [] else: return ["[bot]出错了,请重试或联系管理员"] else: diff --git a/pkg/qqbot/process.py b/pkg/qqbot/process.py index 4dda7521..056f0724 100644 --- a/pkg/qqbot/process.py +++ b/pkg/qqbot/process.py @@ -27,6 +27,7 @@ import pkg.plugin.models as plugin_models import pkg.qqbot.ignore as ignore import pkg.qqbot.banlist as banlist import pkg.qqbot.blob as blob +import tips_custom processing = [] @@ -118,7 +119,7 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes if hasattr(config, "rate_limitation") and config.rate_limit_strategy == "drop": if ratelimit.is_reach_limit(session_name): logging.info("根据限速策略丢弃[{}]消息: {}".format(session_name, text_message)) - return MessageChain(["[bot]"+config.rate_limit_drop_tip]) if hasattr(config, "rate_limit_drop_tip") and config.rate_limit_drop_tip != "" else [] + return MessageChain(["[bot]"+tips_custom.rate_limit_drop_tip]) if hasattr(tips_custom, "rate_limit_drop_tip") and tips_custom.rate_limit_drop_tip != "" else [] before = time.time() # 触发插件事件 diff --git a/tips_custom.py b/tips_custom.py new file mode 100644 index 00000000..ae40d72e --- /dev/null +++ b/tips_custom.py @@ -0,0 +1,41 @@ +import config + +# ---------------------------------------------花里胡哨参数--------------------------------------------- +# ---原config.py开始-- + +# 消息处理出错时向用户发送的提示信息,仅当hide_exce_info_to_user为True时生效 +# 设置为空字符串时,不发送提示信息 +# config.py,line:232 +# pkg/qqbot/message.py,line:19 +alter_tip_message = '天空一声巨响,魔法少女闪亮登场,唉呀脚滑了,疼~等会再来~(这是一条全世界最人见人爱花见花开玉树临风英俊潇洒美丽且可爱的出错提醒哦~)' + +# drop策略时,超过限速均值时,丢弃的对话的提示信息,仅当rate_limitation_strategy为"drop"时生效 +# 若设置为空字符串,则不发送提示信息 +# config.py,line:265 +# pkg/qqbot/process.py,line:122 +rate_limit_drop_tip = "欧尼酱慢点我跟不上" + +# 指令!help帮助消息 +# config.py,line:279 +# pkg/qqbot/process.py,line:122 +help_message = """ +这是一个很正经的帮助文档 +此处省略10086字... +biu~biu~biu~""".format(config.session_expire_time // 60) + +# ---原config.py结束-- + +# QChatGPT/pkg/qqbot/manager.py +# 私聊消息超时提示,line:271 +reply_message = "天空一声巨响,魔法少女闪亮登场,哎呀脚滑了,疼~(这是一条全世界最人见人爱花见花开玉树临风英俊潇洒美丽且可爱的超时提醒哦。)" +# 群聊消息超时提示,line:310 +replys_message = "天空一声巨响,魔法少女闪亮登场,哎呀脚滑了,疼~(这是一条全世界最人见人爱花见花开玉树临风英俊潇洒美丽且可爱的超时提醒哦。)" + +# 指令权限不足/无效提示 +# QChatGPT/pkg/qqbot/command.py,line:57 +# 更改代码 +# reply = [format(e)] +# QChatGPT/pkg/qqbot/cmds/mgr.py +# line:266,279 +command_admin_message = "你居然想偷看我裙底?坏蛋,大坏蛋,超级大坏蛋,无敌超级大坏蛋,宇宙无敌超级大坏蛋。哼! " +command_err_message = "你又再想涩涩的事了?" From 2050d20ea79a28bd6d5bd03bc48b237c19db4ba8 Mon Sep 17 00:00:00 2001 From: 26751 <2675174581@qq.com> Date: Sat, 1 Apr 2023 02:14:25 +0800 Subject: [PATCH 02/14] Signed-off-by: 26751 <2675174581@qq.com> --- config-template.py | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/config-template.py b/config-template.py index 7ff08d26..98957ceb 100644 --- a/config-template.py +++ b/config-template.py @@ -145,8 +145,6 @@ baidu_api_key = "" # 百度云SECRET_KEY 32位的英文数字字符串 baidu_secret_key = "" -# 不合规消息自定义返回 -inappropriate_message_tips = "[百度云]请珍惜机器人,当前返回内容不合规" # 启动时是否发送赞赏码 # 仅当使用量已经超过2048字时发送 @@ -226,10 +224,6 @@ retry_times = 3 # 设置为False时,向用户及管理员发送错误详细信息 hide_exce_info_to_user = False -# 消息处理出错时向用户发送的提示信息 -# 仅当hide_exce_info_to_user为True时生效 -# 设置为空字符串时,不发送提示信息 -alter_tip_message = '出错了,请稍后再试' # 线程池相关配置 # 该参数决定机器人可以同时处理几个人的消息,超出线程池数量的请求会被阻塞,不会被丢弃 @@ -259,10 +253,7 @@ rate_limitation = 60 # - "drop": 此分钟内,若对话次数超过限速次数,则丢弃之后的对话,每自然分钟重置 rate_limit_strategy = "wait" -# drop策略时,超过限速均值时,丢弃的对话的提示信息 -# 仅当rate_limitation_strategy为"drop"时生效 -# 若设置为空字符串,则不发送提示信息 -rate_limit_drop_tip = "本分钟对话次数超过限速次数,此对话被丢弃" + # 是否在启动时进行依赖库更新 upgrade_dependencies = True @@ -274,13 +265,3 @@ report_usage = True # 日志级别 logging_level = logging.INFO - -# 定制帮助消息 -help_message = """此机器人通过调用OpenAI的GPT-3大型语言模型生成回复,不具有情感。 -你可以用自然语言与其交流,回复的消息中[GPT]开头的为模型生成的语言,[bot]开头的为程序提示。 -了解此项目请找QQ 1010553892 联系作者 -请不要用其生成整篇文章或大段代码,因为每次只会向模型提交少部分文字,生成大部分文字会产生偏题、前后矛盾等问题 -每次会话最后一次交互后{}分钟后会自动结束,结束后将开启新会话,如需继续前一次会话请发送 !last 重新开启 -欢迎到github.com/RockChinQ/QChatGPT 给个star - -指令帮助信息请查看: https://github.com/RockChinQ/QChatGPT/wiki/%E5%8A%9F%E8%83%BD%E4%BD%BF%E7%94%A8#%E6%9C%BA%E5%99%A8%E4%BA%BA%E6%8C%87%E4%BB%A4""".format(session_expire_time // 60) From b6f7f3b73fdaaef297093f84e5dbce689587119b Mon Sep 17 00:00:00 2001 From: 26751 <2675174581@qq.com> Date: Sat, 1 Apr 2023 02:35:27 +0800 Subject: [PATCH 03/14] Signed-off-by: 26751 <2675174581@qq.com> --- config-template.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/config-template.py b/config-template.py index 98957ceb..8e57ad54 100644 --- a/config-template.py +++ b/config-template.py @@ -145,6 +145,8 @@ baidu_api_key = "" # 百度云SECRET_KEY 32位的英文数字字符串 baidu_secret_key = "" +# 不合规消息自定义返回 +inappropriate_message_tips = "[百度云]请珍爱机器人,当前返回内容不合规" # 启动时是否发送赞赏码 # 仅当使用量已经超过2048字时发送 @@ -224,7 +226,6 @@ retry_times = 3 # 设置为False时,向用户及管理员发送错误详细信息 hide_exce_info_to_user = False - # 线程池相关配置 # 该参数决定机器人可以同时处理几个人的消息,超出线程池数量的请求会被阻塞,不会被丢弃 # 如果你不清楚该参数的意义,请不要更改 @@ -253,8 +254,6 @@ rate_limitation = 60 # - "drop": 此分钟内,若对话次数超过限速次数,则丢弃之后的对话,每自然分钟重置 rate_limit_strategy = "wait" - - # 是否在启动时进行依赖库更新 upgrade_dependencies = True From da0391161002ed96ca3d51bd1cfbecfbbcabd8ce Mon Sep 17 00:00:00 2001 From: 26751 <2675174581@qq.com> Date: Sat, 1 Apr 2023 16:09:07 +0800 Subject: [PATCH 04/14] Signed-off-by: 26751 <2675174581@qq.com> --- config-template.py | 2 ++ main.py | 4 ++++ pkg/qqbot/cmds/mgr.py | 4 ++-- pkg/qqbot/command.py | 2 +- tips_custom.py | 24 ++++++++++++---------- tips_custom_template.py | 44 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 tips_custom_template.py diff --git a/config-template.py b/config-template.py index 8e57ad54..391b600a 100644 --- a/config-template.py +++ b/config-template.py @@ -253,6 +253,8 @@ rate_limitation = 60 # - "wait": 每次对话获取到回复时,等待一定时间再发送回复,保证其不会超过限速均值 # - "drop": 此分钟内,若对话次数超过限速次数,则丢弃之后的对话,每自然分钟重置 rate_limit_strategy = "wait" +# drop策略时,超过限速均值时,丢弃的对话的提示信息,仅当rate_limitation_strategy为"drop"时生效 +# 转tips_custom.py中rate_limit_drop_tip字段 # 是否在启动时进行依赖库更新 upgrade_dependencies = True diff --git a/main.py b/main.py index fdac1d67..196a3dc0 100644 --- a/main.py +++ b/main.py @@ -378,6 +378,10 @@ def check_file(): if not os.path.exists("cmdpriv.json"): shutil.copy("cmdpriv-template.json", "cmdpriv.json") + # 检查tips_custom + if not os.path.exists("tips_custom.py"): + shutil.copy("tips_custom_template.py", "tips_custom.py") + # 检查temp目录 if not os.path.exists("temp/"): os.mkdir("temp/") diff --git a/pkg/qqbot/cmds/mgr.py b/pkg/qqbot/cmds/mgr.py index b1022cf7..b2f92853 100644 --- a/pkg/qqbot/cmds/mgr.py +++ b/pkg/qqbot/cmds/mgr.py @@ -265,7 +265,7 @@ def execute(context: Context) -> list: # 检查权限 if ctx.privilege < node['privilege']: - raise CommandPrivilegeError(tips_custom.command_admin_message) + raise CommandPrivilegeError(tips_custom.command_admin_message+"{}".format(path)) # 执行 execed, reply = node['cls'].process(ctx) @@ -278,7 +278,7 @@ def execute(context: Context) -> list: path = path + '.' + ctx.crt_command except KeyError: traceback.print_exc() - raise CommandPrivilegeError(tips_custom.command_err_message) + raise CommandPrivilegeError(tips_custom.command_err_message+"{}".format(path)) def register_all(): diff --git a/pkg/qqbot/command.py b/pkg/qqbot/command.py index 1e01bab3..d3141d95 100644 --- a/pkg/qqbot/command.py +++ b/pkg/qqbot/command.py @@ -54,7 +54,7 @@ def process_command(session_name: str, text_message: str, mgr, config, try: reply = cmdmgr.execute(context) except cmdmgr.CommandPrivilegeError as e: - reply = [format(e)] + reply = ["{}".format(e)] return reply except Exception as e: diff --git a/tips_custom.py b/tips_custom.py index ae40d72e..d37ad1c7 100644 --- a/tips_custom.py +++ b/tips_custom.py @@ -7,29 +7,33 @@ import config # 设置为空字符串时,不发送提示信息 # config.py,line:232 # pkg/qqbot/message.py,line:19 -alter_tip_message = '天空一声巨响,魔法少女闪亮登场,唉呀脚滑了,疼~等会再来~(这是一条全世界最人见人爱花见花开玉树临风英俊潇洒美丽且可爱的出错提醒哦~)' +alter_tip_message = '出错了,请稍后再试' # drop策略时,超过限速均值时,丢弃的对话的提示信息,仅当rate_limitation_strategy为"drop"时生效 # 若设置为空字符串,则不发送提示信息 # config.py,line:265 # pkg/qqbot/process.py,line:122 -rate_limit_drop_tip = "欧尼酱慢点我跟不上" +rate_limit_drop_tip = "本分钟对话次数超过限速次数,此对话被丢弃" # 指令!help帮助消息 # config.py,line:279 # pkg/qqbot/process.py,line:122 -help_message = """ -这是一个很正经的帮助文档 -此处省略10086字... -biu~biu~biu~""".format(config.session_expire_time // 60) +help_message = """【可自定义】 +此机器人通过调用OpenAI的GPT-3大型语言模型生成回复,不具有情感。 +你可以用自然语言与其交流,回复的消息中[GPT]开头的为模型生成的语言,[bot]开头的为程序提示。 +了解此项目请找QQ 1010553892 联系作者 +请不要用其生成整篇文章或大段代码,因为每次只会向模型提交少部分文字,生成大部分文字会产生偏题、前后矛盾等问题 +每次会话最后一次交互后{}分钟后会自动结束,结束后将开启新会话,如需继续前一次会话请发送 !last 重新开启 +欢迎到github.com/RockChinQ/QChatGPT 给个star +指令帮助信息请查看: https://github.com/RockChinQ/QChatGPT/wiki/%E5%8A%9F%E8%83%BD%E4%BD%BF%E7%94%A8#%E6%9C%BA%E5%99%A8%E4%BA%BA%E6%8C%87%E4%BB%A4""".format(config.session_expire_time // 60) # ---原config.py结束-- # QChatGPT/pkg/qqbot/manager.py # 私聊消息超时提示,line:271 -reply_message = "天空一声巨响,魔法少女闪亮登场,哎呀脚滑了,疼~(这是一条全世界最人见人爱花见花开玉树临风英俊潇洒美丽且可爱的超时提醒哦。)" +reply_message = ["私聊请求超时"] # 群聊消息超时提示,line:310 -replys_message = "天空一声巨响,魔法少女闪亮登场,哎呀脚滑了,疼~(这是一条全世界最人见人爱花见花开玉树临风英俊潇洒美丽且可爱的超时提醒哦。)" +replys_message = ["群聊请求超时"] # 指令权限不足/无效提示 # QChatGPT/pkg/qqbot/command.py,line:57 @@ -37,5 +41,5 @@ replys_message = "天空一声巨响,魔法少女闪亮登场,哎呀脚滑 # reply = [format(e)] # QChatGPT/pkg/qqbot/cmds/mgr.py # line:266,279 -command_admin_message = "你居然想偷看我裙底?坏蛋,大坏蛋,超级大坏蛋,无敌超级大坏蛋,宇宙无敌超级大坏蛋。哼! " -command_err_message = "你又再想涩涩的事了?" +command_admin_message = "权限不足: " +command_err_message = "指令执行出错:" diff --git a/tips_custom_template.py b/tips_custom_template.py new file mode 100644 index 00000000..4cae59a9 --- /dev/null +++ b/tips_custom_template.py @@ -0,0 +1,44 @@ +import config + +# ---------------------------------------------花里胡哨参数--------------------------------------------- +# ---原config.py开始-- + +# 消息处理出错时向用户发送的提示信息,仅当hide_exce_info_to_user为True时生效 +# 设置为空字符串时,不发送提示信息 +# config.py,line:232 +# pkg/qqbot/message.py,line:19 +alter_tip_message = '出错了,请稍后再试' + +# drop策略时,超过限速均值时,丢弃的对话的提示信息,仅当rate_limitation_strategy为"drop"时生效 +# 若设置为空字符串,则不发送提示信息 +# config.py,line:265 +# pkg/qqbot/process.py,line:122 +rate_limit_drop_tip = "本分钟对话次数超过限速次数,此对话被丢弃" + +# 指令!help帮助消息 +# config.py,line:279 +# pkg/qqbot/process.py,line:122 +help_message = """【可自定义】 +此机器人通过调用OpenAI的GPT-3大型语言模型生成回复,不具有情感。 +你可以用自然语言与其交流,回复的消息中[GPT]开头的为模型生成的语言,[bot]开头的为程序提示。 +了解此项目请找QQ 1010553892 联系作者 +请不要用其生成整篇文章或大段代码,因为每次只会向模型提交少部分文字,生成大部分文字会产生偏题、前后矛盾等问题 +每次会话最后一次交互后{}分钟后会自动结束,结束后将开启新会话,如需继续前一次会话请发送 !last 重新开启 +欢迎到github.com/RockChinQ/QChatGPT 给个star +指令帮助信息请查看: https://github.com/RockChinQ/QChatGPT/wiki/%E5%8A%9F%E8%83%BD%E4%BD%BF%E7%94%A8#%E6%9C%BA%E5%99%A8%E4%BA%BA%E6%8C%87%E4%BB%A4""".format(config.session_expire_time // 60) + +# ---原config.py结束-- + +# QChatGPT/pkg/qqbot/manager.py +# 私聊消息超时提示,line:271 +reply_message = ["私聊请求超时"] +# 群聊消息超时提示,line:310 +replys_message = ["群聊请求超时"] + +# 指令权限不足/无效提示 +# QChatGPT/pkg/qqbot/command.py,line:57 +# 更改代码 +# QChatGPT/pkg/qqbot/cmds/mgr.py +# line:266,279 +command_admin_message = "权限不足: " +command_err_message = "指令执行出错:" From 48dcd257da099c18f86a52073fa4e492b76cc88b Mon Sep 17 00:00:00 2001 From: 26751 <2675174581@qq.com> Date: Sat, 1 Apr 2023 18:29:24 +0800 Subject: [PATCH 05/14] Signed-off-by: 26751 <2675174581@qq.com> --- pkg/qqbot/cmds/session/reset.py | 5 +++-- tips_custom_template.py | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/qqbot/cmds/session/reset.py b/pkg/qqbot/cmds/session/reset.py index 269cdb30..483defea 100644 --- a/pkg/qqbot/cmds/session/reset.py +++ b/pkg/qqbot/cmds/session/reset.py @@ -1,3 +1,4 @@ +import tips_custom from ..mgr import AbstractCommandNode, Context import pkg.openai.session @@ -22,12 +23,12 @@ class ResetCommand(AbstractCommandNode): if len(params) == 0: pkg.openai.session.get_session(session_name).reset(explicit=True) - reply = ["[bot]会话已重置"] + reply = tips_custom.command_reset_message else: try: import pkg.openai.dprompt as dprompt pkg.openai.session.get_session(session_name).reset(explicit=True, use_prompt=params[0]) - reply = ["[bot]会话已重置,使用场景预设:{}".format(dprompt.mode_inst().get_full_name(params[0]))] + reply = [tips_custom.command_reset_name_message+"{}".format(dprompt.mode_inst().get_full_name(params[0]))] except Exception as e: reply = ["[bot]会话重置失败:{}".format(e)] diff --git a/tips_custom_template.py b/tips_custom_template.py index 4cae59a9..d9f72562 100644 --- a/tips_custom_template.py +++ b/tips_custom_template.py @@ -25,7 +25,8 @@ help_message = """【可自定义】 请不要用其生成整篇文章或大段代码,因为每次只会向模型提交少部分文字,生成大部分文字会产生偏题、前后矛盾等问题 每次会话最后一次交互后{}分钟后会自动结束,结束后将开启新会话,如需继续前一次会话请发送 !last 重新开启 欢迎到github.com/RockChinQ/QChatGPT 给个star -指令帮助信息请查看: https://github.com/RockChinQ/QChatGPT/wiki/%E5%8A%9F%E8%83%BD%E4%BD%BF%E7%94%A8#%E6%9C%BA%E5%99%A8%E4%BA%BA%E6%8C%87%E4%BB%A4""".format(config.session_expire_time // 60) +指令帮助信息请查看: https://github.com/RockChinQ/QChatGPT/wiki/%E5%8A%9F%E8%83%BD%E4%BD%BF%E7%94%A8#%E6%9C%BA%E5%99%A8%E4%BA%BA%E6%8C%87%E4%BB%A4""".format( + config.session_expire_time // 60) # ---原config.py结束-- @@ -42,3 +43,8 @@ replys_message = ["群聊请求超时"] # line:266,279 command_admin_message = "权限不足: " command_err_message = "指令执行出错:" + +# 会话重置提示 +# pkg/qqbot/cmds/session/reset.py,line:25,31 +command_reset_message = ["[bot]会话已重置"] +command_reset_name_message = ["[bot]会话已重置,使用场景预设:"] From 973ef0078ff17ea9fbc4bcb3d942c77a579afe52 Mon Sep 17 00:00:00 2001 From: 2675hujilo <113016971+2675hujilo@users.noreply.github.com> Date: Sat, 1 Apr 2023 18:36:33 +0800 Subject: [PATCH 06/14] Delete tips_custom.py --- tips_custom.py | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 tips_custom.py diff --git a/tips_custom.py b/tips_custom.py deleted file mode 100644 index d37ad1c7..00000000 --- a/tips_custom.py +++ /dev/null @@ -1,45 +0,0 @@ -import config - -# ---------------------------------------------花里胡哨参数--------------------------------------------- -# ---原config.py开始-- - -# 消息处理出错时向用户发送的提示信息,仅当hide_exce_info_to_user为True时生效 -# 设置为空字符串时,不发送提示信息 -# config.py,line:232 -# pkg/qqbot/message.py,line:19 -alter_tip_message = '出错了,请稍后再试' - -# drop策略时,超过限速均值时,丢弃的对话的提示信息,仅当rate_limitation_strategy为"drop"时生效 -# 若设置为空字符串,则不发送提示信息 -# config.py,line:265 -# pkg/qqbot/process.py,line:122 -rate_limit_drop_tip = "本分钟对话次数超过限速次数,此对话被丢弃" - -# 指令!help帮助消息 -# config.py,line:279 -# pkg/qqbot/process.py,line:122 -help_message = """【可自定义】 -此机器人通过调用OpenAI的GPT-3大型语言模型生成回复,不具有情感。 -你可以用自然语言与其交流,回复的消息中[GPT]开头的为模型生成的语言,[bot]开头的为程序提示。 -了解此项目请找QQ 1010553892 联系作者 -请不要用其生成整篇文章或大段代码,因为每次只会向模型提交少部分文字,生成大部分文字会产生偏题、前后矛盾等问题 -每次会话最后一次交互后{}分钟后会自动结束,结束后将开启新会话,如需继续前一次会话请发送 !last 重新开启 -欢迎到github.com/RockChinQ/QChatGPT 给个star -指令帮助信息请查看: https://github.com/RockChinQ/QChatGPT/wiki/%E5%8A%9F%E8%83%BD%E4%BD%BF%E7%94%A8#%E6%9C%BA%E5%99%A8%E4%BA%BA%E6%8C%87%E4%BB%A4""".format(config.session_expire_time // 60) - -# ---原config.py结束-- - -# QChatGPT/pkg/qqbot/manager.py -# 私聊消息超时提示,line:271 -reply_message = ["私聊请求超时"] -# 群聊消息超时提示,line:310 -replys_message = ["群聊请求超时"] - -# 指令权限不足/无效提示 -# QChatGPT/pkg/qqbot/command.py,line:57 -# 更改代码 -# reply = [format(e)] -# QChatGPT/pkg/qqbot/cmds/mgr.py -# line:266,279 -command_admin_message = "权限不足: " -command_err_message = "指令执行出错:" From d37c31b31c756b1b6c0a1ca84d5caec49b684dfb Mon Sep 17 00:00:00 2001 From: 2675hujilo <113016971+2675hujilo@users.noreply.github.com> Date: Sat, 1 Apr 2023 18:43:03 +0800 Subject: [PATCH 07/14] Update tips_custom_template.py --- tips_custom_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tips_custom_template.py b/tips_custom_template.py index d9f72562..5ba44879 100644 --- a/tips_custom_template.py +++ b/tips_custom_template.py @@ -47,4 +47,4 @@ command_err_message = "指令执行出错:" # 会话重置提示 # pkg/qqbot/cmds/session/reset.py,line:25,31 command_reset_message = ["[bot]会话已重置"] -command_reset_name_message = ["[bot]会话已重置,使用场景预设:"] +command_reset_name_message = "[bot]会话已重置,使用场景预设:" From 4061a92f8e764cc5c0058414b3ce92bc3bc8d2d2 Mon Sep 17 00:00:00 2001 From: 26751 <2675174581@qq.com> Date: Sun, 2 Apr 2023 13:36:51 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E5=88=A0=E9=99=A4override-all.json?= =?UTF-8?q?=E4=B8=AD=E6=97=A0=E6=95=88=E7=9A=84=E5=AD=97=E6=AE=B5=20Signed?= =?UTF-8?q?-off-by:=2026751=20<2675174581@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- override-all.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/override-all.json b/override-all.json index b0269b01..d60a5807 100644 --- a/override-all.json +++ b/override-all.json @@ -63,16 +63,13 @@ "font_path": "", "retry_times": 3, "hide_exce_info_to_user": false, - "alter_tip_message": "出错了,请稍后再试", "sys_pool_num": 8, "admin_pool_num": 2, "user_pool_num": 6, "session_expire_time": 1200, "rate_limitation": 60, "rate_limit_strategy": "wait", - "rate_limit_drop_tip": "本分钟对话次数超过限速次数,此对话被丢弃", "upgrade_dependencies": true, "report_usage": true, - "logging_level": 20, - "help_message": "此机器人通过调用OpenAI的GPT-3大型语言模型生成回复,不具有情感。\n你可以用自然语言与其交流,回复的消息中[GPT]开头的为模型生成的语言,[bot]开头的为程序提示。\n了解此项目请找QQ 1010553892 联系作者\n请不要用其生成整篇文章或大段代码,因为每次只会向模型提交少部分文字,生成大部分文字会产生偏题、前后矛盾等问题\n每次会话最后一次交互后20分钟后会自动结束,结束后将开启新会话,如需继续前一次会话请发送 !last 重新开启\n欢迎到github.com/RockChinQ/QChatGPT 给个star\n\n指令帮助信息请查看: https://github.com/RockChinQ/QChatGPT/wiki/%E5%8A%9F%E8%83%BD%E4%BD%BF%E7%94%A8#%E6%9C%BA%E5%99%A8%E4%BA%BA%E6%8C%87%E4%BB%A4" + "logging_level": 20 } \ No newline at end of file From 5865ac017c87f7967dc37c21dab45d70db3a0439 Mon Sep 17 00:00:00 2001 From: 26751 <2675174581@qq.com> Date: Sun, 2 Apr 2023 13:46:15 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E5=A2=9E=E5=8A=A0tips=5Fcustom.py?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=20Signed-off-by:=2026751=20<2675174581@qq.co?= =?UTF-8?q?m>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config-template.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config-template.py b/config-template.py index 391b600a..74746566 100644 --- a/config-template.py +++ b/config-template.py @@ -225,6 +225,8 @@ retry_times = 3 # 设置为True时,仅向管理员发送错误详细信息 # 设置为False时,向用户及管理员发送错误详细信息 hide_exce_info_to_user = False +# 消息处理出错时向用户发送的提示信息 +#转tips_custom.py中alter_tip_message字段 # 线程池相关配置 # 该参数决定机器人可以同时处理几个人的消息,超出线程池数量的请求会被阻塞,不会被丢弃 From 83d02aaaac3d5d06cde091c4d7e46bc89fb9e27b Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Fri, 7 Apr 2023 13:20:57 +0800 Subject: [PATCH 10/14] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- main.py | 4 ++-- pkg/qqbot/cmds/mgr.py | 2 +- pkg/qqbot/cmds/session/reset.py | 2 +- pkg/qqbot/manager.py | 2 +- pkg/qqbot/message.py | 2 +- pkg/qqbot/process.py | 2 +- tips_custom_template.py => tips-custom-template.py | 0 8 files changed, 9 insertions(+), 8 deletions(-) rename tips_custom_template.py => tips-custom-template.py (100%) diff --git a/.gitignore b/.gitignore index e9a9cf30..5679094d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ scenario/ override.json cookies.json res/announcement_saved -cmdpriv.json \ No newline at end of file +cmdpriv.json +tips.py \ No newline at end of file diff --git a/main.py b/main.py index 196a3dc0..ec70748c 100644 --- a/main.py +++ b/main.py @@ -379,8 +379,8 @@ def check_file(): shutil.copy("cmdpriv-template.json", "cmdpriv.json") # 检查tips_custom - if not os.path.exists("tips_custom.py"): - shutil.copy("tips_custom_template.py", "tips_custom.py") + if not os.path.exists("tips.py"): + shutil.copy("tips-custom-template.py", "tips.py") # 检查temp目录 if not os.path.exists("temp/"): diff --git a/pkg/qqbot/cmds/mgr.py b/pkg/qqbot/cmds/mgr.py index b2f92853..2bc64059 100644 --- a/pkg/qqbot/cmds/mgr.py +++ b/pkg/qqbot/cmds/mgr.py @@ -10,7 +10,7 @@ import json __command_list__ = {} -import tips_custom +import tips as tips_custom """命令树 diff --git a/pkg/qqbot/cmds/session/reset.py b/pkg/qqbot/cmds/session/reset.py index 483defea..3b43187f 100644 --- a/pkg/qqbot/cmds/session/reset.py +++ b/pkg/qqbot/cmds/session/reset.py @@ -1,4 +1,4 @@ -import tips_custom +import tips as tips_custom from ..mgr import AbstractCommandNode, Context import pkg.openai.session diff --git a/pkg/qqbot/manager.py b/pkg/qqbot/manager.py index bfb9b747..2e98f625 100644 --- a/pkg/qqbot/manager.py +++ b/pkg/qqbot/manager.py @@ -19,7 +19,7 @@ import pkg.utils.context import pkg.plugin.host as plugin_host import pkg.plugin.models as plugin_models -import tips_custom +import tips as tips_custom # 检查消息是否符合泛响应匹配机制 diff --git a/pkg/qqbot/message.py b/pkg/qqbot/message.py index bb8c640c..fe66f8d6 100644 --- a/pkg/qqbot/message.py +++ b/pkg/qqbot/message.py @@ -7,7 +7,7 @@ import pkg.openai.session import pkg.plugin.host as plugin_host import pkg.plugin.models as plugin_models import pkg.qqbot.blob as blob -import tips_custom +import tips as tips_custom def handle_exception(notify_admin: str = "", set_reply: str = "") -> list: diff --git a/pkg/qqbot/process.py b/pkg/qqbot/process.py index 056f0724..077d366f 100644 --- a/pkg/qqbot/process.py +++ b/pkg/qqbot/process.py @@ -27,7 +27,7 @@ import pkg.plugin.models as plugin_models import pkg.qqbot.ignore as ignore import pkg.qqbot.banlist as banlist import pkg.qqbot.blob as blob -import tips_custom +import tips as tips_custom processing = [] diff --git a/tips_custom_template.py b/tips-custom-template.py similarity index 100% rename from tips_custom_template.py rename to tips-custom-template.py From 07abad6a148000e40d5534d263433e5ad0ae5e8a Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Fri, 7 Apr 2023 13:23:58 +0800 Subject: [PATCH 11/14] =?UTF-8?q?feat:=20=E5=B0=86tips=E7=9A=84=E5=80=BC?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=B8=BAstr=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/cmds/session/reset.py | 2 +- pkg/qqbot/manager.py | 4 ++-- tips-custom-template.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/qqbot/cmds/session/reset.py b/pkg/qqbot/cmds/session/reset.py index 3b43187f..172e5130 100644 --- a/pkg/qqbot/cmds/session/reset.py +++ b/pkg/qqbot/cmds/session/reset.py @@ -23,7 +23,7 @@ class ResetCommand(AbstractCommandNode): if len(params) == 0: pkg.openai.session.get_session(session_name).reset(explicit=True) - reply = tips_custom.command_reset_message + reply = [tips_custom.command_reset_message] else: try: import pkg.openai.dprompt as dprompt diff --git a/pkg/qqbot/manager.py b/pkg/qqbot/manager.py index 2e98f625..041dac19 100644 --- a/pkg/qqbot/manager.py +++ b/pkg/qqbot/manager.py @@ -269,7 +269,7 @@ class QQBotManager: if failed == self.retry: pkg.openai.session.get_session('person_{}'.format(event.sender.id)).release_response_lock() self.notify_admin("{} 请求超时".format("person_{}".format(event.sender.id))) - reply = tips_custom.reply_message + reply = [tips_custom.reply_message] if reply: return self.send(event, reply, check_quote=False) @@ -309,7 +309,7 @@ class QQBotManager: if failed == self.retry: pkg.openai.session.get_session('group_{}'.format(event.group.id)).release_response_lock() self.notify_admin("{} 请求超时".format("group_{}".format(event.group.id))) - replys = tips_custom.replys_message + replys = [tips_custom.replys_message] return replys diff --git a/tips-custom-template.py b/tips-custom-template.py index 5ba44879..f2ebe57c 100644 --- a/tips-custom-template.py +++ b/tips-custom-template.py @@ -32,9 +32,9 @@ help_message = """【可自定义】 # QChatGPT/pkg/qqbot/manager.py # 私聊消息超时提示,line:271 -reply_message = ["私聊请求超时"] +reply_message = "私聊请求超时" # 群聊消息超时提示,line:310 -replys_message = ["群聊请求超时"] +replys_message = "群聊请求超时" # 指令权限不足/无效提示 # QChatGPT/pkg/qqbot/command.py,line:57 @@ -46,5 +46,5 @@ command_err_message = "指令执行出错:" # 会话重置提示 # pkg/qqbot/cmds/session/reset.py,line:25,31 -command_reset_message = ["[bot]会话已重置"] +command_reset_message = "[bot]会话已重置" command_reset_name_message = "[bot]会话已重置,使用场景预设:" From 66224e5a32edc5176146aa5a119d78106cbe8bad Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Fri, 7 Apr 2023 13:25:57 +0800 Subject: [PATCH 12/14] =?UTF-8?q?fix:=20=E7=83=AD=E9=87=8D=E8=BD=BD?= =?UTF-8?q?=E5=90=8E=E6=9C=AA=E6=A3=80=E6=9F=A5=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=AD=98=E5=9C=A8=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/utils/reloader.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/utils/reloader.py b/pkg/utils/reloader.py index 46399d09..41ba2207 100644 --- a/pkg/utils/reloader.py +++ b/pkg/utils/reloader.py @@ -47,6 +47,9 @@ def reload_all(notify=True): import plugins walk(plugins) + # 初始化相关文件 + main.check_file() + # 执行启动流程 logging.info("执行程序启动流程") main.load_config() From a588d7f960dbad43a216a17c3f82d638562540d5 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Fri, 7 Apr 2023 13:28:07 +0800 Subject: [PATCH 13/14] =?UTF-8?q?feat:=20=E7=83=AD=E9=87=8D=E8=BD=BD?= =?UTF-8?q?=E5=8A=A0=E4=B8=8Atips=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/utils/reloader.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/utils/reloader.py b/pkg/utils/reloader.py index 41ba2207..d06821ec 100644 --- a/pkg/utils/reloader.py +++ b/pkg/utils/reloader.py @@ -41,6 +41,7 @@ def reload_all(notify=True): importlib.reload(__import__('config')) importlib.reload(__import__('main')) importlib.reload(__import__('banlist')) + importlib.reload(__import__('tips')) context.context = this_context # 重载插件 From a68e29dff68028cbbec4c141e9ed3a983d041732 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Fri, 7 Apr 2023 16:02:22 +0800 Subject: [PATCH 14/14] =?UTF-8?q?feat:=20tips=E6=A8=A1=E5=9D=97=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=E6=80=A7=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 28 +++++++++++++++++++++++++--- pkg/utils/reloader.py | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index ec70748c..03b2ecde 100644 --- a/main.py +++ b/main.py @@ -108,6 +108,7 @@ def reset_logging(): # 临时函数,用于加载config和上下文,未来统一放在config类 def load_config(): + logging.info("检查config模块完整性.") # 完整性校验 is_integrity = True config_template = importlib.import_module('config-template') @@ -119,7 +120,7 @@ def load_config(): is_integrity = False if not is_integrity: - logging.warning("配置文件不完整,请依据config-template.py检查config.py") + logging.warning("配置文件不完整,您可以依据config-template.py检查config.py") # 检查override.json覆盖 if os.path.exists("override.json"): @@ -132,13 +133,31 @@ def load_config(): logging.error("无法覆写配置[{}]为[{}],该配置不存在,请检查override.json是否正确".format(key, override_json[key])) if not is_integrity: - logging.warning("以上配置已被设为默认值,将在5秒后继续启动... ") - time.sleep(5) + logging.warning("以上配置已被设为默认值,将在3秒后继续启动... ") + time.sleep(3) # 存进上下文 pkg.utils.context.set_config(config) +def complete_tips(): + """根据tips-custom-template模块补全tips模块的属性""" + is_integrity = True + logging.info("检查tips模块完整性.") + tips_template = importlib.import_module('tips-custom-template') + tips = importlib.import_module('tips') + for key in dir(tips_template): + if not key.startswith("__") and not hasattr(tips, key): + setattr(tips, key, getattr(tips_template, key)) + logging.warning("[{}]不存在".format(key)) + is_integrity = False + + if not is_integrity: + logging.warning("tips模块不完整,您可以依据tips-custom-template.py检查tips.py") + logging.warning("以上配置已被设为默认值,将在3秒后继续启动... ") + time.sleep(3) + + def start(first_time_init=False): """启动流程,reload之后会被执行""" @@ -405,6 +424,9 @@ def main(): load_config() config = pkg.utils.context.get_config() + # 检查tips模块 + complete_tips() + # 配置线程池 from pkg.utils import ThreadCtl thread_ctl = ThreadCtl( diff --git a/pkg/utils/reloader.py b/pkg/utils/reloader.py index d06821ec..abe27fa0 100644 --- a/pkg/utils/reloader.py +++ b/pkg/utils/reloader.py @@ -54,6 +54,7 @@ def reload_all(notify=True): # 执行启动流程 logging.info("执行程序启动流程") main.load_config() + main.complete_tips() context.get_thread_ctl().reload( admin_pool_num=context.get_config().admin_pool_num, user_pool_num=context.get_config().user_pool_num