mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-Nonebot.git
synced 2026-04-01 22:04:51 +00:00
更新ai功能
可选择开启或关闭
This commit is contained in:
parent
c761ba2e9c
commit
3933a03cac
3 changed files with 13 additions and 6 deletions
4
src/ai_chat/config/example.chat_ai.yaml
Normal file
4
src/ai_chat/config/example.chat_ai.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
chat_ai:
|
||||||
|
url: "<KEY>"
|
||||||
|
key: "<KEY>"
|
||||||
|
active: "False" # True为启动ai功能,False为关闭功能
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
chat_ai:
|
|
||||||
url: "<KEY>"
|
|
||||||
key: "<KEY>"
|
|
||||||
|
|
@ -5,8 +5,10 @@ from nonebot import on_message
|
||||||
from nonebot.adapters.qq import Message
|
from nonebot.adapters.qq import Message
|
||||||
from nonebot.adapters import Bot, Event
|
from nonebot.adapters import Bot, Event
|
||||||
from src.ai_chat import ai_chat
|
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:
|
async def check_value_in_menu(event: Event) -> bool:
|
||||||
value = event.get_plaintext().strip().split(" ")
|
value = event.get_plaintext().strip().split(" ")
|
||||||
if value[0] in menu:
|
if value[0] in menu:
|
||||||
|
|
@ -15,6 +17,8 @@ async def check_value_in_menu(event: Event) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
rule = Rule(check_value_in_menu)
|
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 = on_message(rule=to_me() & rule ,block=True)
|
||||||
@check.handle()
|
@check.handle()
|
||||||
|
|
@ -22,8 +26,10 @@ async def check(bot: Bot, event: Event):
|
||||||
print(event.get_plaintext())
|
print(event.get_plaintext())
|
||||||
msg = ai_chat.gpt(event.get_plaintext())
|
msg = ai_chat.gpt(event.get_plaintext())
|
||||||
print(msg)
|
print(msg)
|
||||||
await bot.send(message=msg,event=event)
|
if is_ai == "True":
|
||||||
# await bot.send(message=Message(random.choice(text_list)),event=event)
|
await bot.send(message=msg,event=event)
|
||||||
|
else:
|
||||||
|
await bot.send(message=Message(random.choice(text_list)),event=event)
|
||||||
|
|
||||||
text_list = [
|
text_list = [
|
||||||
"是什么呢?猫猫没有识别到,喵~"+'\n'+"(๑>ڡ<)☆ 给个准信,别让我瞎猜",
|
"是什么呢?猫猫没有识别到,喵~"+'\n'+"(๑>ڡ<)☆ 给个准信,别让我瞎猜",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue