import re
from loguru import logger
from nonebot import on_message
from nonebot_plugin_alconna import Reference, Reply, UniMsg

from nonebot.adapters import Event


matcher_fix = on_message()

pattern = (
    r"^(?:(?:av|cv)\d+|BV[a-zA-Z0-9]{10})|"
    r"(?:b23\.tv|bili(?:22|23|33|2233)\.cn|\.bilibili\.com|QQ小程序(?:&amp;#93;|&#93;|\])哔哩哔哩).{0,500}"
)


@matcher_fix.handle()
async def _(msg: UniMsg, event: Event):
    to_search = msg.exclude(Reply, Reference).dump(json=True)
    if not re.search(pattern, to_search):
        return
    logger.info("检测到有 Bilibili 相关的消息，直接进行一个调用")
    _module = __import__("nonebot_plugin_analysis_bilibili")
    await _module.handle_analysis(event)

