BiliBili_YouTubers_Live_Tra.../defs/msg.py
2022-03-25 00:23:15 +08:00

49 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from defs.utils import Vtuber, TrackMessage
from defs.thumbnail import thumb
from ci import me
template = """
{}
<b>{}</b> 正在直播
<b>标题:</b><code>{}</code>
<b>人气值:</b><code>{}</code>
<b>开播时间:</b><code>{}</code>
@DD_YTbs_Live_Tracker | @DD_YTbs_Bot
"""
def gen_button(data: Vtuber) -> InlineKeyboardMarkup:
data_ = [[InlineKeyboardButton("🔗️ 观看", url=data.room_link)],
[InlineKeyboardButton("主页", url=data.space_link),
InlineKeyboardButton(
"订阅",
url=f"https://t.me/{me.username}?start={data.room_id}"), ]
]
return InlineKeyboardMarkup(data_)
def format_text(text: str) -> str:
text = text.strip()
for i in ["/", " ", "-", "@", "", ]:
text = text.replace(i, "_")
for i in ["", "", "[", "]", "", "(", ")", "`", "!", ]:
text = text.replace(i, "")
return text.strip()
def gen_tags(data: Vtuber) -> str:
return f"#id{data.mid} #{format_text(data.name.split()[0])} "
async def gen_update_msg(data: Vtuber) -> TrackMessage:
text = template.format(gen_tags(data), data.name, data.title, data.online,
data.liveStartTimeStr,)
button = gen_button(data)
img = await thumb(data.face, data.title, data.name)
return TrackMessage(text, button, img)