From e01b1ed882a01d03b763e9b06b8b5d0608fc5f21 Mon Sep 17 00:00:00 2001 From: Kyomotoi <1172294279@qq.com> Date: Sat, 24 Apr 2021 16:20:19 +0800 Subject: =?UTF-8?q?=E2=9C=A8=F0=9F=94=A5=F0=9F=8E=A8=F0=9F=90=9B=E2=99=BB?= =?UTF-8?q?=EF=B8=8F=F0=9F=93=9D=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增:开发工具中ub paste,再也不怕长消息了。 新增:错误处理两项`ReadFileError`、`FormatError` 修复:bot退群显示被自己踢出群 删除:Service部分内容 删除:hitokoto本地库,改用请求 优化:b站小程序抓取 重构:bot管理部分,对命令进行简化 --- ATRI/plugins/rich/__init__.py | 93 +++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 48 deletions(-) (limited to 'ATRI/plugins/rich') diff --git a/ATRI/plugins/rich/__init__.py b/ATRI/plugins/rich/__init__.py index 9d5d6a9..cd4c5bd 100644 --- a/ATRI/plugins/rich/__init__.py +++ b/ATRI/plugins/rich/__init__.py @@ -1,7 +1,10 @@ import re import json +from random import choice from aiohttp.client import ClientSession + from nonebot.adapters.cqhttp import Bot, MessageEvent +from nonebot.adapters.cqhttp.message import MessageSegment from ATRI.service import Service as sv from ATRI.utils.request import get_bytes @@ -11,6 +14,10 @@ from .data_source import dec temp_list = [] +img_url = [ + "https://cdn.jsdelivr.net/gh/Kyomotoi/CDN@master/project/ATRI/fkrich.png", + "https://cdn.jsdelivr.net/gh/Kyomotoi/CDN@master/project/ATRI/xixi.jpg" +] bilibili_rich = sv.on_message() @@ -18,59 +25,49 @@ bilibili_rich = sv.on_message() @bilibili_rich.handle() async def _bilibili_rich(bot: Bot, event: MessageEvent) -> None: global temp_list - msg = str(event.raw_message).replace("\\", "") - bv = False - - if "qqdocurl" not in msg: - if "av" in msg: - try: + try: + msg = str(event.raw_message).replace("\\", "") + bv = False + + if "qqdocurl" not in msg: + if "av" in msg: av = re.findall(r"(av\d+)", msg)[0].replace('av', '') - except: - return - else: - try: + else: bv = re.findall(r"(BV\w+)", msg) av = str(dec(bv[0])) - except: - return - else: - patt = r"(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-&?=%.]+" - bv_url = re.findall(patt, msg) - bv_url = bv_url[3] - 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: - try: + else: + patt = r"(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-&?=%.]+" + bv_url = re.findall(patt, msg) + bv_url = bv_url[3] + 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', '') - except: + else: return - else: + + if count_list(temp_list, av) == 4: + await bot.send(event, "你是怕别人看不到么发这么多次?") + temp_list = del_list_aim(temp_list, av) return - - if count_list(temp_list, av) == 4: - await bot.send(event, "你是怕别人看不到么发这么多次?") - temp_list = del_list_aim(temp_list, av) - return - - temp_list.append(av) - - try: + + temp_list.append(av) + URL = f"https://api.kyomotoi.moe/api/bilibili/v2/?aid={av}" - except: + data = json.loads(await get_bytes(URL))['data'] + repo = ( + f"{data['bvid']} INFO:\n" + f"Title: {data['title']}\n" + f"Link: {data['short_link']}\n" + "にまねげぴのTencent rich!" + ) + await bot.send( + event, + MessageSegment.image(file=choice(img_url))) + await bilibili_rich.finish(repo) + except BaseException: 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) -- cgit v1.2.3