notify telegram of new comments

This commit is contained in:
j 2023-08-31 17:12:34 +01:00
parent dd2ce36765
commit 92f21cc859
2 changed files with 18 additions and 0 deletions

View file

@ -52,6 +52,15 @@ def announce_items():
os.unlink(f.name) 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) @app.task(queue="default", ignore_results=True)
def notify_moderators(id, link): def notify_moderators(id, link):
comment = models.Comment.objects.filter(id=id).first() comment = models.Comment.objects.filter(id=id).first()
@ -69,6 +78,10 @@ def notify_moderators(id, link):
rpc.send_reaction( rpc.send_reaction(
account, comment.data["moderator_ts"], "🎉", group=group account, comment.data["moderator_ts"], "🎉", group=group
) )
msg = '%s commented on <b>%s</b> at <a href="%s">%s</a>' % (
comment.name, comment.item.title, link, link
)
notify_telegram.delay(msg)
else: else:
print("failed to notify", r) print("failed to notify", r)

View file

@ -171,6 +171,11 @@ def publish_comment(request):
send_reaction( send_reaction(
account, comment.data["moderator_ts"], "🎉", group=group account, comment.data["moderator_ts"], "🎉", group=group
) )
link = request.build_absolute_uri(comment.item.get_absolute_url())
msg = '%s commented on <b>%s</b> at <a href="%s">%s</a>' % (
comment.name, comment.item.title, link, link
)
tasks.notify_telegram.delay(msg)
response['status'] = 'ok' response['status'] = 'ok'
else: else:
response['error'] = 'permission denied' response['error'] = 'permission denied'