2025-01-14 17:48:32 +00:00
|
|
|
from nonebot.plugin import on_command, on_keyword
|
2025-01-14 16:28:26 +00:00
|
|
|
import random
|
2025-01-14 07:09:00 +00:00
|
|
|
from nonebot.rule import Rule, to_me
|
|
|
|
|
from nonebot import on_message
|
2025-01-17 17:51:23 +00:00
|
|
|
from nonebot.adapters.qq import Message, MessageEvent
|
2025-01-14 07:09:00 +00:00
|
|
|
from nonebot.adapters import Bot, Event
|
2025-01-16 14:40:22 +00:00
|
|
|
from src.ai_chat import ai_chat
|
2025-01-17 03:28:22 +00:00
|
|
|
import os
|
|
|
|
|
import yaml
|
2025-01-17 17:51:23 +00:00
|
|
|
from src.my_sqlite.admin_manage_by_sqlite import insert_administrator, check_admin_access
|
2025-01-14 07:09:00 +00:00
|
|
|
|
2025-01-17 17:51:23 +00:00
|
|
|
"""
|
|
|
|
|
设置管理员鉴权密码
|
|
|
|
|
"""
|
|
|
|
|
admin_passwd = "1234"
|
|
|
|
|
|
|
|
|
|
menu = ['/今日运势','/天气','/图','/点歌','/摸摸头','/群老婆','/今日老婆', '/待办', '/test', '我喜欢你', "❤", "/待办查询", "/新建待办", "/删除待办", "/activate_ai", "/cf", "/管理员确认"]
|
2025-01-14 07:09:00 +00:00
|
|
|
async def check_value_in_menu(event: Event) -> bool:
|
|
|
|
|
value = event.get_plaintext().strip().split(" ")
|
|
|
|
|
if value[0] in menu:
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
rule = Rule(check_value_in_menu)
|
2025-01-17 17:51:23 +00:00
|
|
|
|
2025-01-14 07:09:00 +00:00
|
|
|
|
|
|
|
|
check = on_message(rule=to_me() & rule ,block=True)
|
|
|
|
|
@check.handle()
|
|
|
|
|
async def check(bot: Bot, event: Event):
|
2025-01-17 17:51:23 +00:00
|
|
|
if is_ai() == "True":
|
2025-01-17 12:33:52 +00:00
|
|
|
msg = ai_chat.deepseek_chat(event.get_plaintext())
|
2025-01-17 03:28:22 +00:00
|
|
|
await bot.send(message=msg,event=event)
|
|
|
|
|
else:
|
|
|
|
|
await bot.send(message=Message(random.choice(text_list)),event=event)
|
2025-01-14 16:28:26 +00:00
|
|
|
|
|
|
|
|
text_list = [
|
|
|
|
|
"是什么呢?猫猫没有识别到,喵~"+'\n'+"(๑>ڡ<)☆ 给个准信,别让我瞎猜",
|
|
|
|
|
"是想让我干嘛呢?猫猫一头雾水,喵~" + '\n' + "(๑•̀ㅂ•́)و✧ 直接跟我说,别这么含蓄,喵~",
|
|
|
|
|
"是啥意思呀?猫猫完全没搞懂,喵~" + '\n' + "(๑・.・๑) 别折腾我啦,说明白,喵~",
|
|
|
|
|
"是特殊信号?猫猫听不懂,喵~" + '\n' + "(๑・̀︶・́)و 下个明确指令,喵~",
|
|
|
|
|
"难道是新指令?猫猫一脸茫然,喵~" + '\n' + "(๑>ڡ<)☆ 说详细点,别这么隐晦,喵~",
|
2025-01-14 17:48:32 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
love = on_keyword({"我喜欢你", "❤"}, rule=to_me(), priority=10, block=True)
|
|
|
|
|
@love.handle()
|
|
|
|
|
async def spread_love():
|
|
|
|
|
await love.finish("我也喜欢你。")
|
|
|
|
|
|
|
|
|
|
test = on_command("test", rule=to_me(), priority=10, block=True)
|
|
|
|
|
@test.handle()
|
|
|
|
|
async def bot_on_ready():
|
|
|
|
|
await test.finish("\nBoost & Magnum, ready fight!!!")
|
|
|
|
|
|
2025-01-17 17:51:23 +00:00
|
|
|
verification = on_command("管理员确认", rule=to_me(), priority=10, block=True)
|
|
|
|
|
@verification.handle()
|
|
|
|
|
async def verify_as_administrator(message: MessageEvent):
|
|
|
|
|
passwd = message.get_plaintext().replace("/管理员确认", "").strip(" ")
|
|
|
|
|
if passwd == admin_passwd:
|
|
|
|
|
insert_administrator(message.get_user_id())
|
|
|
|
|
await verification.finish("成功注册为管理员。")
|
|
|
|
|
else:
|
|
|
|
|
await verification.finish("管理员鉴权失败。")
|
|
|
|
|
|
|
|
|
|
ai_is_available = on_command("activate_ai", rule=to_me(), priority=10, block=True)
|
|
|
|
|
@ai_is_available.handle()
|
|
|
|
|
async def change_ai_availability(message: MessageEvent):
|
|
|
|
|
member_openid = message.get_user_id()
|
|
|
|
|
result = check_admin_access(member_openid)
|
|
|
|
|
if result is None:
|
|
|
|
|
await ai_is_available.finish(message=Message(random.choice(text_list)))
|
|
|
|
|
elif str(result).lstrip("('").rstrip("',)") == member_openid:
|
|
|
|
|
if is_ai() == "True":
|
|
|
|
|
change_chatai_yaml_availability_to("False")
|
|
|
|
|
await ai_is_available.finish("成功关闭语言模型对话功能。")
|
|
|
|
|
else:
|
|
|
|
|
change_chatai_yaml_availability_to("True")
|
|
|
|
|
await ai_is_available.finish("成功开启语言模型对话功能。一起来聊天吧~")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def change_chatai_yaml_availability_to(is_available):
|
|
|
|
|
with open(os.getcwd() + '/src/ai_chat/config/chat_ai.yaml', 'r', encoding='utf-8') as f1:
|
|
|
|
|
dic_temp = yaml.load(f1, Loader=yaml.FullLoader)
|
|
|
|
|
dic_temp['chat_ai']['active'] = is_available
|
|
|
|
|
with open(os.getcwd() + '/src/ai_chat/config/chat_ai.yaml', 'w', encoding='utf-8') as f1:
|
|
|
|
|
yaml.dump(dic_temp, f1)
|
|
|
|
|
print(dic_temp)
|
|
|
|
|
f1.close()
|
2025-01-14 17:48:32 +00:00
|
|
|
|
2025-01-17 17:51:23 +00:00
|
|
|
def is_ai():
|
|
|
|
|
with open(os.getcwd() + '/src/ai_chat/config/chat_ai.yaml', 'r', encoding='utf-8') as f:
|
|
|
|
|
state = yaml.load(f.read(), Loader=yaml.FullLoader).get('chat_ai').get('active')
|
|
|
|
|
return state
|