Skip to content

Commit

Permalink
modules: post: Fetch changelog url from maintainers.json
Browse files Browse the repository at this point in the history
Replace the changelog argument with a boolean to optionally skip
posting changelog.
  • Loading branch information
pranayadmn committed Jul 31, 2024
1 parent d7513d9 commit 0571536
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository = "https://github.com/StatiXOS/statixbot"
python = "^3.11"
pyrogram = {git = "https://github.com/KurimuzonAkuma/pyrogram.git", rev = "v2.1.22"}
python-dotenv = "^1.0.1"
python-strtobool = "^1.0.2"
TgCrypto = "^1.2.5"

[tool.poetry.group.dev.dependencies]
Expand Down
20 changes: 14 additions & 6 deletions statixbot/modules/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pyrogram import Client, filters
from pyrogram.enums import ParseMode
from pyrogram.types import Message
from str_to_bool import str_to_bool

from statixbot.Auth import authorized
from statixbot.Module import ModuleBase
Expand Down Expand Up @@ -53,13 +54,13 @@ async def post_message(client: Client, message: Message) -> None:
args: str = message.text.split(maxsplit=2)
if len(args) < 2:
await message.reply_text(
"Usage: /post <code>&lt;codename&gt;</code> <code>[changelog]</code>",
"Usage: /post <code>&lt;codename&gt;</code> <code>[changelog (bool)]</code>",
parse_mode=ParseMode.HTML,
)
return

codename: str = args[1]
changelog: str = args[2] if len(args) == 3 else ""
postcl: bool = str_to_bool(args[2]) if len(args) == 3 else True

if codename not in JSON_DATA:
await message.reply_text(f"Codename `{codename}` not found in database.")
Expand All @@ -68,16 +69,23 @@ async def post_message(client: Client, message: Message) -> None:
data: Dict = JSON_DATA
release: Dict = data.get("release", {})
device: Dict = data.get(codename, {})
changelog: str = device.get("changelog", "")
download: str = (
f"https://downloads.statixos.com/{release.get('version', '0')}-{release.get('codename', 'UNKNOWN')}/{codename}"
)

message_text: str = (
f"#{codename} #{release.get('branch', 'unknown')}\n"
f"New **StatiXOS {release.get('codename', 'UNKNOWN')}** build for **{device.get('manufacturer', 'Unknown')} {device.get('model', 'Unknown')} ({codename})**!\n\n"
f"**Maintainer:** {device.get('maintainer', 'Unknown')}\n"
f"[Download](https://downloads.statixos.com/{release.get('version', '0')}-{release.get('codename', 'UNKNOWN')}/{codename})"
f"[Download]({download})"
)

if changelog:
message_text += f" | [Changelog]({changelog})"
if postcl:
if changelog:
message_text += f" | [Changelog](https://xdaforums.com/t/{changelog})"
else:
message_text += f" | [Changelog]({download}/changelog.txt)"

await client.send_message(
chat_id="-1001238532711",
Expand All @@ -92,6 +100,6 @@ async def post_message(client: Client, message: Message) -> None:
await message.reply_text("An error occurred while posting the message.")

add_cmd(
"post <code>&lt;codename&gt;</code> <code>[changelog]</code>",
"post <code>&lt;codename&gt;</code> <code>[changelog (bool)]</code>",
"Post a new build to @StatiXOSReleases.",
)

0 comments on commit 0571536

Please sign in to comment.