Skip to content

Commit

Permalink
Update post_release.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Bengejd committed Jun 12, 2024
1 parent 7d5d7c3 commit 11440f0
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions scripts/post_release.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from discord import Webhook, RequestsWebhookAdapter, Embed
from discord import SyncWebhook, Embed
import requests
import time
import sys
Expand Down Expand Up @@ -50,13 +50,13 @@ def get_newest_changelog():
exit(20)

def get_pretty_changelog(currTag, prevTag):
if len(changelog) == 0:
return "No changelog attached"
else:
s = changelog
prev_tag = f'## {prevTag}'.encode()
curr_tag = f'## {currTag}'.encode()
return s[s.find(curr_tag)+len(curr_tag):s.rfind(prev_tag)].decode().replace('### ', '\n').replace('\n\n', '\n').strip()
if len(changelog) == 0:
return "No changelog attached"
else:
s = changelog
prev_tag = f'## {prevTag}'.encode()
curr_tag = f'## {currTag}'.encode()
return s[s.find(curr_tag)+len(curr_tag):s.rfind(prev_tag)].decode().replace('### ', '\n').replace('\n\n', '\n').strip()

def split_longer_embed(changelog):
line = changelog
Expand All @@ -77,13 +77,13 @@ def split_longer_embed(changelog):

pretty_changelog = get_pretty_changelog(tag, prev_tag)

embed = {
"author": {"name": "PantheonDKP has been updated!"},
"title": name,
"color": 14464841,
"fields": [],
"footer": {"text": "Released by " + author + " (Neekio)"}
}
embed = Embed(
title=name,
color=14464841,
description="_This is a beta version and may still contain bugs_" if prerelease else None
)
embed.set_author(name="PantheonDKP has been updated!")
embed.set_footer(text="Released by " + author + " (Neekio)")

if len(pretty_changelog) > 1000:
multibody = split_longer_embed(pretty_changelog)
Expand All @@ -93,22 +93,20 @@ def split_longer_embed(changelog):
for body in multibody:
if len(body) > 0:
title = "**CHANGELOG**" if first else "\u200b"
embed["fields"].append({"name": title, "value": "```" + body + "```", "inline": False})
embed.add_field(name=title, value="```" + body + "```", inline=False)
first = False
else:
if len(body) > 0:
embed["fields"].append({"name": "**CHANGELOG**", "value": "```" + body + "```", "inline": False})
embed.add_field(name="**CHANGELOG**", value="```" + body + "```", inline=False)
else:
embed["fields"].append({"name": "CHANGELOG", "value": "`" + pretty_changelog + "`", "inline": False})
if prerelease:
embed["description"] = "_This is a beta version and may still contain bugs_"
embed.add_field(name="CHANGELOG", value="`" + pretty_changelog + "`", inline=False)

webhook = Webhook.from_url(sys.argv[1], adapter = RequestsWebhookAdapter())
webhook = SyncWebhook.from_url(sys.argv[1])
if prerelease:
webhook.send(embed = Embed.from_dict(embed))
webhook.send(embed=embed)
else:
webhook.send(content = "@everyone", embed = Embed.from_dict(embed))
webhook.send(content="@everyone", embed=embed)

except Exception as e:
print(str(e))
exit(30)

0 comments on commit 11440f0

Please sign in to comment.