From 951dcdf4ec224b31433c5ab5c170b76fd3087910 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Thu, 8 Jul 2021 14:09:51 +0000 Subject: =?UTF-8?q?:rotating=5Flight:=20=E8=87=AA=E5=8A=A8=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/plugins/rich/__init__.py | 3 ++- ATRI/plugins/rich/data_source.py | 18 ++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'ATRI/plugins/rich') diff --git a/ATRI/plugins/rich/__init__.py b/ATRI/plugins/rich/__init__.py index 87a2b02..4c5b624 100644 --- a/ATRI/plugins/rich/__init__.py +++ b/ATRI/plugins/rich/__init__.py @@ -9,12 +9,13 @@ _rich_flmt = FreqLimiter(2) bili_rich = Rich().on_message("小程序爪巴", block=False) + @bili_rich.handle() async def _fk_bili(bot: Bot, event: MessageEvent): user_id = event.get_user_id() if not _rich_flmt.check(user_id): return - + msg = str(event.message) try: result, is_ok = await Rich().fk_bili(msg) diff --git a/ATRI/plugins/rich/data_source.py b/ATRI/plugins/rich/data_source.py index 3277a58..9e59bf5 100644 --- a/ATRI/plugins/rich/data_source.py +++ b/ATRI/plugins/rich/data_source.py @@ -24,10 +24,9 @@ __doc__ = """ class Rich(Service): - def __init__(self): Service.__init__(self, "小程序处理", __doc__, rule=is_in_service("小程序处理")) - + @staticmethod def _bv_dec(x) -> str: r = 0 @@ -35,7 +34,7 @@ class Rich(Service): r += tr[x[s[i]]] * 58 ** i result = "av" + str((r - add) ^ xor) return result - + @staticmethod def _bv_enc(x) -> str: x = (x ^ xor) + add @@ -43,7 +42,7 @@ class Rich(Service): for i in range(6): r[s[i]] = table[x // 58 ** i % 58] return "".join(r) - + @classmethod async def fk_bili(cls, text: str) -> tuple: """ @@ -52,7 +51,7 @@ class Rich(Service): """ msg = text.replace("\\", "") bv = False - + if "qqdocurl" not in msg: if "av" in msg: av = re.findall(r"(av\d+)", msg) @@ -70,7 +69,7 @@ class Rich(Service): if not bv_url: return "Get value (bv url) failed!", False bv_url = bv_url[3] - + try: res = await request.get(bv_url) except RequestError: @@ -79,7 +78,7 @@ class Rich(Service): if not bv: return "Get value (bv) failed!", False av = cls._bv_dec(bv[0]) - + if not bv: if "av" in msg: av = re.findall(r"(av\d+)", msg) @@ -88,7 +87,7 @@ class Rich(Service): av = av[0].replace("av", "") else: return "Not found av", False - + url = URL + av try: res = await request.get(url) @@ -96,11 +95,10 @@ class Rich(Service): return "Request failed!", False res_data = await res.json() data = res_data["data"] - + result = ( f"{data['bvid']} INFO:\n" f"Title: {data['title']}\n" f"Link: {data['short_link']}" ) return result, True - \ No newline at end of file -- cgit v1.2.3