d0b6f9d199
bilibili模块有无法重载的错误,不知道是怎么回事
43 lines
No EOL
1.4 KiB
Python
43 lines
No EOL
1.4 KiB
Python
import re
|
|
|
|
from core.builtins import Bot
|
|
from core.component import module
|
|
from .bilibili import get_info
|
|
|
|
api_url = f'https://api.bilibili.com/x/web-interface/view/detail'
|
|
|
|
|
|
bili = module('bilibili', alias='bili', developers=['DoroWolf'],
|
|
desc='{bilibili.help.desc}', support_languages=['zh_cn'])
|
|
|
|
|
|
@bili.command('<video> [-i] {{bilibili.help}}',
|
|
options_desc={'-i': '{bilibili.help.option.i}'})
|
|
async def _(msg: Bot.MessageSession, video: str, get_detail=False):
|
|
if msg.parsed_msg.get('-i', False):
|
|
get_detail = True
|
|
if video[:2].upper() == "BV":
|
|
url = f"{api_url}?bvid={video}"
|
|
elif video[:2].lower() == "av":
|
|
url = f"{api_url}?aid={video[2:]}"
|
|
else:
|
|
await msg.finish(msg.locale.t('bilibili.message.error.invalid'))
|
|
await get_info(msg, url, get_detail)
|
|
|
|
|
|
@bili.handle(re.compile(r"\b([aA][vV])(\d+)\b"),
|
|
desc="{bilibili.help.regex.av}")
|
|
async def _(msg: Bot.MessageSession):
|
|
res = msg.matched_msg
|
|
if res:
|
|
url = f"{api_url}?aid={res.groups()[1]}"
|
|
await get_info(msg, url, get_detail=False)
|
|
|
|
|
|
@bili.handle(re.compile(r"\bBV[a-zA-Z0-9]{10}\b"),
|
|
desc="{bilibili.help.regex.bv}")
|
|
async def _(msg: Bot.MessageSession):
|
|
res = msg.matched_msg
|
|
if res:
|
|
url = f"{api_url}?bvid={res.group()}"
|
|
await get_info(msg, url, get_detail=False) |