Add Y'all Seein' Eye award v2 for offsitementions.

Reusing the assets and design for the ill-fated YSE in a0f441a67d.
This time, the award provides access to our offsite mentions (reddit
notifs).
remotes/1693045480750635534/spooky-22
Snakes 2022-06-10 07:12:19 -04:00
parent 933f2a9a40
commit 8709ca816d
7 changed files with 36 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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):

View File

@ -30,14 +30,14 @@
Messages
</a>
</li>
{% if v.admin_level > 1 %}
{% if v.admin_level >= 2 %}
<li class="nav-item">
<a class="nav-link py-3{% if '/notifications?modmail=true' in request.full_path %} active{% endif %}" href="/notifications?modmail=true">
Modmail
</a>
</li>
{% endif %}
{% if v.admin_level %}
{% if v.can_view_offsitementions %}
<li class="nav-item">
<a class="nav-link py-3{% if '/notifications?reddit=true' in request.full_path %} active{% endif %}" href="/notifications?reddit=true">
Reddit {% if v.reddit_notifications_count %}<span class="font-weight-bold" style="color:#805ad5">({{v.reddit_notifications_count}})</span>{% endif %}

View File

@ -1,6 +1,6 @@
{%-
set CACHE_VER = {
'css/main.css': 297,
'css/main.css': 298,
'css/4chan.css': 59,
'css/classic.css': 59,