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] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=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 = "你又再想涩涩的事了?"