diff --git a/app/item/tasks.py b/app/item/tasks.py index c2ff2a1..f51091a 100644 --- a/app/item/tasks.py +++ b/app/item/tasks.py @@ -52,6 +52,15 @@ def announce_items(): os.unlink(f.name) +@app.task(queue="default", ignore_results=True) +def notify_telegram(message): + if getattr(settings, "TELEGRAM_ANNOUNCE_CHANNEL"): + r = telegram_rpc.send( + message, + channel=settings.TELEGRAM_ANNOUNCE_CHANNEL + ) + + @app.task(queue="default", ignore_results=True) def notify_moderators(id, link): comment = models.Comment.objects.filter(id=id).first() @@ -69,6 +78,10 @@ def notify_moderators(id, link): rpc.send_reaction( account, comment.data["moderator_ts"], "🎉", group=group ) + msg = '%s commented on %s at %s' % ( + comment.name, comment.item.title, link, link + ) + notify_telegram.delay(msg) else: print("failed to notify", r) diff --git a/app/item/views.py b/app/item/views.py index c1a83d7..27be4b0 100644 --- a/app/item/views.py +++ b/app/item/views.py @@ -171,6 +171,11 @@ def publish_comment(request): send_reaction( account, comment.data["moderator_ts"], "🎉", group=group ) + link = request.build_absolute_uri(comment.item.get_absolute_url()) + msg = '%s commented on %s at %s' % ( + comment.name, comment.item.title, link, link + ) + tasks.notify_telegram.delay(msg) response['status'] = 'ok' else: response['error'] = 'permission denied'