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 import Credential, ResponseCodeException
|
||||||
from bilibili_api.audio import Audio
|
from bilibili_api.audio import Audio
|
||||||
from bilibili_api.video import Video
|
from bilibili_api.video import Video
|
||||||
from bilibili_api.user import User
|
from bilibili_api.utils.network import Api
|
||||||
from pyrogram import ContinuePropagation
|
from pyrogram import ContinuePropagation
|
||||||
from qrcode.image.pil import PilImage
|
from qrcode.image.pil import PilImage
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
@ -168,6 +168,13 @@ def numf(num: int):
|
|||||||
return view
|
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):
|
async def binfo_up_info(video_info: dict):
|
||||||
# UP主
|
# UP主
|
||||||
# 等级 0-4 \uE6CB-F 5-6\uE6D0-1
|
# 等级 0-4 \uE6CB-F 5-6\uE6D0-1
|
||||||
@ -176,35 +183,41 @@ async def binfo_up_info(video_info: dict):
|
|||||||
up_list = []
|
up_list = []
|
||||||
for up in video_info["staff"]:
|
for up in video_info["staff"]:
|
||||||
up_mid = up["mid"]
|
up_mid = up["mid"]
|
||||||
u = User(up_mid, credential=credential)
|
up_data = await get_user_info(up_mid)
|
||||||
up_data = await u.get_user_info()
|
nickname_color, level = (
|
||||||
|
up_data["card"]["vip"]["nickname_color"],
|
||||||
|
up_data["card"]["level_info"]["current_level"],
|
||||||
|
)
|
||||||
up_list.append(
|
up_list.append(
|
||||||
{
|
{
|
||||||
"name": up["name"],
|
"name": up["name"],
|
||||||
"up_title": up["title"],
|
"up_title": up["title"],
|
||||||
"face": up["face"],
|
"face": up["face"],
|
||||||
"color": up_data["vip"]["nickname_color"]
|
"color": nickname_color if nickname_color != "" else "black",
|
||||||
if up_data["vip"]["nickname_color"] != ""
|
|
||||||
else "black",
|
|
||||||
"follower": up["follower"],
|
"follower": up["follower"],
|
||||||
"level": up_data["level"],
|
"level": level,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
up_mid = video_info["owner"]["mid"]
|
up_mid = video_info["owner"]["mid"]
|
||||||
u = User(up_mid, credential=credential)
|
up_data = await get_user_info(up_mid)
|
||||||
up_data = await u.get_user_info()
|
nickname_color, level = (
|
||||||
up_stat = await u.get_relation_info()
|
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 = [
|
up_list = [
|
||||||
{
|
{
|
||||||
"name": up_data["name"],
|
"name": name,
|
||||||
"up_title": "UP主",
|
"up_title": "UP主",
|
||||||
"face": up_data["face"],
|
"face": face,
|
||||||
"color": up_data["vip"]["nickname_color"]
|
"color": nickname_color if nickname_color != "" else "black",
|
||||||
if up_data["vip"]["nickname_color"] != ""
|
"follower": follower,
|
||||||
else "black",
|
"level": level,
|
||||||
"follower": up_stat["follower"],
|
|
||||||
"level": up_data["level"],
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
return up_list
|
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()}"
|
f"<b>{info['title']}</b>\n\n{info['desc']}\n\nhttps://b23.tv/{v.get_bvid()}"
|
||||||
)
|
)
|
||||||
if len(caption) > 800:
|
if len(caption) > 800:
|
||||||
caption = (
|
caption = f"<b>{info['title']}</b>\n\n简介过长,无法显示\n\nhttps://b23.tv/{v.get_bvid()}"
|
||||||
f"<b>{info['title']}</b>\n\n简介过长,无法显示\n\nhttps://b23.tv/{v.get_bvid()}"
|
|
||||||
)
|
|
||||||
return caption
|
return caption
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,14 @@ from re import Pattern
|
|||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from pyrogram.filters import create
|
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):
|
def regex(pattern: Union[str, Pattern], flags: int = 0):
|
||||||
@ -27,5 +34,5 @@ def regex(pattern: Union[str, Pattern], flags: int = 0):
|
|||||||
return create(
|
return create(
|
||||||
func,
|
func,
|
||||||
"RegexFilter",
|
"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):
|
async def check_exists(self):
|
||||||
if await LofterPostModel.get_by_post_id(self.post_id):
|
if await LofterPostModel.get_by_post_id(self.post_id):
|
||||||
self.text += (
|
self.text += f'\n📄 此图集已被<a href="https://t.me/{lofter_channel_username}">此频道</a>收录'
|
||||||
f'\n📄 此图集已被<a href="https://t.me/{lofter_channel_username}">此频道</a>收录'
|
|
||||||
)
|
|
||||||
|
|
||||||
async def init(self):
|
async def init(self):
|
||||||
await self.check_exists()
|
await self.check_exists()
|
||||||
|
@ -90,9 +90,9 @@ class TwitterClient:
|
|||||||
return await self.client.request(method, url, headers=headers, **kwargs)
|
return await self.client.request(method, url, headers=headers, **kwargs)
|
||||||
|
|
||||||
async def reset_session(self):
|
async def reset_session(self):
|
||||||
self.headers[
|
self.headers["authorization"] = (
|
||||||
"authorization"
|
f"Basic {base64.b64encode(self.tokens[0].encode()).decode()}"
|
||||||
] = f"Basic {base64.b64encode(self.tokens[0].encode()).decode()}"
|
)
|
||||||
response = await self.request(
|
response = await self.request(
|
||||||
"https://api.twitter.com/oauth2/token",
|
"https://api.twitter.com/oauth2/token",
|
||||||
method="POST",
|
method="POST",
|
||||||
|
@ -78,7 +78,10 @@ class UserName(BaseModel):
|
|||||||
if self.status == AuctionStatus.Available:
|
if self.status == AuctionStatus.Available:
|
||||||
text += f"最低出价:{self.now_price.text}\n"
|
text += f"最低出价:{self.now_price.text}\n"
|
||||||
elif self.status == AuctionStatus.OnAuction:
|
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:
|
elif self.status == AuctionStatus.Sold:
|
||||||
text += (
|
text += (
|
||||||
f"售出价格:{self.now_price.text}\n"
|
f"售出价格:{self.now_price.text}\n"
|
||||||
@ -86,7 +89,10 @@ class UserName(BaseModel):
|
|||||||
f"售出时间:{self.strf_end_time}\n"
|
f"售出时间:{self.strf_end_time}\n"
|
||||||
)
|
)
|
||||||
elif self.status == AuctionStatus.Sale:
|
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
|
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()):
|
if video_db := await BiliFavAction.get_by_bv_id(video.get_bvid()):
|
||||||
await message.reply_video(
|
await message.reply_video(
|
||||||
video_db.file_id,
|
video_db.file_id,
|
||||||
caption=f"详细信息:https://t.me/{bilifav_channel_username}/{video_db.message_id}"
|
caption=(
|
||||||
if video_db.message_id
|
f"详细信息:https://t.me/{bilifav_channel_username}/{video_db.message_id}"
|
||||||
else None,
|
if video_db.message_id
|
||||||
|
else None
|
||||||
|
),
|
||||||
quote=True,
|
quote=True,
|
||||||
)
|
)
|
||||||
raise ContinuePropagation
|
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()):
|
if audio_db := await BiliFavAction.get_by_id(audio.get_auid()):
|
||||||
await message.reply_audio(
|
await message.reply_audio(
|
||||||
audio_db.file_id,
|
audio_db.file_id,
|
||||||
caption=f"详细信息:https://t.me/{bilifav_channel_username}/{audio_db.message_id}"
|
caption=(
|
||||||
if audio_db.message_id
|
f"详细信息:https://t.me/{bilifav_channel_username}/{audio_db.message_id}"
|
||||||
else None,
|
if audio_db.message_id
|
||||||
|
else None
|
||||||
|
),
|
||||||
quote=True,
|
quote=True,
|
||||||
)
|
)
|
||||||
raise ContinuePropagation
|
raise ContinuePropagation
|
||||||
|
@ -66,7 +66,9 @@ async def dc_query(_: Client, inline_query: InlineQuery):
|
|||||||
results = [
|
results = [
|
||||||
InlineQueryResultArticle(
|
InlineQueryResultArticle(
|
||||||
title="查询 dc",
|
title="查询 dc",
|
||||||
input_message_content=InputTextMessageContent(message_text="加载中,请等待。。。"),
|
input_message_content=InputTextMessageContent(
|
||||||
|
message_text="加载中,请等待。。。"
|
||||||
|
),
|
||||||
reply_markup=InlineKeyboardMarkup(
|
reply_markup=InlineKeyboardMarkup(
|
||||||
[[InlineKeyboardButton(text="重试", callback_data="dc")]]
|
[[InlineKeyboardButton(text="重试", callback_data="dc")]]
|
||||||
),
|
),
|
||||||
@ -82,7 +84,10 @@ async def dc_query(_: Client, inline_query: InlineQuery):
|
|||||||
|
|
||||||
|
|
||||||
def get_dc_text(dc: int):
|
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$"))
|
@bot.on_chosen_inline_result(inline_result_filters.regex(r"^dc$"))
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
from pyrogram import Client, filters
|
from pyrogram import Client, filters
|
||||||
from pyrogram.enums import ChatType
|
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 defs.exchange import exchange_client
|
||||||
from scheduler import scheduler
|
from scheduler import scheduler
|
||||||
|
@ -48,4 +48,6 @@ async def geo_command(_: Client, message: Message):
|
|||||||
msg = await message.reply_location(
|
msg = await message.reply_location(
|
||||||
longitude=float(lat), latitude=float(lon), quote=True
|
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(
|
InlineQueryResultArticle(
|
||||||
title="exchange",
|
title="exchange",
|
||||||
input_message_content=InputTextMessageContent("使用 exchange 来查询汇率数据"),
|
input_message_content=InputTextMessageContent(
|
||||||
|
"使用 exchange 来查询汇率数据"
|
||||||
|
),
|
||||||
description="使用 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}"):
|
if temp := await cache.get(f"sticker:export:{message.from_user.id}"):
|
||||||
try:
|
try:
|
||||||
await export_add(temp, message.sticker, client)
|
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:
|
except ValueError as exc:
|
||||||
await message.reply(str(exc), quote=True)
|
await message.reply(str(exc), quote=True)
|
||||||
else:
|
else:
|
||||||
@ -87,7 +89,9 @@ async def process_custom_emoji(client: "Client", message: "Message"):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
await message.reply("无法获取贴纸", quote=True)
|
await message.reply("无法获取贴纸", quote=True)
|
||||||
raise ContinuePropagation
|
raise ContinuePropagation
|
||||||
reply = await message.reply(f"正在下载 {len(stickers)} 个 emoji ...请耐心等待", quote=True)
|
reply = await message.reply(
|
||||||
|
f"正在下载 {len(stickers)} 个 emoji ...请耐心等待", quote=True
|
||||||
|
)
|
||||||
exc = None
|
exc = None
|
||||||
for sticker in stickers:
|
for sticker in stickers:
|
||||||
target_file = None
|
target_file = None
|
||||||
@ -118,15 +122,21 @@ async def batch_start(_: "Client", message: "Message"):
|
|||||||
if "start" in message.command[0].lower():
|
if "start" in message.command[0].lower():
|
||||||
if await cache.get(f"sticker:export:{uid}"):
|
if await cache.get(f"sticker:export:{uid}"):
|
||||||
await message.reply(
|
await message.reply(
|
||||||
"已经开始批量导出贴纸,请直接发送贴纸,完成选择请输入 /sticker_export_end", quote=True
|
"已经开始批量导出贴纸,请直接发送贴纸,完成选择请输入 /sticker_export_end",
|
||||||
|
quote=True,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
await cache.set(f"sticker:export:{uid}", tempfile.mkdtemp())
|
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:
|
else:
|
||||||
target_dir = await cache.get(f"sticker:export:{uid}")
|
target_dir = await cache.get(f"sticker:export:{uid}")
|
||||||
if not target_dir:
|
if not target_dir:
|
||||||
await message.reply("未开始批量导出贴纸,请先使用命令 /sticker_export_start", quote=True)
|
await message.reply(
|
||||||
|
"未开始批量导出贴纸,请先使用命令 /sticker_export_start", quote=True
|
||||||
|
)
|
||||||
return
|
return
|
||||||
file = None
|
file = None
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user