2021-11-23 21:44:59 +08:00
|
|
|
from nonebot.matcher import Matcher
|
|
|
|
|
from nonebot.message import run_preprocessor, IgnoredException
|
|
|
|
|
from nonebot.typing import T_State
|
2022-02-19 18:20:19 +08:00
|
|
|
from ._utils import status_message_manager
|
2022-03-01 20:26:11 +08:00
|
|
|
from utils.image_utils import text2image
|
|
|
|
|
from typing import Dict, Any
|
2022-02-19 18:20:19 +08:00
|
|
|
from nonebot.adapters.onebot.v11 import (
|
2021-11-23 21:44:59 +08:00
|
|
|
Bot,
|
|
|
|
|
MessageEvent,
|
|
|
|
|
PrivateMessageEvent,
|
|
|
|
|
GroupMessageEvent,
|
|
|
|
|
)
|
2022-03-01 20:26:11 +08:00
|
|
|
import re
|
2021-11-23 21:44:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# 为什么AI会自己和自己聊天
|
|
|
|
|
@run_preprocessor
|
|
|
|
|
async def _(matcher: Matcher, bot: Bot, event: PrivateMessageEvent, state: T_State):
|
|
|
|
|
if not isinstance(event, MessageEvent):
|
|
|
|
|
return
|
|
|
|
|
if event.user_id == int(bot.self_id):
|
|
|
|
|
raise IgnoredException("为什么AI会自己和自己聊天")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 有命令就别说话了
|
|
|
|
|
@run_preprocessor
|
|
|
|
|
async def _(matcher: Matcher, bot: Bot, event: MessageEvent, state: T_State):
|
|
|
|
|
if not isinstance(event, MessageEvent):
|
|
|
|
|
return
|
2022-02-19 18:20:19 +08:00
|
|
|
if matcher.type == "message" and matcher.plugin_name == "ai":
|
2021-11-23 21:44:59 +08:00
|
|
|
if (
|
|
|
|
|
isinstance(event, GroupMessageEvent)
|
|
|
|
|
and not status_message_manager.check(event.group_id)
|
|
|
|
|
):
|
|
|
|
|
status_message_manager.delete(event.group_id)
|
|
|
|
|
raise IgnoredException("有命令就别说话了")
|
|
|
|
|
elif (
|
|
|
|
|
isinstance(event, PrivateMessageEvent)
|
|
|
|
|
and not status_message_manager.check(event.user_id)
|
|
|
|
|
):
|
|
|
|
|
status_message_manager.delete(event.user_id)
|
|
|
|
|
raise IgnoredException("有命令就别说话了")
|
|
|
|
|
|
2022-03-01 20:26:11 +08:00
|
|
|
# @Bot.on_calling_api
|
|
|
|
|
# async def handle_api_call(bot: Bot, api: str, data: Dict[str, Any]):
|
|
|
|
|
# if api in ["send_msg", "send_group_msg", "send_private_msg"]:
|
|
|
|
|
# msg = str(data["message"])
|
|
|
|
|
# if (r := re.search("\[\[To_Img\|?(.*?)]]", msg)) or (r := re.search("[[To_Img\|?(.*?)[[")):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|