NLPSession,
    on_command,
    on_natural_language,
)
from nonebot.permission import GROUP_ADMIN, SUPERUSER

from utils.decorators import SyncToAsync
from utils.manager import PluginManager
from utils.message import processSession

from .config import CONFIG
from .parse import BiliParser, IDCoverter, getVideoInfo

REPLY_FORMAT = CONFIG.customize.video
POWER_GROUP = SUPERUSER | GROUP_ADMIN
MATCH_AV = compileRegexp(CONFIG.customize.regexp.av)
MATCH_BV = compileRegexp(CONFIG.customize.regexp.bv)

__plugin_name__ = "bilibili"

PluginManager(__plugin_name__)


@on_command("bilibili_info", aliases=("视频信息", "b站视频"))
@processSession(pluginName=__plugin_name__)
@SyncToAsync
def vidInfo(session: CommandSession):
    aid = session.state["id"]
    responseData = getVideoInfo(aid)
    try:
        parsedData = BiliParser.parse(responseData)
from re import compile as compileRegexp

from nonebot import (
    CommandSession,
    IntentCommand,
    MessageSegment,
    NLPSession,
    logger,
    on_command,
    on_natural_language,
)

from utils.decorators import SyncToAsync
from utils.message import processSession

MATCH_RICH_TEXT = compileRegexp(r"\[CQ:rich,data=(\{.+\})\]")
REPLY_FORMAT = """
{preview}
{prompt} - {desc}

{link}
"""


def parse(data: str) -> dict:
    dataLoad = json.loads(data)
    link = ""
    perview = ""  # noqa: F841
    assert "desc" in dataLoad
    assert "prompt" in dataLoad
    assert "meta" in dataLoad
    BaseBotError,
    BotDisabledError,
    BotExistError,
    BotMessageError,
    BotNetworkError,
    BotNotFoundError,
    BotPermissionError,
    BotProgramError,
    BotRequestError,
    ExceptionProcess,
)
from .manager import PluginManager
from .objects import SyncWrapper

UnionSession = Union[CommandSession, NLPSession, NoticeSession, RequestSession]
CQ_CODE = compileRegexp(r"\[(CQ:\w+)(?:,\w+=[^,]+)*\]")


@message_preprocessor
async def _(bot: NoneBot, event: Event, plugin_manager):
    loginInfo = await bot.get_login_info()

    if loginInfo["user_id"] != event.self_id:
        raise CanceledException(None)

    return


def _shortCQCode(message: str) -> str:
    return CQ_CODE.sub(r"[\1...]", message).__repr__()
Exemple #4
0
from nonebot.permission import GROUP_ADMIN, PRIVATE_FRIEND, SUPERUSER

from utils.decorators import SyncToAsync
from utils.exception import BotExistError
from utils.manager import PluginManager, nameJoin
from utils.message import processSession

from .config import CONFIG, __plugin_name__
from .network import RefreshFeed, downloadFeed
from .parse import rssParser

PluginManager(__plugin_name__, defaultSettings={"subscribed": {}})
SUBSCRIBE_COMMAND = nameJoin(__plugin_name__, "subscribe")
TEST_COMMAND = nameJoin(__plugin_name__, "test")

URL_MATCH_REGEX = compileRegexp(
    r"(https?|ftp)://((?:\w|\d|[-+&@#/%?=~_|!:,.;])+(?:\w|\d|[-+&@#/%=~_|]))")
REFRESH_FEED = RefreshFeed()
POWER_GROUP = GROUP_ADMIN | PRIVATE_FRIEND | SUPERUSER


@on_command(SUBSCRIBE_COMMAND,
            aliases=("rss订阅", "RSS订阅"),
            permission=POWER_GROUP)
@processSession
@SyncToAsync
def rssSubscribe(session: CommandSession):
    rssLink: str = session.get("link")
    session.send(f'开始检查订阅源:"{rssLink}"')
    # Get feed data
    rssResource: str = downloadFeed(rssLink)
    rssResourceParse: dict = rssParser(rssResource)
Exemple #5
0
from re import compile as compileRegexp
from typing import Any, Dict, Optional
from urllib.parse import urljoin, urlparse

import requests
from lxml import etree
from nonetrip import MessageSegment
from utils.decorators import CatchRequestsException
from utils.network import NetworkUtils

from .config import Config

_ASCII2D_PARSE = urlparse(Config.apis.ascii2d)
_MATCH_NUMBER = compileRegexp(r"\d{4,20}")
_ASCII2D_ADDRESS = f"{_ASCII2D_PARSE.scheme}://{_ASCII2D_PARSE.netloc}/"


@CatchRequestsException(prompt="搜索图片失败", retries=Config.apis.retries)
def searchImage(imageURL: str) -> str:
    fullURL = str(Config.apis.ascii2d) + imageURL
    getResult = requests.get(fullURL, timeout=6, proxies=NetworkUtils.proxy)
    getResult.raise_for_status()
    return getResult.text


def _getNumbers(match: str) -> Optional[int]:
    searchResult = _MATCH_NUMBER.search(match)
    return None if not searchResult else int(searchResult.group())


def getCorrectInfo(originData: str) -> Dict[str, Any]: