Lsposed_Modules_Updates_Tra.../defs/msg.py

68 lines
2.4 KiB
Python
Raw Normal View History

2022-03-19 17:44:35 +00:00
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)]]
2022-03-20 05:02:17 +00:00
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('.', '_')}"), ]])
else:
data_.extend([[InlineKeyboardButton("主页", url=data.homepageUrl),
InlineKeyboardButton(
"订阅",
url=f"https://t.me/{me.username}?start={data.name.replace('.', '_')}"), ]])
2022-03-19 17:44:35 +00:00
return InlineKeyboardMarkup(data_)
2022-03-20 05:02:17 +00:00
def format_text(text: str) -> str:
text = text.strip()
2022-03-20 12:34:51 +00:00
for i in ["/", " ", "-", "@", "", ]:
2022-03-20 05:02:17 +00:00
text = text.replace(i, "_")
2022-03-20 12:34:51 +00:00
for i in ["", "", "[", "]", "", "(", ")", "`", "!", ]:
2022-03-20 05:02:17 +00:00
text = text.replace(i, "")
return text.strip()
2022-03-19 17:44:35 +00:00
def gen_tags(data: Module) -> str:
2022-03-20 05:02:17 +00:00
text = f"#{format_text(data.description.split()[0])} "
if data.collaborators:
2023-02-03 10:05:44 +00:00
for i in data.collaborators:
text += f"#{format_text(i)} "
2022-03-19 17:44:35 +00:00
return text
def gen_update_msg(data: Module) -> TrackMessage:
text = template.format(gen_tags(data), data.name, data.description, data.latestRelease,
data.updatedAt,
2022-03-20 05:11:38 +00:00
data.releases[0].description.replace(r"\r\n", "\n")[:250].strip())
2022-03-19 17:44:35 +00:00
url = None
2022-03-20 05:02:17 +00:00
name = None
2022-08-08 06:38:00 +00:00
if data.releases and data.releases[0].releaseAssets:
url = data.releases[0].releaseAssets[0].url
mime = data.releases[0].releaseAssets[0].name.split(".")[-1:][0]
name = data.name.replace('.', '_') + "-" + data.latestRelease + "." + mime
2022-03-19 17:44:35 +00:00
button = gen_button(data)
return TrackMessage(text, url, name, button)