import re

from nonebot_plugin_alconna import Text, UniMsg


def match_keyword(*patterns: str | re.Pattern):
    async def _matcher(msg: UniMsg):
        text = msg.get(Text).extract_plain_text().strip()
        for pattern in patterns:
            if isinstance(pattern, str) and text == pattern:
                return True
            if isinstance(pattern, re.Pattern) and re.match(pattern, text):
                return True
        return False

    return _matcher
