diff --git a/files/classes/user.py b/files/classes/user.py index d547f6e3d..f3543d851 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -90,6 +90,7 @@ class User(Base): unmutable = Column(Boolean) eye = Column(Boolean) alt = Column(Boolean) + offsitementions = Column(Boolean, default=False, nullable=False) frontsize = Column(Integer, default=25) controversial = Column(Boolean, default=False) bio = deferred(Column(String)) @@ -229,7 +230,11 @@ class User(Base): if self.has_badge(badge): discount -= discounts[badge] return discount - + + @property + @lazy + def can_view_offsitementions(self): + return self.offsitementions or self.admin_level >= REDDIT_NOTIFS_JL_MIN @property @lazy diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 25fc50d8e..1f4872021 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -5,12 +5,12 @@ from files.classes.badges import Badge, BadgeDef # TODO: More sanity checks on passed parameters. # TODO: Add `replace=False` parameter which, when set true, removes any # existing badge with identical id & user and replaces with new one. -def badge_grant(user_id, badge_id, desc='', url=''): +def badge_grant(user_id, badge_id, desc='', url='', commit=True): user = g.db.query(User).filter(User.id == int(user_id)).one_or_none() if not user: - return False + return None elif user.has_badge(badge_id): - return True + return None badge = Badge( badge_id=int(badge_id), @@ -20,5 +20,8 @@ def badge_grant(user_id, badge_id, desc='', url=''): ) g.db.add(badge) - g.db.commit() - return True + if commit: + g.db.commit() + else: + g.db.flush() + return badge diff --git a/files/helpers/const.py b/files/helpers/const.py index 7bd4d290f..a7e2a19b9 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -662,6 +662,14 @@ AWARDS = { "color": "text-silver", "price": 10000 }, + "offsitementions": { + "kind": "offsitementions", + "title": "Y'all Seein' Eye", + "description": "Gives the recipient access to notifications when people off-site talk about us.", + "icon": "fas fa-eyes", + "color": "text-orange", + "price": 10000, + }, "unblockable": { "kind": "unblockable", "title": "Unblockable", @@ -803,6 +811,7 @@ else: patron = 'Patron' REDDIT_NOTIFS_SITE = [] REDDIT_NOTIFS_USERS = {} +REDDIT_NOTIFS_JL_MIN = 1 if SITE_NAME == 'rDrama': REDDIT_NOTIFS_SITE = ['rdrama', 'marsey',] @@ -816,6 +825,7 @@ if SITE_NAME == 'rDrama': } elif SITE_NAME == 'PCM': REDDIT_NOTIFS_SITE = ['pcmemes.net',] + REDDIT_NOTIFS_JL_MIN = 3 discounts = { # Big Spender badges, 2pp additive discount each diff --git a/files/helpers/offsitementions.py b/files/helpers/offsitementions.py index b1415123f..2601ef735 100644 --- a/files/helpers/offsitementions.py +++ b/files/helpers/offsitementions.py @@ -1,6 +1,7 @@ from flask import g import itertools import requests +from sqlalchemy import _or import files.helpers.const as const from files.classes.user import User from files.classes.comment import Comment @@ -13,9 +14,9 @@ from files.classes.notifications import Notification def offsite_mentions_task(): if const.REDDIT_NOTIFS_SITE: - # Site-specific logic: send to JL1+, except on PCM JL3+ - jl_min = 3 if const.SITE_NAME == 'PCM' else 1 - row_send_to = g.db.query(User.id).filter(User.admin_level >= jl_min).all() + row_send_to = g.db.query(User.id) + .filter(_or(User.admin_level >= const.REDDIT_NOTIFS_JL_MIN, + User.offsitementions == True)).all() send_to = [x[0] for x in row_send_to] site_mentions = get_mentions(const.REDDIT_NOTIFS_SITE) diff --git a/files/routes/awards.py b/files/routes/awards.py index 5006f6382..e2abb3156 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -4,6 +4,7 @@ from files.helpers.alerts import * from files.helpers.get import * from files.helpers.const import * from files.helpers.discord import * +from files.helpers.actions import badge_grant from files.classes.award import * from .front import frontlist from flask import g, request @@ -301,6 +302,10 @@ def award_thing(v, thing_type, id): g.db.add(new_badge) g.db.flush() send_notification(author.id, f"@AutoJanny has given you the following profile badge:\n\n![]({new_badge.path})\n\n{new_badge.name}") + elif kind == "offsitementions": + author.offsitementions = True + new_badge = badge_grant(user_id=author.id, badge_id=140, commit=False) + send_notification(author.id, f"@AutoJanny has given you the following profile badge:\n\n![]({new_badge.path})\n\n{new_badge.name}") elif kind == "alt": author.alt = True if not author.has_badge(84): diff --git a/files/templates/notifications.html b/files/templates/notifications.html index 62d954aeb..e562f2775 100644 --- a/files/templates/notifications.html +++ b/files/templates/notifications.html @@ -30,14 +30,14 @@ Messages - {% if v.admin_level > 1 %} + {% if v.admin_level >= 2 %} {% endif %} - {% if v.admin_level %} + {% if v.can_view_offsitementions %}