diff --git a/notifications/management/commands/send_best_comments.py b/notifications/management/commands/send_best_comments.py index 551102b41..89076c265 100644 --- a/notifications/management/commands/send_best_comments.py +++ b/notifications/management/commands/send_best_comments.py @@ -5,6 +5,7 @@ from django.core.management import BaseCommand from django.template.loader import render_to_string +from badges.models import UserBadge from comments.models import Comment from notifications.telegram.common import send_telegram_message, Chat @@ -26,7 +27,14 @@ def handle(self, *args, **options): upvotes__gte=MIN_UPVOTES, ).order_by("-upvotes")[:LIMIT] - for comment in best_comments: + new_badges = UserBadge.objects.filter( + created_at__gte=datetime.utcnow() - TIME_INTERVAL, + comment__isnull=False, + ).order_by("-created_at")[:LIMIT] + + comments_with_badges = [b.comment for b in new_badges] + + for comment in list(comments_with_badges) + list(best_comments): if not comment.metadata or not comment.metadata.get("in_best_comments"): self.stdout.write(f"Comment {comment.id} +{comment.upvotes}") comment.metadata = comment.metadata or {} diff --git a/notifications/telegram/templates/messages/best_comments.html b/notifications/telegram/templates/messages/best_comments.html index fcf9f7055..537b9b203 100644 --- a/notifications/telegram/templates/messages/best_comments.html +++ b/notifications/telegram/templates/messages/best_comments.html @@ -1,4 +1,6 @@ -{% load text_filters %}{% load posts %}Re: {% if comment.post.emoji %}{{ comment.post.emoji }} {% endif %}{% if comment.post.prefix %}{{ comment.post.prefix }} {% endif %}{{ comment.post.title }} +{% load text_filters %}{% load posts %}{% if comment.metadata.badges %}πŸ† ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΠ» Π½Π°Π³Ρ€Π°Π΄Ρƒ {% for badge in comment.metadata.badges.values %}Β«{{ badge.title }}Β» {% endfor %} + +{% endif %}Re: {% if comment.post.emoji %}{{ comment.post.emoji }} {% endif %}{% if comment.post.prefix %}{{ comment.post.prefix }} {% endif %}{{ comment.post.title }} (+{{ comment.upvotes }}) {{ comment.author.full_name }}: {% render_plain comment 3000 %}