flairlock

remotes/1693045480750635534/spooky-22
Aevann1 2021-10-21 22:50:00 +02:00
parent c6f4ccac26
commit c9a0e91e24
14 changed files with 100 additions and 46 deletions

View File

@ -71,7 +71,7 @@ class User(Base):
hidevotedon = Column(Boolean, default=False) hidevotedon = Column(Boolean, default=False)
highlightcomments = Column(Boolean, default=True) highlightcomments = Column(Boolean, default=True)
slurreplacer = Column(Boolean, default=True) slurreplacer = Column(Boolean, default=True)
flairchanged = Column(Boolean, default=False) flairchanged = Column(Integer)
newtab = Column(Boolean, default=False) newtab = Column(Boolean, default=False)
newtabexternal = Column(Boolean, default=True) newtabexternal = Column(Boolean, default=True)
oldreddit = Column(Boolean, default=True) oldreddit = Column(Boolean, default=True)

View File

@ -196,11 +196,19 @@ if SITE_NAME == "Drama":
"agendaposter": { "agendaposter": {
"kind": "agendaposter", "kind": "agendaposter",
"title": "Agendaposter", "title": "Agendaposter",
"description": "Force the agendaposter theme on the author for 24 hours.", "description": "Forces the agendaposter theme on the author for 24 hours.",
"icon": "fas fa-snooze", "icon": "fas fa-snooze",
"color": "text-purple", "color": "text-purple",
"price": 2000 "price": 2000
}, },
"flairlock": {
"kind": "flairlock",
"title": "!-Day Flairlock",
"description": "Sets a flair for the author and locks it or 24 hours.",
"icon": "fas fa-lock",
"color": "text-black",
"price": 1250
},
} }
else: else:
AWARDS = { AWARDS = {

View File

@ -227,3 +227,25 @@ def sanitize(sanitized, noimages=False):
sanitized = re.sub('<p>(https:\/\/[^ <>]*)', r'<p><a target="_blank" rel="nofollow noopener noreferrer" href="\1">\1</a></p>', sanitized) sanitized = re.sub('<p>(https:\/\/[^ <>]*)', r'<p><a target="_blank" rel="nofollow noopener noreferrer" href="\1">\1</a></p>', sanitized)
return sanitized return sanitized
def filter_title(title):
title = title.strip()
title = title.replace("\n", "")
title = title.replace("\r", "")
title = title.replace("\t", "")
title = bleach.clean(title, tags=[])
for i in re.finditer('(?<!"):([^ ]{1,30}?):', title):
emoji = i.group(1)
if emoji.startswith("!"):
emoji = emoji[1:]
if path.isfile(f'./files/assets/images/emojis/{emoji}.webp'):
title = re.sub(f'(?<!"):!{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{emoji}:" title=":!{emoji}:" delay="0" height=30 src="http://{site}/assets/images/emojis/{emoji}.webp" class="mirrored">', title)
elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'):
title = re.sub(f'(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" delay="0" height=30 src="http://{site}/assets/images/emojis/{emoji}.webp">', title)
if len(title) > 1500: abort(400)
else: return title

View File

@ -24,12 +24,6 @@ def get_logged_in_user():
else: v = None else: v = None
except: v = None except: v = None
if v and v.agendaposter_expires_utc and v.agendaposter_expires_utc < g.timestamp:
v.agendaposter_expires_utc = 0
v.agendaposter = False
g.db.add(v)
if v and (nonce < v.login_nonce): if v and (nonce < v.login_nonce):
x= (None, None) x= (None, None)
else: else:

View File

@ -806,7 +806,7 @@ def admin_title_change(user_id, v):
user=g.db.query(User).with_for_update().options(lazyload('*')).filter_by(id=user.id).first() user=g.db.query(User).with_for_update().options(lazyload('*')).filter_by(id=user.id).first()
user.customtitle=new_name user.customtitle=new_name
user.flairchanged = bool(request.values.get("locked")) if request.values.get("locked"): user.flairchanged = time.time() + 2629746
g.db.add(user) g.db.add(user)
if user.flairchanged: kind = "set_flair_locked" if user.flairchanged: kind = "set_flair_locked"

View File

@ -6,6 +6,7 @@ from files.helpers.const import *
from files.classes.award import * from files.classes.award import *
from .front import frontlist from .front import frontlist
from flask import g, request from flask import g, request
from files.helpers.sanitize import filter_title
AWARDS2 = { AWARDS2 = {
"ban": { "ban": {
@ -107,11 +108,19 @@ def shop(v):
"agendaposter": { "agendaposter": {
"kind": "agendaposter", "kind": "agendaposter",
"title": "Agendaposter", "title": "Agendaposter",
"description": "Force the agendaposter theme on the author for 24 hours.", "description": "Forces the agendaposter theme on the author for 24 hours.",
"icon": "fas fa-snooze", "icon": "fas fa-snooze",
"color": "text-purple", "color": "text-purple",
"price": 2000 "price": 2000
}, },
"flairlock": {
"kind": "flairlock",
"title": "1-Day Flairlock",
"description": "Sets a flair for the author and locks it or 24 hours.",
"icon": "fas fa-lock",
"color": "text-black",
"price": 1250
},
} }
else: else:
AWARDS = { AWARDS = {
@ -257,11 +266,19 @@ def buy(v, award):
"agendaposter": { "agendaposter": {
"kind": "agendaposter", "kind": "agendaposter",
"title": "Agendaposter", "title": "Agendaposter",
"description": "Force the agendaposter theme on the author for 24 hours.", "description": "Forces the agendaposter theme on the author for 24 hours.",
"icon": "fas fa-snooze", "icon": "fas fa-snooze",
"color": "text-purple", "color": "text-purple",
"price": 2000 "price": 2000
}, },
"flairlock": {
"kind": "flairlock",
"title": "1-Day Flairlock",
"description": "Sets a flair for the author and locks it or 24 hours.",
"icon": "fas fa-lock",
"color": "text-black",
"price": 1250
},
} }
else: else:
AWARDS = { AWARDS = {
@ -428,6 +445,12 @@ def award_post(pid, v):
if not author.has_badge(26): if not author.has_badge(26):
badge = Badge(user_id=author.id, badge_id=26) badge = Badge(user_id=author.id, badge_id=26)
g.db.add(badge) g.db.add(badge)
elif kind == "flairlock":
new_name = note[:100].replace("𒐪","")
author.customtitleplain = new_name
author.customtitle = filter_title(new_name)
if len(author.customtitle) > 1000: abort(403)
author.flairchanged = time.time() + 86400
post.author.received_award_count += 1 post.author.received_award_count += 1
g.db.add(post.author) g.db.add(post.author)
@ -529,7 +552,13 @@ def award_comment(cid, v):
if not author.has_badge(26): if not author.has_badge(26):
badge = Badge(user_id=author.id, badge_id=26) badge = Badge(user_id=author.id, badge_id=26)
g.db.add(badge) g.db.add(badge)
elif kind == "flairlock":
new_name = note[:100].replace("𒐪","")
author.customtitleplain = new_name
author.customtitle = filter_title(new_name)
if len(author.customtitle) > 1000: abort(403)
author.flairchanged = time.time() + 86400
c.author.received_award_count += 1 c.author.received_award_count += 1
g.db.add(c.author) g.db.add(c.author)

View File

@ -9,7 +9,7 @@ from files.routes.front import comment_idlist
from pusher_push_notifications import PushNotifications from pusher_push_notifications import PushNotifications
from flask import * from flask import *
from files.__main__ import app, limiter from files.__main__ import app, limiter
from .posts import filter_title from files.helpers.sanitize import filter_title
site = environ.get("DOMAIN").strip() site = environ.get("DOMAIN").strip()

View File

@ -335,29 +335,6 @@ def archiveorg(url):
try: requests.get(f'https://web.archive.org/save/{url}', headers={'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}, timeout=100) try: requests.get(f'https://web.archive.org/save/{url}', headers={'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}, timeout=100)
except Exception as e: print(e) except Exception as e: print(e)
def filter_title(title):
title = title.strip()
title = title.replace("\n", "")
title = title.replace("\r", "")
title = title.replace("\t", "")
title = bleach.clean(title, tags=[])
for i in re.finditer('(?<!"):([^ ]{1,30}?):', title):
emoji = i.group(1)
if emoji.startswith("!"):
emoji = emoji[1:]
if path.isfile(f'./files/assets/images/emojis/{emoji}.webp'):
title = re.sub(f'(?<!"):!{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{emoji}:" title=":!{emoji}:" delay="0" height=30 src="http://{site}/assets/images/emojis/{emoji}.webp" class="mirrored">', title)
elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'):
title = re.sub(f'(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" delay="0" height=30 src="http://{site}/assets/images/emojis/{emoji}.webp">', title)
if len(title) > 1500: abort(400)
else: return title
def thumbnail_thread(pid): def thumbnail_thread(pid):

View File

@ -10,7 +10,7 @@ from files.__main__ import app, cache, limiter
import youtube_dl import youtube_dl
from .front import frontlist from .front import frontlist
import os import os
from .posts import filter_title from files.helpers.sanitize import filter_title
from files.helpers.discord import add_role from files.helpers.discord import add_role
from shutil import copyfile from shutil import copyfile
import requests import requests

View File

@ -101,6 +101,16 @@ def api_vote_post(post_id, new, v):
post.stickied = None post.stickied = None
g.db.add(post) g.db.add(post)
cache.delete_memoized(frontlist) cache.delete_memoized(frontlist)
if v.agendaposter_expires_utc and v.agendaposter_expires_utc < time.time():
v.agendaposter_expires_utc = 0
v.agendaposter = False
g.db.add(v)
if v.flairchanged and v.flairchanged < time.time():
v.flairchanged = None
g.db.add(v)
try: try:
g.db.flush() g.db.flush()
post.upvotes = g.db.query(Vote.id).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=1).count() post.upvotes = g.db.query(Vote.id).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=1).count()
@ -159,6 +169,10 @@ def api_vote_comment(comment_id, new, v):
g.db.add(vote) g.db.add(vote)
if comment.is_pinned and comment.is_pinned.startswith("t:") and int(time.time()) > int(comment.is_pinned[2:]):
comment.is_pinned = None
g.db.add(comment)
try: try:
g.db.flush() g.db.flush()
comment.upvotes = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=1).count() comment.upvotes = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=1).count()

View File

@ -1,4 +1,4 @@
<script src="/assets/js/award_modal.js?v=53"></script> <script src="/assets/js/award_modal.js?v=57"></script>
<div class="modal fade" id="awardModal" tabindex="-1" role="dialog" aria-labelledby="awardModalTitle" aria-hidden="true"> <div class="modal fade" id="awardModal" tabindex="-1" role="dialog" aria-labelledby="awardModalTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-scrollable modal-dialog-centered" role="document"> <div class="modal-dialog modal-dialog-scrollable modal-dialog-centered" role="document">
@ -23,18 +23,18 @@
<div class="text-muted">{{award.owned}} owned</div> <div class="text-muted">{{award.owned}} owned</div>
</a> </a>
{% endfor %} {% endfor %}
<a class="card disabled d-md-none"> <!-- <a class="card disabled d-md-none">
<pre> <pre>
</pre> </pre>
</a> </a> -->
</div> </div>
<label for="note" class="pt-4">Note (optional):</label> <label id="notelabel" for="note" class="pt-4">Note (optional):</label>
<input id="kind" name="kind" value="" hidden> <input id="kind" name="kind" value="" hidden>
<textarea id="note" name="note" class="form-control" placeholder="Note to include in award notification"></textarea> <textarea id="note" name="note" class="form-control" placeholder="Note to include in award notification..."></textarea>
<input id="giveaward" class="btn btn-primary" style="float:right" type="submit" value="Give Award" disabled> <input id="giveaward" class="btn btn-primary" style="float:right" type="submit" value="Give Award" disabled>
</form> </form>
</div> </div>
@ -76,7 +76,7 @@
@media (min-width: 767.98px) { @media (min-width: 767.98px) {
.award-columns { .award-columns {
column-count: 9 !important; column-count: 5 !important;
} }
} }
</style> </style>

View File

@ -107,6 +107,16 @@
const date = new Date({{c.created_utc*1000}}); const date = new Date({{c.created_utc*1000}});
document.getElementById('timestamp-{{c.id}}').title = date.toString(); document.getElementById('timestamp-{{c.id}}').title = date.toString();
})() })()
{% if c.is_pinned %}
const pinned_info = document.getElementById('pinned-{{c.id}}')
{% if c.is_pinned.startswith('t:') %}
pinned_info.setAttribute("data-bs-original-title", `Pinned until ${new Date({{c.is_pinned[2:]}} * 1000).toString()}`)
{% else %}
pinned_info.setAttribute("data-bs-original-title", "Pinned by @{{c.is_pinned}}")
{%endif%}
{%endif%}
})()
</script> </script>
<div style="display:none" id="popover-{{c.id}}"> <div style="display:none" id="popover-{{c.id}}">
@ -262,7 +272,7 @@
{% if c.active_flags %}<a class="btn btn-primary" style="padding:1px 5px; font-size:10px;" href="javascript:void(0)" onclick="document.getElementById('flaggers-{{c.id}}').classList.toggle('d-none')">{{c.active_flags}} Reports</a>{% endif %} {% if c.active_flags %}<a class="btn btn-primary" style="padding:1px 5px; font-size:10px;" href="javascript:void(0)" onclick="document.getElementById('flaggers-{{c.id}}').classList.toggle('d-none')">{{c.active_flags}} Reports</a>{% endif %}
{% if c.over_18 %}<span class="badge badge-danger text-small-extra mr-1">+18</span>{% endif %} {% if c.over_18 %}<span class="badge badge-danger text-small-extra mr-1">+18</span>{% endif %}
{% if v and v.admin_level==6 and c.author.shadowbanned %}<i class="fas fa-user-times text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="Shadowbanned by @{{c.author.shadowbanned}}"></i>{% endif %} {% if v and v.admin_level==6 and c.author.shadowbanned %}<i class="fas fa-user-times text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="Shadowbanned by @{{c.author.shadowbanned}}"></i>{% endif %}
{% if c.is_pinned %}<i class="text-admin fas fa-thumbtack fa-rotate--45" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="Pinned by @{{c.is_pinned}}"></i>{% endif %} {% if c.is_pinned %}<i id='pinned-{{c.id}}' class="fas fa-thumbtack fa-rotate--45 text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="Pinned {% if c.is_pinned.startswith('t:') %}until {{c.is_pinned[2:]}}{% else %}by @{{c.is_pinned}}{%endif%}"></i>{% endif %}
{% if c.distinguish_level %}<i class="fas fa-broom text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="{{'SITE_NAME' | app_config}} Admin, speaking officially"></i>{% endif %} {% if c.distinguish_level %}<i class="fas fa-broom text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="{{'SITE_NAME' | app_config}} Admin, speaking officially"></i>{% endif %}
{% if c.is_op %}<i class="fas fa-microphone-stand text-info" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="OP"></i>{% endif %} {% if c.is_op %}<i class="fas fa-microphone-stand text-info" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="OP"></i>{% endif %}
{% if c.is_bot %}<i class="fad fa-robot text-info" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="Bot"></i>{% endif %} {% if c.is_bot %}<i class="fad fa-robot text-info" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="Bot"></i>{% endif %}

View File

@ -183,7 +183,7 @@
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% if v and v.admin_level==6 and p.author.shadowbanned %}<i class="fas fa-user-times text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="Shadowbanned by @{{p.author.shadowbanned}}"></i>{% endif %} {% if v and v.admin_level==6 and p.author.shadowbanned %}<i class="fas fa-user-times text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="Shadowbanned by @{{p.author.shadowbanned}}"></i>{% endif %}
{% if p.stickied %}<i id='pinned-{{ p.id }}' class="fas fa-thumbtack fa-rotate--45 text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="Pinned {% if p.stickied.startswith('t:') %}until {{p.stickied[2:]}}{% else %}by @{{p.stickied}}{%endif%}"></i>{% endif %} {% if p.stickied %}<i id='pinned-{{p.id}}' class="fas fa-thumbtack fa-rotate--45 text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="Pinned {% if p.stickied.startswith('t:') %}until {{p.stickied[2:]}}{% else %}by @{{p.stickied}}{%endif%}"></i>{% endif %}
{% if p.distinguish_level %}<i class="fas fa-broom text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="{{'SITE_NAME' | app_config}} Admin, speaking officially"></i>{% endif %} {% if p.distinguish_level %}<i class="fas fa-broom text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="{{'SITE_NAME' | app_config}} Admin, speaking officially"></i>{% endif %}
{% if p.is_pinned and request.path.startswith('/@') %}<i class="fas fa-thumbtack fa-rotate--45 text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="Pinned to profile"></i>{% endif %} {% if p.is_pinned and request.path.startswith('/@') %}<i class="fas fa-thumbtack fa-rotate--45 text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="" data-bs-original-title="Pinned to profile"></i>{% endif %}
{% if p.over_18 %}<span class="badge badge-danger text-small-extra mr-1">+18</span>{% endif %} {% if p.over_18 %}<span class="badge badge-danger text-small-extra mr-1">+18</span>{% endif %}

View File

@ -773,7 +773,7 @@ CREATE TABLE public.users (
bannerurl character varying(65), bannerurl character varying(65),
hidevotedon boolean, hidevotedon boolean,
newtab boolean, newtab boolean,
flairchanged boolean, flairchanged integer,
defaultsortingcomments character varying(15), defaultsortingcomments character varying(15),
theme character varying(15), theme character varying(15),
song character varying(50), song character varying(50),