forked from rDrama/rDrama
1
0
Fork 0

Merge branch 'frost' of https://github.com/Aevann1/Drama into frost

master
Aevann1 2022-06-21 16:34:55 +02:00
commit cc3feaffe3
20 changed files with 98 additions and 30 deletions

View File

@ -70,6 +70,7 @@ class User(Base):
received_award_count = Column(Integer, default=0)
created_utc = Column(Integer)
admin_level = Column(Integer, default=0)
last_active = Column(Integer, default=0, nullable=False)
coins_spent = Column(Integer, default=0)
lootboxes_bought = Column(Integer, default=0)
agendaposter = Column(Integer, default=0)
@ -198,6 +199,12 @@ class User(Base):
return time.strftime("%d %b %Y", time.gmtime(self.created_utc))
@property
@lazy
def last_active_date(self):
if self.last_active == 0:
return "never"
return str(time.strftime("%d %b %Y", time.gmtime(self.last_active)))
@property
@lazy
@ -345,7 +352,9 @@ class User(Base):
@lazy
def bio_html_eager(self):
if self.bio_html == None: return ''
return self.bio_html.replace('data-src', 'src').replace('src="/assets/images/loading.webp"', '')
return self.bio_html.replace('data-src', 'src') \
.replace('src="/assets/images/loading.webp?v=2"', '') \
.replace('src="/assets/images/loading.webp"', '')
@property
@lazy
@ -671,6 +680,13 @@ class User(Base):
def created_datetime(self):
return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc)))
@property
@lazy
def last_active_datetime(self):
if self.last_active == 0:
return "never"
return str(time.strftime("%Y-%m-%d %H:%M:%SZ", time.gmtime(self.last_active)))
@lazy
def subscribed_idlist(self, page=1):
posts = g.db.query(Subscription.submission_id).filter_by(user_id=self.id).all()
@ -724,3 +740,8 @@ class User(Base):
@lazy
def lottery_stats(self):
return { "winnings": self.total_lottery_winnings, "ticketsHeld": { "current": self.currently_held_lottery_tickets , "total": self.total_held_lottery_tickets } }
@property
@lazy
def can_create_hole(self):
return self.admin_level >= HOLE_CREATE_JL_MIN

View File

@ -140,9 +140,11 @@ AGENDAPOSTER_MSG_HTML = """<p>Hi <a href="/id/{id}"><img loading="lazy" src="/pp
################################################################################
HOLE_COST = 0
HOLE_CREATE_JL_MIN = 0
HOLE_INACTIVITY_DELETION = False
PIN_LIMIT = 3
POST_RATE_LIMIT = '1/second;2/minute;10/hour;50/day'
LOGGEDIN_ACTIVE_TIME = 15 * 60
NOTIFICATIONS_ID = 1
AUTOJANNY_ID = 2
@ -278,7 +280,7 @@ elif SITE == 'cringetopia.org':
"7": "886781932430565418",
}
elif SITE == 'watchpeopledie.co':
HOLE_COST = 10000
HOLE_CREATE_JL_MIN = 2
GIFT_NOTIF_ID = 13
CARP_ID = 13

View File

@ -6,6 +6,7 @@ import files.helpers.const as const
from files.classes.user import User
from files.classes.comment import Comment
from files.classes.notifications import Notification
from files.helpers.sanitize import sanitize
# https://api.pushshift.io/meta provides key server_ratelimit_per_minute
# At time of writing, the ratelimit is 120 req/min. We get nowhere near this
@ -38,23 +39,30 @@ def get_mentions(queries):
+ f'?html_decode=true&q={query}&size=1', timeout=5).json()['data']
except: break
for i in data:
for i in data:
# Special case: PokemonGoRaids says 'Marsey' a lot unrelated to us.
if i['subreddit'] == 'PokemonGoRaids': continue
mentions.append(i['permalink'])
mentions.append({
'permalink': i['permalink'],
'text': i['body' if kind == 'comment' else 'title'],
})
return mentions
def notify_mentions(send_to, mentions, mention_str='site mention'):
for m in mentions:
notif_text = f'<p>New {mention_str}: <a href="https://old.reddit.com{m}' \
permalink = m['permalink']
text = sanitize(m['text'])
notif_text = \
f'<p>New {mention_str}: <a href="https://old.reddit.com{permalink}' \
f'?context=89" rel="nofollow noopener noreferrer" target="_blank">' \
f'https://old.reddit.com{m}?context=89</a></p>'
f'https://old.reddit.com{permalink}?context=89</a></p>' \
f'<blockquote>{text}</blockquote>'
existing_comment = g.db.query(Comment.id).filter_by(
author_id=const.NOTIFICATIONS_ID,
parent_submission=None,
author_id=const.NOTIFICATIONS_ID,
parent_submission=None,
body_html=notif_text).one_or_none()
if existing_comment: continue

View File

@ -32,7 +32,8 @@ TLDS = ( # Original gTLDs and ccTLDs
'vu','wf','ws','xn','xxx','ye','yt','yu','za','zm','zw',
# New gTLDs
'app','cleaning','club','dev','florist','fun','gay','lgbt','life','lol',
'moe','mom','monster','pics','press','pub','win','wtf','xyz',
'moe','mom','monster','new','news','online','pics','press','pub','site',
'vip','win','wtf','xyz',
)
allowed_tags = ('b','blockquote','br','code','del','em','h1','h2','h3','h4','h5','h6','hr','i',
@ -221,7 +222,7 @@ def sanitize(sanitized, alert=False, edit=False):
if tag.get("src") and not tag["src"].startswith('/pp/'):
tag["loading"] = "lazy"
tag["data-src"] = tag["src"]
tag["src"] = "/assets/images/loading.webp"
tag["src"] = "/assets/images/loading.webp?v=2"
tag['alt'] = f'![]({tag["data-src"]})'
tag['referrerpolicy'] = "no-referrer"

View File

@ -128,6 +128,7 @@ def stats(site=None):
"total awards": g.db.query(AwardRelationship).count(),
"awards given": g.db.query(AwardRelationship).filter(or_(AwardRelationship.submission_id != None, AwardRelationship.comment_id != None)).count(),
"users who posted, commented, or voted in the past 7 days": len(active_users),
"users online in the past 7 days": g.db.query(User).filter(User.last_active > week).count(),
}
if site == 'rDrama':

View File

@ -53,15 +53,21 @@ def get_logged_in_user():
if v:
if session["session_id"] in loggedout: del loggedout[session["session_id"]]
loggedin[v.id] = timestamp
# Check against last_active + ACTIVE_TIME to reduce frequency of
# UPDATEs in exchange for a ±ACTIVE_TIME margin of error.
if (v.last_active + LOGGEDIN_ACTIVE_TIME) < timestamp:
v.last_active = timestamp
g.db.add(v)
g.db.commit()
else:
ua = str(user_agents.parse(g.agent))
if not ua.startswith('Spider') and 'bot' not in ua.lower():
loggedout[session["session_id"]] = (timestamp, ua)
g.loggedin_counter = len([x for x in loggedin.values() if timestamp-x<15*60])
g.loggedin_counter = len([x for x in loggedin.values() if timestamp-x < LOGGEDIN_ACTIVE_TIME])
cache.set(f'{SITE}_loggedin', loggedin)
g.loggedout_counter = len([x for x in loggedout.values() if timestamp-x[0]<15*60])
g.loggedout_counter = len([x for x in loggedout.values() if timestamp-x[0] < LOGGEDIN_ACTIVE_TIME])
cache.set(f'{SITE}_loggedout', loggedout)
g.v = v

View File

@ -63,14 +63,14 @@ def kippy(v):
@app.get('/admin/loggedin')
@admin_level_required(2)
def loggedin_list(v):
ids = [x for x,val in cache.get(f'{SITE}_loggedin').items() if time.time()-val<15*60]
ids = [x for x,val in cache.get(f'{SITE}_loggedin').items() if time.time()-val < LOGGEDIN_ACTIVE_TIME]
users = g.db.query(User).filter(User.id.in_(ids)).order_by(User.admin_level.desc(), User.truecoins.desc()).all()
return render_template("loggedin.html", v=v, users=users)
@app.get('/admin/loggedout')
@admin_level_required(2)
def loggedout_list(v):
users = sorted([val[1] for x,val in cache.get(f'{SITE}_loggedout').items() if time.time()-val[0]<15*60])
users = sorted([val[1] for x,val in cache.get(f'{SITE}_loggedout').items() if time.time()-val[0] < LOGGEDIN_ACTIVE_TIME])
return render_template("loggedout.html", v=v, users=users)
@app.get('/admin/merge/<id1>/<id2>')

View File

@ -654,7 +654,7 @@ def edit_comment(cid, v):
c = get_comment(cid, v=v)
if time.time() - c.created_utc > 7*24*60*60:
if time.time() - c.created_utc > 7*24*60*60 and not (c.post and c.post.private):
return {"error":"You can't edit comments older than 1 week!"}, 403
if c.author_id != v.id: abort(403)

View File

@ -12,7 +12,7 @@ valid_params=[
]
def searchparse(text):
text = text.lower()
criteria = {x[0]:x[1] for x in query_regex.findall(text)}

View File

@ -265,13 +265,17 @@ def remove_mod(v, sub):
@app.get("/create_hole")
@is_not_permabanned
def create_sub(v):
return render_template("sub/create_hole.html", v=v, cost=HOLE_COST)
if not v.can_create_hole:
abort(403)
return render_template("sub/create_hole.html", v=v, cost=HOLE_COST)
@app.post("/create_hole")
@is_not_permabanned
def create_sub2(v):
if not v.can_create_hole:
abort(403)
name = request.values.get('name')
if not name: abort(400)
name = name.strip().lower()

View File

@ -308,3 +308,5 @@
}
</style>
{%- endif %}
<link rel="preload" as="image" href="/assets/images/loading.webp?v=2">

View File

@ -9,7 +9,7 @@
</div>
<div class="modal-body">
<ul class="list-group post-actions">
{% if request.path.startswith('/post/') and v.admin_level > 2 %}
{% if (request.path.startswith('/post/') or request.path.startswith('/h/')) and v.admin_level > 2 and p.id %}
<button class="nobackground btn btn-link btn-block btn-lg text-left text-muted" data-bs-dismiss="modal" onclick="togglePostEdit('{{p.id}}')"><i class="far fa-edit text-center text-muted mr-3"></i>Edit</button>
{% endif %}

View File

@ -19,7 +19,9 @@
<div class="mb-4">{{sub.sidebar_html|safe}}</div>
{% endif %}
{% if v %}
<a class="btn btn-primary btn-block mb-3" href="/create_hole">CREATE HOLE</a>
{% if v.can_create_hole -%}
<a class="btn btn-primary btn-block mb-3" href="/create_hole">CREATE HOLE</a>
{%- endif %}
{% if v.mods(sub.name) %}
<a class="btn btn-primary btn-block mb-3" href="/h/{{sub.name}}/settings">HOLE SETTINGS</a>
{% endif %}
@ -29,7 +31,9 @@
<a class="btn btn-primary btn-block mb-3" href="/h/{{sub.name}}/followers">HOLE FOLLOWERS</a>
<a class="btn btn-primary btn-block mb-3" href="/h/{{sub.name}}/blockers">HOLE BLOCKERS</a>
{% else %}
<a class="btn btn-primary btn-block mb-3" href="/create_hole">CREATE HOLE</a>
{% if v and v.can_create_hole -%}
<a class="btn btn-primary btn-block mb-3" href="/create_hole">CREATE HOLE</a>
{%- endif %}
<a class="btn btn-primary btn-block mb-3" href="/holes">BROWSE HOLES</a>
<div class="mt-4">

View File

@ -19,7 +19,9 @@
<a class="btn btn-primary btn-block" href="/h/{{sub.name}}/blockers">HOLE BLOCKERS</a>
{% endif %}
<a class="btn btn-primary btn-block" href="/create_hole">CREATE HOLE</a>
{% if v and v.can_create_hole -%}
<a class="btn btn-primary btn-block" href="/create_hole">CREATE HOLE</a>
{%- endif %}
<a class="btn btn-primary btn-block" href="/holes">BROWSE HOLES</a>
<a class="btn btn-primary btn-block mt-5" href="https://ip2.network">STREAM LIST</a>
<a class="btn btn-primary btn-block" href="/post/4103">BUGS/SUGGESTIONS MEGATHREAD</a>

View File

@ -19,7 +19,9 @@
<div class="mb-4">{{sub.sidebar_html|safe}}</div>
{% endif %}
{% if v %}
<a class="btn btn-primary btn-block mb-3" href="/create_hole">CREATE HOLE</a>
{% if v.can_create_hole -%}
<a class="btn btn-primary btn-block mb-3" href="/create_hole">CREATE HOLE</a>
{%- endif %}
{% if v.mods(sub.name) %}
<a class="btn btn-primary btn-block mb-3" href="/h/{{sub.name}}/settings">HOLE SETTINGS</a>
{% endif %}

View File

@ -63,7 +63,9 @@ set VISITORS_HERE_FLAVOR = [
<div class="mb-4">{{sub.sidebar_html|safe}}</div>
{% endif %}
{% if v %}
<a class="btn btn-primary btn-block mb-3" href="/create_hole">CREATE HOLE</a>
{% if v.can_create_hole -%}
<a class="btn btn-primary btn-block mb-3" href="/create_hole">CREATE HOLE</a>
{%- endif %}
{% if v.mods(sub.name) %}
<a class="btn btn-primary btn-block mb-3" href="/h/{{sub.name}}/settings">HOLE SETTINGS</a>
{% endif %}
@ -78,9 +80,9 @@ set VISITORS_HERE_FLAVOR = [
<span id="sidebar--directory--subhead">Submit Marseys & Art | Info Megathreads</span>
</a>
<a class="btn btn-primary btn-block mb-3" href="/holes">BROWSE HOLES</a>
{% if v %}
{% if v and v.can_create_hole -%}
<a class="btn btn-primary btn-block mb-3" href="/create_hole">CREATE HOLE</a>
{% endif %}
{%- endif %}
<div class="rules mt-5">
<h3>Rules:</h3><br>

View File

@ -65,6 +65,8 @@
{% set voted=-2 %}
{% endif %}
{% set v_forbid_deleted = (p.deleted_utc != 0 or p.is_banned) and not (v and v.admin_level >= 2) and not (v and v.id == p.author_id) %}
{% if p.active_flags(v) %}
<div id="flaggers-{{p.id}}" class="flaggers d-none">
<strong><i class="far fa-fw fa-flag"></i> Reported by:</strong>
@ -112,6 +114,7 @@
<div class="card-header bg-transparent border-0 d-flex flex-row flex-nowrap pl-2 pl-md-0 p-0 mr-md-2">
{% if not v_forbid_deleted %}
<div style="z-index: 3;">
{% if p.club and not (v and (v.paid_dues or v.id == p.author_id)) %}
<img alt="post thumnail" loading="lazy" src="/e/marseyglow.webp" class="post-img">
@ -135,6 +138,7 @@
</a>
{% endif %}
</div>
{% endif %}
</div>
@ -337,7 +341,7 @@
</div>
{% if not p.club or v and (v.paid_dues or v.id == p.author_id) %}
{% if (not p.club or v and (v.paid_dues or v.id == p.author_id)) and not v_forbid_deleted %}
{% if p.realbody(v) %}
<div class="d-none card rounded border pt-3 pb-2 my-2 {% if p.author.agendaposter %}agendaposter{% endif %}" id="post-text-{{p.id}}">
{{p.realbody(v) | safe}}
@ -347,7 +351,7 @@
{% if p.is_image and not p.over_18 and ((v and v.cardview) or (not v and environ.get('CARD_VIEW') == '1')) %}
<div style="text-align: center" class="mt-3 mb-4">
<a {% if v and v.newtab and not g.webview %}target="_blank"{% endif %} rel="nofollow noopener noreferrer" href="{{p.realurl(v)}}">
<img loading="lazy" data-src="{{p.realurl(v)}}" src="/assets/images/loading.webp" class="img-fluid" style="max-height:20rem" alt="Unable to load image">
<img loading="lazy" data-src="{{p.realurl(v)}}" src="/assets/images/loading.webp?v=2" class="img-fluid" style="max-height:20rem" alt="Unable to load image">
</a>
</div>
{% elif p.is_video %}

View File

@ -125,6 +125,10 @@
<a href="/@{{u.username}}/following" id="profile--following">follows {{u.follow_count}} user{{'s' if u.follow_count != 1 else ''}}</a>&nbsp;&nbsp;
<span id="profile--joined">joined <span data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{u.created_datetime}}">{{u.created_date}}</span></span>
{% if v and v.admin_level >= 2 -%}
<span id="profile--lastactive" class="ml-2">last active <span data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{u.last_active_datetime}}">{{u.last_active_date}}</span></span>
{%- endif %}
</div>
{% if u.basedcount %}<p class="text-muted" id="profile--based">Based Count: {{u.basedcount}}</p>{% endif %}
@ -427,6 +431,10 @@
{% endif %}
<br><span id="profile--joined">joined <span data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{u.created_datetime}}" class="font-weight-bold">{{u.created_date}}</span></span>
{% if v and v.admin_level >= 2 -%}
<br><span id="profile--lastactive">last active <span data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{u.last_active_datetime}}" class="font-weight-bold">{{u.last_active_date}}</span></span>
{%- endif %}
</div>
{% if u.bio_html %}
<div class="text-muted text-break" id="profile--bio">{{u.bio_html | safe}}</div>

View File

@ -1,6 +1,6 @@
{%-
set CACHE_VER = {
'css/main.css': 340,
'css/main.css': 341,
'css/4chan.css': 61,
'css/classic.css': 61,

View File

@ -679,7 +679,8 @@ CREATE TABLE public.users (
total_held_lottery_tickets integer DEFAULT 0 NOT NULL,
total_lottery_winnings integer DEFAULT 0 NOT NULL,
can_gamble boolean DEFAULT true NOT NULL,
offsitementions boolean DEFAULT false NOT NULL
offsitementions boolean DEFAULT false NOT NULL,
last_active integer DEFAULT 0 NOT NULL
);