diff options
author | Kyomotoi <[email protected]> | 2021-02-07 22:17:31 +0800 |
---|---|---|
committer | Kyomotoi <[email protected]> | 2021-02-07 22:17:31 +0800 |
commit | 9d052eeb7d9d7b6ae50a4fb6e07a38cd492fd9c1 (patch) | |
tree | 3004e25ea16340211e4c215c6fa8c53697108079 | |
parent | f5ceb8927f2e7f2a9e29d62c8e4cef876f917249 (diff) | |
download | ATRI-9d052eeb7d9d7b6ae50a4fb6e07a38cd492fd9c1.tar.gz ATRI-9d052eeb7d9d7b6ae50a4fb6e07a38cd492fd9c1.tar.bz2 ATRI-9d052eeb7d9d7b6ae50a4fb6e07a38cd492fd9c1.zip |
✨ 新增插件:小程序检测
-rw-r--r-- | ATRI/plugins/rich/__init__.py | 61 | ||||
-rw-r--r-- | ATRI/plugins/rich/data_source.py | 22 |
2 files changed, 83 insertions, 0 deletions
diff --git a/ATRI/plugins/rich/__init__.py b/ATRI/plugins/rich/__init__.py new file mode 100644 index 0000000..6bea2ff --- /dev/null +++ b/ATRI/plugins/rich/__init__.py @@ -0,0 +1,61 @@ +import re +import json +from aiohttp.client import ClientSession + +from nonebot.adapters.cqhttp import Bot, MessageEvent +from nonebot.plugin import on_message + +from ATRI.rule import is_in_banlist, is_in_dormant +from ATRI.utils.request import get_bytes +from .data_source import dec + +bilibili_rich = on_message( + rule=is_in_banlist() & is_in_dormant() +) + +@bilibili_rich.handle() +async def _bilibili_rich(bot: Bot, event: MessageEvent) -> None: + msg = str(event.raw_message) + bv = False + + if "qqdocurl" not in msg: + if "av" in msg: + av = re.findall(r"(av\d+)", msg)[0].replace('av', '') + else: + try: + bv = re.findall(r"(BV\w+)", msg) + av = str(dec(bv[0])) + except: + return + else: + bv_url = re.findall(r"(..........b23...\S+\=)", msg) + bv_url = bv_url[0].replace("\\", "") + print(bv_url) + async with ClientSession() as session: + async with session.get( + url=bv_url) as r: + bv = re.findall(r"(BV\w+)", str(r.url)) + av = dec(bv[0]) + + if not bv: + if "av" in msg: + av = re.findall(r"(av\d+)", msg)[0].replace('av', '') + else: + return + + try: + URL = f"https://api.kyomotoi.moe/api/bilibili/v2/?aid={av}" + except: + return + data = json.loads(await get_bytes(URL))['data'] + repo = ( + f"{av} INFO:\n" + f"Title: {data['title']}\n" + f"Bid: {data['bvid']}\n" + f"View: {data['stat']['view']} Like: {data['stat']['like']}\n" + f"Coin: {data['stat']['coin']} Share: {data['stat']['share']}\n" + f"Link: {data['short_link']}\n" + "にまねげぴのTencent rich!" + ) + await bilibili_rich.finish(repo) +
\ No newline at end of file diff --git a/ATRI/plugins/rich/data_source.py b/ATRI/plugins/rich/data_source.py new file mode 100644 index 0000000..32ac219 --- /dev/null +++ b/ATRI/plugins/rich/data_source.py @@ -0,0 +1,22 @@ +table = 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF' +tr = {} +for i in range(58): + tr[table[i]] = i +s = [11, 10, 3, 8, 4, 6] +xor = 177451812 +add = 8728348608 + + +def dec(x) -> int: + r = 0 + for i in range(6): + r += tr[x[s[i]]] * 58**i + return (r - add) ^ xor + + +def enc(x) -> str: + x = (x ^ xor) + add + r = list('BV1 4 1 7 ') + for i in range(6): + r[s[i]] = table[x // 58**i % 58] + return ''.join(r) |