diff --git a/defs/bilibili.py b/defs/bilibili.py index 4ef2ba8..5332911 100644 --- a/defs/bilibili.py +++ b/defs/bilibili.py @@ -8,7 +8,7 @@ import string from bilibili_api import Credential, ResponseCodeException from bilibili_api.audio import Audio from bilibili_api.video import Video -from bilibili_api.user import User +from bilibili_api.utils.network import Api from pyrogram import ContinuePropagation from qrcode.image.pil import PilImage from io import BytesIO @@ -168,6 +168,13 @@ def numf(num: int): return view +async def get_user_info(mid: int): + api = "https://api.bilibili.com/x/web-interface/card" + params = {"mid": mid} + result = await Api(api, "GET", credential=credential).update_params(**params).result + return result + + async def binfo_up_info(video_info: dict): # UP主 # 等级 0-4 \uE6CB-F 5-6\uE6D0-1 @@ -176,35 +183,41 @@ async def binfo_up_info(video_info: dict): up_list = [] for up in video_info["staff"]: up_mid = up["mid"] - u = User(up_mid, credential=credential) - up_data = await u.get_user_info() + up_data = await get_user_info(up_mid) + nickname_color, level = ( + up_data["card"]["vip"]["nickname_color"], + up_data["card"]["level_info"]["current_level"], + ) up_list.append( { "name": up["name"], "up_title": up["title"], "face": up["face"], - "color": up_data["vip"]["nickname_color"] - if up_data["vip"]["nickname_color"] != "" - else "black", + "color": nickname_color if nickname_color != "" else "black", "follower": up["follower"], - "level": up_data["level"], + "level": level, } ) else: up_mid = video_info["owner"]["mid"] - u = User(up_mid, credential=credential) - up_data = await u.get_user_info() - up_stat = await u.get_relation_info() + up_data = await get_user_info(up_mid) + nickname_color, level = ( + up_data["card"]["vip"]["nickname_color"], + up_data["card"]["level_info"]["current_level"], + ) + name, face, follower = ( + up_data["card"]["name"], + up_data["card"]["face"], + up_data["follower"], + ) up_list = [ { - "name": up_data["name"], + "name": name, "up_title": "UP主", - "face": up_data["face"], - "color": up_data["vip"]["nickname_color"] - if up_data["vip"]["nickname_color"] != "" - else "black", - "follower": up_stat["follower"], - "level": up_data["level"], + "face": face, + "color": nickname_color if nickname_color != "" else "black", + "follower": follower, + "level": level, } ] return up_list diff --git a/defs/bilibili_download.py b/defs/bilibili_download.py index 594e48d..a1118ad 100644 --- a/defs/bilibili_download.py +++ b/defs/bilibili_download.py @@ -383,9 +383,7 @@ def gen_video_caption(v: Video, info: Dict) -> str: f"{info['title']}\n\n{info['desc']}\n\nhttps://b23.tv/{v.get_bvid()}" ) if len(caption) > 800: - caption = ( - f"{info['title']}\n\n简介过长,无法显示\n\nhttps://b23.tv/{v.get_bvid()}" - ) + caption = f"{info['title']}\n\n简介过长,无法显示\n\nhttps://b23.tv/{v.get_bvid()}" return caption diff --git a/defs/inline_result_filters.py b/defs/inline_result_filters.py index d09a78f..45c57fd 100644 --- a/defs/inline_result_filters.py +++ b/defs/inline_result_filters.py @@ -3,7 +3,14 @@ from re import Pattern from typing import Union from pyrogram.filters import create -from pyrogram.types import Message, CallbackQuery, InlineQuery, PreCheckoutQuery, ChosenInlineResult, Update +from pyrogram.types import ( + Message, + CallbackQuery, + InlineQuery, + PreCheckoutQuery, + ChosenInlineResult, + Update, +) def regex(pattern: Union[str, Pattern], flags: int = 0): @@ -27,5 +34,5 @@ def regex(pattern: Union[str, Pattern], flags: int = 0): return create( func, "RegexFilter", - p=pattern if isinstance(pattern, Pattern) else re.compile(pattern, flags) + p=pattern if isinstance(pattern, Pattern) else re.compile(pattern, flags), ) diff --git a/defs/lofter.py b/defs/lofter.py index 526acf4..8eb6d77 100644 --- a/defs/lofter.py +++ b/defs/lofter.py @@ -42,9 +42,7 @@ class LofterItem: async def check_exists(self): if await LofterPostModel.get_by_post_id(self.post_id): - self.text += ( - f'\n📄 此图集已被此频道收录' - ) + self.text += f'\n📄 此图集已被此频道收录' async def init(self): await self.check_exists() diff --git a/models/apis/twitter/client.py b/models/apis/twitter/client.py index 21695f1..f259fac 100644 --- a/models/apis/twitter/client.py +++ b/models/apis/twitter/client.py @@ -90,9 +90,9 @@ class TwitterClient: return await self.client.request(method, url, headers=headers, **kwargs) async def reset_session(self): - self.headers[ - "authorization" - ] = f"Basic {base64.b64encode(self.tokens[0].encode()).decode()}" + self.headers["authorization"] = ( + f"Basic {base64.b64encode(self.tokens[0].encode()).decode()}" + ) response = await self.request( "https://api.twitter.com/oauth2/token", method="POST", diff --git a/models/services/fragment.py b/models/services/fragment.py index 84aa78e..eae54e3 100644 --- a/models/services/fragment.py +++ b/models/services/fragment.py @@ -78,7 +78,10 @@ class UserName(BaseModel): if self.status == AuctionStatus.Available: text += f"最低出价:{self.now_price.text}\n" elif self.status == AuctionStatus.OnAuction: - text += f"目前最高出价:{self.now_price.text}\n" f"距离拍卖结束:{self.end_human_time}\n" + text += ( + f"目前最高出价:{self.now_price.text}\n" + f"距离拍卖结束:{self.end_human_time}\n" + ) elif self.status == AuctionStatus.Sold: text += ( f"售出价格:{self.now_price.text}\n" @@ -86,7 +89,10 @@ class UserName(BaseModel): f"售出时间:{self.strf_end_time}\n" ) elif self.status == AuctionStatus.Sale: - text += f"售价:{self.now_price.text}\n" f"距离出售结束:{self.end_human_time}\n" + text += ( + f"售价:{self.now_price.text}\n" + f"距离出售结束:{self.end_human_time}\n" + ) return text diff --git a/modules/bilibili_download.py b/modules/bilibili_download.py index fbda9fd..6712a55 100644 --- a/modules/bilibili_download.py +++ b/modules/bilibili_download.py @@ -33,9 +33,11 @@ async def bili_download_resolve(_: Client, message: Message): if video_db := await BiliFavAction.get_by_bv_id(video.get_bvid()): await message.reply_video( video_db.file_id, - caption=f"详细信息:https://t.me/{bilifav_channel_username}/{video_db.message_id}" - if video_db.message_id - else None, + caption=( + f"详细信息:https://t.me/{bilifav_channel_username}/{video_db.message_id}" + if video_db.message_id + else None + ), quote=True, ) raise ContinuePropagation @@ -55,9 +57,11 @@ async def bili_audio_download_resolve(_: Client, message: Message): if audio_db := await BiliFavAction.get_by_id(audio.get_auid()): await message.reply_audio( audio_db.file_id, - caption=f"详细信息:https://t.me/{bilifav_channel_username}/{audio_db.message_id}" - if audio_db.message_id - else None, + caption=( + f"详细信息:https://t.me/{bilifav_channel_username}/{audio_db.message_id}" + if audio_db.message_id + else None + ), quote=True, ) raise ContinuePropagation diff --git a/modules/dc.py b/modules/dc.py index c7cdfb3..8350047 100644 --- a/modules/dc.py +++ b/modules/dc.py @@ -66,7 +66,9 @@ async def dc_query(_: Client, inline_query: InlineQuery): results = [ InlineQueryResultArticle( title="查询 dc", - input_message_content=InputTextMessageContent(message_text="加载中,请等待。。。"), + input_message_content=InputTextMessageContent( + message_text="加载中,请等待。。。" + ), reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton(text="重试", callback_data="dc")]] ), @@ -82,7 +84,10 @@ async def dc_query(_: Client, inline_query: InlineQuery): def get_dc_text(dc: int): - return f"此会话所在数据中心为: DC{dc}\n" f"该数据中心位于 {geo_dic[str(dc)]}" + return ( + f"此会话所在数据中心为: DC{dc}\n" + f"该数据中心位于 {geo_dic[str(dc)]}" + ) @bot.on_chosen_inline_result(inline_result_filters.regex(r"^dc$")) diff --git a/modules/exchange.py b/modules/exchange.py index 6054682..1695f50 100644 --- a/modules/exchange.py +++ b/modules/exchange.py @@ -1,6 +1,11 @@ from pyrogram import Client, filters from pyrogram.enums import ChatType -from pyrogram.types import Message, InlineQuery, InlineQueryResultArticle, InputTextMessageContent +from pyrogram.types import ( + Message, + InlineQuery, + InlineQueryResultArticle, + InputTextMessageContent, +) from defs.exchange import exchange_client from scheduler import scheduler diff --git a/modules/geo.py b/modules/geo.py index cd40982..e4b3ee7 100644 --- a/modules/geo.py +++ b/modules/geo.py @@ -48,4 +48,6 @@ async def geo_command(_: Client, message: Message): msg = await message.reply_location( longitude=float(lat), latitude=float(lon), quote=True ) - await msg.reply(f"坐标:`{lat},{lon}`\n地址:{formatted_address}", quote=True) + await msg.reply( + f"坐标:`{lat},{lon}`\n地址:{formatted_address}", quote=True + ) diff --git a/modules/start.py b/modules/start.py index 836f625..b9783ff 100644 --- a/modules/start.py +++ b/modules/start.py @@ -66,7 +66,9 @@ async def empty_inline(_, inline_query: InlineQuery): ), InlineQueryResultArticle( title="exchange", - input_message_content=InputTextMessageContent("使用 exchange 来查询汇率数据"), + input_message_content=InputTextMessageContent( + "使用 exchange 来查询汇率数据" + ), description="使用 exchange 来查询汇率数据", ), ] diff --git a/modules/sticker_download.py b/modules/sticker_download.py index b4505ab..50a2245 100644 --- a/modules/sticker_download.py +++ b/modules/sticker_download.py @@ -54,7 +54,9 @@ async def process_single_sticker(client: "Client", message: "Message"): if temp := await cache.get(f"sticker:export:{message.from_user.id}"): try: await export_add(temp, message.sticker, client) - await message.reply_text("成功加入导出列表,结束选择请输入 /sticker_export_end", quote=True) + await message.reply_text( + "成功加入导出列表,结束选择请输入 /sticker_export_end", quote=True + ) except ValueError as exc: await message.reply(str(exc), quote=True) else: @@ -87,7 +89,9 @@ async def process_custom_emoji(client: "Client", message: "Message"): except AttributeError: await message.reply("无法获取贴纸", quote=True) raise ContinuePropagation - reply = await message.reply(f"正在下载 {len(stickers)} 个 emoji ...请耐心等待", quote=True) + reply = await message.reply( + f"正在下载 {len(stickers)} 个 emoji ...请耐心等待", quote=True + ) exc = None for sticker in stickers: target_file = None @@ -118,15 +122,21 @@ async def batch_start(_: "Client", message: "Message"): if "start" in message.command[0].lower(): if await cache.get(f"sticker:export:{uid}"): await message.reply( - "已经开始批量导出贴纸,请直接发送贴纸,完成选择请输入 /sticker_export_end", quote=True + "已经开始批量导出贴纸,请直接发送贴纸,完成选择请输入 /sticker_export_end", + quote=True, ) return await cache.set(f"sticker:export:{uid}", tempfile.mkdtemp()) - await message.reply("开始批量导出贴纸,请直接发送贴纸,完成选择请输入 /sticker_export_end", quote=True) + await message.reply( + "开始批量导出贴纸,请直接发送贴纸,完成选择请输入 /sticker_export_end", + quote=True, + ) else: target_dir = await cache.get(f"sticker:export:{uid}") if not target_dir: - await message.reply("未开始批量导出贴纸,请先使用命令 /sticker_export_start", quote=True) + await message.reply( + "未开始批量导出贴纸,请先使用命令 /sticker_export_start", quote=True + ) return file = None try: