Lsposed_Modules_Updates_Tra.../defs/msg.py
2022-03-20 01:44:35 +08:00

51 lines
1.6 KiB
Python

from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from defs.utils import Module, TrackMessage
from ci import me
template = """
{}
<b>模块:</b><code>{}</code>
<b>简介:</b><code>{}</code>
<b>版本:</b><code>{}</code>
<b>更新时间:</b><code>{}</code>
<b>更新日志:</b>
<code>
{}
</code>
@lsposed_Modules_Updates_Tracker | @lsposed_Geeks_Bot
"""
def gen_button(data: Module) -> InlineKeyboardMarkup:
data_ = []
if data.releases:
if data.releases[0].releaseAssets:
data_ = [[InlineKeyboardButton("⬇️ 下载", url=data.releases[0].releaseAssets[0].url)]]
data_.extend([[InlineKeyboardButton("Release", url=data.releases[0].url),
InlineKeyboardButton("主页", url=data.homepageUrl),
InlineKeyboardButton(
"订阅",
url=f"https://t.me/{me.username}?start={data.name.replace('.', '_')}"),]])
return InlineKeyboardMarkup(data_)
def gen_tags(data: Module) -> str:
text = f"#{data.description.split()[0]} "
text += f"#{data.collaborators[0]} "
return text
def gen_update_msg(data: Module) -> TrackMessage:
text = template.format(gen_tags(data), data.name, data.description, data.latestRelease,
data.updatedAt,
data.releases[0].description.replace(r"\r\n", "\n"))
url = None
if data.releases:
if data.releases[0].releaseAssets:
url = data.releases[0].releaseAssets[0].url
name = data.name.replace('.', '_') + "-" + data.latestRelease
button = gen_button(data)
return TrackMessage(text, url, name, button)