mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-03 19:57:29 +01:00
Add Discord embed to package webhooks
This commit is contained in:
parent
4c98063d6a
commit
540e24e8f9
@ -396,7 +396,8 @@ def move_to_state(package):
|
||||
if state == PackageState.APPROVED:
|
||||
if not package.approved_at:
|
||||
post_discord_webhook.delay(package.author.username,
|
||||
"New package {}".format(package.getURL("packages.view", absolute=True)), False)
|
||||
"New package {}".format(package.getURL("packages.view", absolute=True)), False,
|
||||
package.title, package.short_desc, package.getThumbnailURL(2, True))
|
||||
package.approved_at = datetime.datetime.now()
|
||||
|
||||
screenshots = PackageScreenshot.query.filter_by(package=package, approved=False).all()
|
||||
@ -406,7 +407,8 @@ def move_to_state(package):
|
||||
msg = "Approved {}".format(package.title)
|
||||
elif state == PackageState.READY_FOR_REVIEW:
|
||||
post_discord_webhook.delay(package.author.username,
|
||||
"Ready for Review: {}".format(package.getURL("packages.view", absolute=True)), True)
|
||||
"Ready for Review: {}".format(package.getURL("packages.view", absolute=True)), True,
|
||||
package.title, package.short_desc, package.getThumbnailURL(2, True))
|
||||
|
||||
addNotification(package.maintainers, current_user, NotificationType.PACKAGE_APPROVAL, msg, package.getURL("packages.view"), package)
|
||||
severity = AuditSeverity.NORMAL if current_user in package.maintainers else AuditSeverity.EDITOR
|
||||
|
@ -22,7 +22,7 @@ from app.models import User
|
||||
from app.tasks import celery
|
||||
|
||||
@celery.task()
|
||||
def post_discord_webhook(username: Optional[str], content: str, is_queue: bool):
|
||||
def post_discord_webhook(username: Optional[str], content: str, is_queue: bool, title: Optional[str], description: Optional[str], thumbnail: Optional[str]):
|
||||
discord_url = app.config.get("DISCORD_WEBHOOK_QUEUE" if is_queue else "DISCORD_WEBHOOK_FEED")
|
||||
if discord_url is None:
|
||||
return
|
||||
@ -37,4 +37,15 @@ def post_discord_webhook(username: Optional[str], content: str, is_queue: bool):
|
||||
if user:
|
||||
json["avatar_url"] = user.getProfilePicURL().replace("/./", "/")
|
||||
|
||||
if title:
|
||||
embed = {
|
||||
"title": title,
|
||||
"description": description,
|
||||
}
|
||||
|
||||
if thumbnail:
|
||||
embed["thumbnail"] = {"url": thumbnail}
|
||||
|
||||
json["embeds"] = [embed]
|
||||
|
||||
requests.post(discord_url, json=json)
|
||||
|
Loading…
Reference in New Issue
Block a user