diff options
Diffstat (limited to 'ATRI/plugins/plugin_rich')
-rw-r--r-- | ATRI/plugins/plugin_rich/__init__.py | 129 | ||||
-rw-r--r-- | ATRI/plugins/plugin_rich/body.py | 23 |
2 files changed, 152 insertions, 0 deletions
diff --git a/ATRI/plugins/plugin_rich/__init__.py b/ATRI/plugins/plugin_rich/__init__.py new file mode 100644 index 0000000..2639188 --- /dev/null +++ b/ATRI/plugins/plugin_rich/__init__.py @@ -0,0 +1,129 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import re +import json +import requests +from datetime import datetime + +from nonebot.log import logger +from nonebot.plugin import on_message +from nonebot.adapters.cqhttp import Bot, Event + +from utils.utils_banList import banList +from utils.utils_request import request_get + +from .body import dec, enc + + +BILI_REPORT_FORMAT = """[{aid}] Info: +Title: {title} +bid: {bid} +Viev: {view} Like: {like} +Coin: {coin} Share: {share} +Link: +{aid_link} +{bid_link}""" + +bilibiliRich = on_message() + [email protected]() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: + user = str(event.user_id) + group = str(event.group_id) + + if banList(user, group): + msg = str(event.message) + + if "qqdocurl" not in msg: + try: + bv = re.findall(r"(BV\w+)", msg) + except: + return + else: + bvURL = re.findall(r"(........b23...\S+\=)", msg) + + try: + r = requests.get(bvURL[0], stream=True, allow_redirects = True) + except: + logger.waring("Get BV ERROR. (Request ERROR)") + return + + bv = re.findall(r"(BV\w+)", r.url) + + if bv: + aid = str(dec(bv[0])) + ad = 'av' + aid + URL = f'https://api.imjad.cn/bilibili/v2/?aid={aid}' + + try: + res = request_get(URL) + except: + logger.waring("Request ERROR") + return + + data = json.loads(res) + msg = BILI_REPORT_FORMAT.format( + title = data["data"]["title"], + + view = data["data"]["stat"]["view"], + coin = data["data"]["stat"]["coin"], + share = data["data"]["stat"]["share"], + like = data["data"]["stat"]["like"], + + bid = data["data"]["bvid"], + bid_link = data["data"]["short_link"], + + aid = ad, + aid_link = f'https://b23.tv/{ad}' + ) + + await bilibiliRich.finish(msg) + + else: + return + + +CLOUDMUSIC_REPORT_FORMAT = """Status: {status} +Song id: {id} +Br: {br} +Download: {url} +MD5: {md5}""" + +cloudmusicRich = on_message() + [email protected]() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: + user = str(event.user_id) + group = str(event.group_id) + + if banList(user, group): + msg = str(event.message) + + if "music.163.com" in msg: + music_id = re.findall(r"song\S+\/|id=\S+\&", msg) + + if music_id: + music_id = str(music_id[0]) + music_id = re.findall(r"-?[1-9]\d*", music_id) + URL = f'https://api.imjad.cn/cloudmusic/?type=song&id={music_id[0]}&br=320000' + + try: + res = request_get(URL) + except: + logger.waring("Request ERROR") + return + + data = json.loads(res) + msg = CLOUDMUSIC_REPORT_FORMAT.format( + status = data["code"], + id = data["data"][0]["id"], + br = data["data"][0]["br"], + url = data["data"][0]["url"], + md5 = data["data"][0]["md5"], + ) + + await cloudmusicRich.finish(msg) + + else: + return diff --git a/ATRI/plugins/plugin_rich/body.py b/ATRI/plugins/plugin_rich/body.py new file mode 100644 index 0000000..2c743c0 --- /dev/null +++ b/ATRI/plugins/plugin_rich/body.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +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)
\ No newline at end of file |