add 4chan offsite mentions
parent
2d7b5a2a01
commit
3207ccfd98
|
@ -891,7 +891,7 @@ class User(Base):
|
|||
return g.db.query(Comment).filter(
|
||||
Comment.created_utc > self.last_viewed_offsite_notifs,
|
||||
Comment.is_banned == False, Comment.deleted_utc == 0,
|
||||
Comment.body_html.like('%<p>New site mention by <a href=%'),
|
||||
Comment.body_html.like('<p>New site mention by%'),
|
||||
Comment.parent_post == None, Comment.author_id == AUTOJANNY_ID).count()
|
||||
|
||||
@property
|
||||
|
|
|
@ -28,6 +28,7 @@ from files.helpers.sanitize import filter_emojis_only, sanitize
|
|||
from files.helpers.useractions import *
|
||||
from files.helpers.offsite_mentions.reddit import *
|
||||
from files.helpers.offsite_mentions.lemmy import *
|
||||
from files.helpers.offsite_mentions.fourchan import *
|
||||
|
||||
from files.cli import app, db_session, g
|
||||
|
||||
|
@ -66,6 +67,9 @@ def cron_fn(every_5m, every_1d, every_1mo):
|
|||
lemmy_mentions_task()
|
||||
g.db.commit()
|
||||
|
||||
fourchan_mentions_task()
|
||||
g.db.commit()
|
||||
|
||||
if every_1d or (not cache.get('stats') and not IS_LOCALHOST):
|
||||
if IS_HOMOWEEN():
|
||||
g.db.execute(text(
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
import requests
|
||||
from flask import g
|
||||
|
||||
from files.helpers.config.const import *
|
||||
from files.classes.comment import Comment
|
||||
from files.helpers.sanitize import *
|
||||
from files.helpers.alerts import push_notif
|
||||
from files.classes.notifications import Notification
|
||||
|
||||
def fourchan_mentions_task():
|
||||
queries = OFFSITE_NOTIF_QUERIES - {'r/drama'}
|
||||
for q in queries:
|
||||
url = f'https://archived.moe/_/api/chan/search?text={q}'
|
||||
data = requests.get(url, headers=HEADERS, timeout=5).json()['0']['posts']
|
||||
|
||||
for thing in data:
|
||||
board = thing['board']['shortname']
|
||||
author_string = thing['name']
|
||||
num = thing["num"]
|
||||
thread_num = thing["thread_num"]
|
||||
|
||||
if num != thread_num:
|
||||
text = f'<blockquote><p>{thing["comment"]}</p></blockquote>'
|
||||
permalink = f'https://archived.moe/{board}/thread/{thread_num}/#{num}'
|
||||
else:
|
||||
text = f'<blockquote><p>{thing["title"]}</p></blockquote><br><blockquote><p>{thing["comment"]}</p></blockquote>'
|
||||
permalink = f'https://archived.moe/{board}/thread/{thread_num}'
|
||||
|
||||
text = f'New site mention by {author_string}\n\n{permalink}\n\n{text}'
|
||||
text = sanitize(text, blackjack="fourchan mention", golden=False)
|
||||
|
||||
existing_comment = g.db.query(Comment.id).filter_by(
|
||||
author_id=AUTOJANNY_ID,
|
||||
parent_post=None,
|
||||
body_html=text).one_or_none()
|
||||
if existing_comment: break
|
||||
|
||||
created_utc = thing["timestamp"]
|
||||
|
||||
new_comment = Comment(
|
||||
author_id=AUTOJANNY_ID,
|
||||
parent_post=None,
|
||||
body_html=text,
|
||||
distinguished=True,
|
||||
created_utc=created_utc,
|
||||
)
|
||||
|
||||
g.db.add(new_comment)
|
||||
g.db.flush()
|
||||
new_comment.top_comment_id = new_comment.id
|
|
@ -278,7 +278,7 @@ def notifications_offsite(v):
|
|||
if not v.can_view_offsite_mentions: abort(403)
|
||||
|
||||
listing = g.db.query(Comment).filter(
|
||||
Comment.body_html.like('%<p>New site mention by <a href=%'),
|
||||
Comment.body_html.like('<p>New site mention by%'),
|
||||
Comment.parent_post == None,
|
||||
Comment.author_id == AUTOJANNY_ID
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue