mirror of
https://github.com/Xtao-Labs/iShotaBot.git
synced 2024-11-30 19:30:41 +00:00
fix: bilibili up user info
This commit is contained in:
parent
b186e7ad2f
commit
0dcbde64da
@ -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
|
||||
|
@ -383,9 +383,7 @@ def gen_video_caption(v: Video, info: Dict) -> str:
|
||||
f"<b>{info['title']}</b>\n\n{info['desc']}\n\nhttps://b23.tv/{v.get_bvid()}"
|
||||
)
|
||||
if len(caption) > 800:
|
||||
caption = (
|
||||
f"<b>{info['title']}</b>\n\n简介过长,无法显示\n\nhttps://b23.tv/{v.get_bvid()}"
|
||||
)
|
||||
caption = f"<b>{info['title']}</b>\n\n简介过长,无法显示\n\nhttps://b23.tv/{v.get_bvid()}"
|
||||
return caption
|
||||
|
||||
|
||||
|
@ -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),
|
||||
)
|
||||
|
@ -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📄 此图集已被<a href="https://t.me/{lofter_channel_username}">此频道</a>收录'
|
||||
)
|
||||
self.text += f'\n📄 此图集已被<a href="https://t.me/{lofter_channel_username}">此频道</a>收录'
|
||||
|
||||
async def init(self):
|
||||
await self.check_exists()
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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"此会话所在数据中心为: <b>DC{dc}</b>\n" f"该数据中心位于 <b>{geo_dic[str(dc)]}</b>"
|
||||
return (
|
||||
f"此会话所在数据中心为: <b>DC{dc}</b>\n"
|
||||
f"该数据中心位于 <b>{geo_dic[str(dc)]}</b>"
|
||||
)
|
||||
|
||||
|
||||
@bot.on_chosen_inline_result(inline_result_filters.regex(r"^dc$"))
|
||||
|
@ -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
|
||||
|
@ -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地址:<b>{formatted_address}</b>", quote=True)
|
||||
await msg.reply(
|
||||
f"坐标:`{lat},{lon}`\n地址:<b>{formatted_address}</b>", quote=True
|
||||
)
|
||||
|
@ -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 来查询汇率数据",
|
||||
),
|
||||
]
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user