diff --git a/app/blueprints/packages/packages.py b/app/blueprints/packages/packages.py index 42f4591d..492ec0f5 100644 --- a/app/blueprints/packages/packages.py +++ b/app/blueprints/packages/packages.py @@ -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 diff --git a/app/tasks/webhooktasks.py b/app/tasks/webhooktasks.py index 0abcf72a..7c4f216d 100644 --- a/app/tasks/webhooktasks.py +++ b/app/tasks/webhooktasks.py @@ -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)