From 3933a03cac49bcec540080729526e530df76c6a7 Mon Sep 17 00:00:00 2001 From: ClovertaTheTrilobita Date: Fri, 17 Jan 2025 11:28:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0ai=E5=8A=9F=E8=83=BD=20?= =?UTF-8?q?=E5=8F=AF=E9=80=89=E6=8B=A9=E5=BC=80=E5=90=AF=E6=88=96=E5=85=B3?= =?UTF-8?q?=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ai_chat/config/example.chat_ai.yaml | 4 ++++ src/ai_chat/config/example.openai.yaml | 3 --- src/qq_plugins/check.py | 12 +++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 src/ai_chat/config/example.chat_ai.yaml delete mode 100644 src/ai_chat/config/example.openai.yaml diff --git a/src/ai_chat/config/example.chat_ai.yaml b/src/ai_chat/config/example.chat_ai.yaml new file mode 100644 index 0000000..94fcb8f --- /dev/null +++ b/src/ai_chat/config/example.chat_ai.yaml @@ -0,0 +1,4 @@ +chat_ai: + url: "" + key: "" + active: "False" # True为启动ai功能,False为关闭功能 \ No newline at end of file diff --git a/src/ai_chat/config/example.openai.yaml b/src/ai_chat/config/example.openai.yaml deleted file mode 100644 index 2e6ca53..0000000 --- a/src/ai_chat/config/example.openai.yaml +++ /dev/null @@ -1,3 +0,0 @@ -chat_ai: - url: "" - key: "" \ No newline at end of file diff --git a/src/qq_plugins/check.py b/src/qq_plugins/check.py index 698ecd3..7c9ce19 100644 --- a/src/qq_plugins/check.py +++ b/src/qq_plugins/check.py @@ -5,8 +5,10 @@ from nonebot import on_message from nonebot.adapters.qq import Message from nonebot.adapters import Bot, Event from src.ai_chat import ai_chat +import os +import yaml -menu = ['/今日运势','/天气','/图','/点歌','/摸摸头','/群老婆','/今日老婆', '/待办', '/test', '我喜欢你', "❤", "/待办查询", "/新建待办", "/删除待办"] +menu = ['/今日运势','/天气','/图','/点歌','/摸摸头','/群老婆','/今日老婆', '/待办', '/test', '我喜欢你', "❤", "/待办查询", "/新建待办", "/删除待办", "/openai"] async def check_value_in_menu(event: Event) -> bool: value = event.get_plaintext().strip().split(" ") if value[0] in menu: @@ -15,6 +17,8 @@ async def check_value_in_menu(event: Event) -> bool: return True rule = Rule(check_value_in_menu) +with open(os.getcwd() +'/src/ai_chat/config/chat_ai.yaml', 'r', encoding='utf-8') as f: + is_ai = yaml.load(f.read(), Loader=yaml.FullLoader).get('chat_ai').get('active') check = on_message(rule=to_me() & rule ,block=True) @check.handle() @@ -22,8 +26,10 @@ async def check(bot: Bot, event: Event): print(event.get_plaintext()) msg = ai_chat.gpt(event.get_plaintext()) print(msg) - await bot.send(message=msg,event=event) - # await bot.send(message=Message(random.choice(text_list)),event=event) + if is_ai == "True": + await bot.send(message=msg,event=event) + else: + await bot.send(message=Message(random.choice(text_list)),event=event) text_list = [ "是什么呢?猫猫没有识别到,喵~"+'\n'+"(๑>ڡ<)☆ 给个准信,别让我瞎猜",