Skip to content

Commit

Permalink
modules: post: Make changelog argument optional
Browse files Browse the repository at this point in the history
  • Loading branch information
pranayadmn committed Jul 31, 2024
1 parent b99e5d6 commit d7513d9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions statixbot/modules/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ async def register(self, app: Client) -> None:
async def post_message(client: Client, message: Message) -> None:
try:
args: str = message.text.split(maxsplit=2)
if len(args) != 3:
if len(args) < 2:
await message.reply_text(
"Usage: /post <code>&lt;codename&gt;</code> <code>&lt;changelog&gt;</code>",
"Usage: /post <code>&lt;codename&gt;</code> <code>[changelog]</code>",
parse_mode=ParseMode.HTML,
)
return

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

if codename not in JSON_DATA:
await message.reply_text(f"Codename `{codename}` not found in database.")
Expand All @@ -73,9 +73,12 @@ async def post_message(client: Client, message: Message) -> None:
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}) | [Changelog]({changelog})"
f"[Download](https://downloads.statixos.com/{release.get('version', '0')}-{release.get('codename', 'UNKNOWN')}/{codename})"
)

if changelog:
message_text += f" | [Changelog]({changelog})"

await client.send_message(
chat_id="-1001238532711",
text=message_text,
Expand All @@ -89,6 +92,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>&lt;changelog&gt;</code>",
"post <code>&lt;codename&gt;</code> <code>[changelog]</code>",
"Post a new build to @StatiXOSReleases.",
)

0 comments on commit d7513d9

Please sign in to comment.