From 9d052eeb7d9d7b6ae50a4fb6e07a38cd492fd9c1 Mon Sep 17 00:00:00 2001 From: Kyomotoi <1172294279@qq.com> Date: Sun, 7 Feb 2021 22:17:31 +0800 Subject: =?UTF-8?q?=E2=9C=A8=20=E6=96=B0=E5=A2=9E=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=EF=BC=9A=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/plugins/rich/__init__.py | 61 ++++++++++++++++++++++++++++++++++++++++ ATRI/plugins/rich/data_source.py | 22 +++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 ATRI/plugins/rich/__init__.py create mode 100644 ATRI/plugins/rich/data_source.py (limited to 'ATRI/plugins/rich') 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) -- cgit v1.2.3