Skip to content

Commit

Permalink
feat: include awarded comments in best comments script
Browse files Browse the repository at this point in the history
  • Loading branch information
vas3k committed Sep 22, 2023
1 parent 3d08764 commit 4664bd3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 9 additions & 1 deletion notifications/management/commands/send_best_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {}
Expand Down
4 changes: 3 additions & 1 deletion notifications/telegram/templates/messages/best_comments.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{% load text_filters %}{% load posts %}Re: <b><a href="{{ settings.APP_HOST }}{% url "show_comment" comment.post.slug comment.id %}">{% if comment.post.emoji %}{{ comment.post.emoji }} {% endif %}{% if comment.post.prefix %}{{ comment.post.prefix }} {% endif %}{{ comment.post.title }}</a></b>
{% load text_filters %}{% load posts %}{% if comment.metadata.badges %}🏆 Комментарий получил награду {% for badge in comment.metadata.badges.values %}«{{ badge.title }}» {% endfor %}

{% endif %}Re: <b><a href="{{ settings.APP_HOST }}{% url "show_comment" comment.post.slug comment.id %}">{% if comment.post.emoji %}{{ comment.post.emoji }} {% endif %}{% if comment.post.prefix %}{{ comment.post.prefix }} {% endif %}{{ comment.post.title }}</a></b>

(+{{ comment.upvotes }}) <b>{{ comment.author.full_name }}:</b> {% render_plain comment 3000 %}

Expand Down

0 comments on commit 4664bd3

Please sign in to comment.