enemies and fixes

master
Aevann1 2021-11-06 17:21:05 +02:00
parent 3a14e1f172
commit e5dfdd701e
23 changed files with 172 additions and 42 deletions

View File

@ -326,8 +326,6 @@ class Comment(Base):
url_noquery = url.split('?')[0]
body = body.replace(url, f"{url_noquery}?{urlencode(p, True)}")
if self.author.sig_html and (self.author_id == 1904 or not (v and v.sigs_disabled)): return body + '<hr>' + self.author.sig_html
return body
def plainbody(self, v):

View File

@ -327,7 +327,6 @@ class Submission(Base):
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")
if v and v.nitter: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net")
if self.author.sig_html and (self.author_id == 1904 or not (v and v.sigs_disabled)): return body + '<hr>' + self.author.sig_html
return body
def plainbody(self, v):

View File

@ -89,6 +89,8 @@ class User(Base):
sigs_disabled = Column(Boolean)
friends = Column(String)
friends_html = Column(String)
enemies = Column(String)
enemies_html = Column(String)
is_banned = Column(Integer, default=0)
unban_utc = Column(Integer, default=0)
ban_reason = Column(String)

View File

@ -75,7 +75,7 @@ no_images = ['b',
'span',
]
allowed_attributes = {'*': ['href', 'style', 'src', 'class', 'title', 'rel', 'data-bs-original-name', 'direction', 'behavior']}
allowed_attributes = {'*': ['href', 'style', 'src', 'class', 'title', 'rel', 'data-bs-original-name', 'direction', 'behavior', 'scrollamount']}
allowed_protocols = ['http', 'https']

View File

@ -20,6 +20,15 @@ from files.helpers.discord import add_role
SITE_NAME = environ.get("SITE_NAME", "").strip()
@app.get("/fix")
@admin_level_required(6)
def fix(v):
for u in g.db.query(User).options(lazyload('*')).all():
u.post_count = g.db.query(Submission.id).options(lazyload('*')).filter_by(author_id=u.id, is_banned=False, deleted_utc=0).count()
g.db.add(u)
g.db.commit()
return 'sex'
@app.get("/truescore")
@admin_level_required(6)
def truescore(v):

View File

@ -737,7 +737,7 @@ def submit_post(v):
if request.headers.get("Authorization"): return {"error": f"File type not allowed"}, 400
else: return render_template("submit.html", v=v, error=f"File type not allowed.", title=title, body=request.values.get("body", "")), 400
if file.content_type.startswith('video/') and v.coins < app.config["VIDEO_COIN_REQUIREMENT"] and v.admin_level < 1:
if file.content_type.startswith('video/') and v.truecoins < app.config["VIDEO_COIN_REQUIREMENT"] and v.admin_level < 1:
if request.headers.get("Authorization"):
return {
"error": f"You need at least {app.config['VIDEO_COIN_REQUIREMENT']} coins to upload videos"
@ -927,7 +927,7 @@ def submit_post(v):
g.db.add(n)
g.db.flush()
v.post_count = g.db.query(Submission.id).options(lazyload('*')).filter_by(is_banned=False, deleted_utc=0).count()
v.post_count = g.db.query(Submission.id).options(lazyload('*')).filter_by(author_id=v.id, is_banned=False, deleted_utc=0).count()
g.db.add(v)
cache.delete_memoized(frontlist)

View File

@ -203,14 +203,14 @@ def settings_profile_post(v):
if bans:
ban = bans[0]
reason = f"Remove the {ban.domain} link from your top friends list and try again."
reason = f"Remove the {ban.domain} link from your friends list and try again."
if ban.reason: reason += f" {ban.reason}"
return {"error": reason}, 401
if len(friends_html) > 2000:
return render_template("settings_profile.html",
v=v,
error="Your top friends list is too long")
error="Your friends list is too long")
notify_users = set()
@ -223,7 +223,7 @@ def settings_profile_post(v):
if request.host == 'rdrama.net' and 'aevann' in friends_html.lower() and 1 not in notify_users: notify_users.add(1)
for x in notify_users:
message = f"@{v.username} has added you to their top friends!"
message = f"@{v.username} has added you to their friends list!"
existing = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message, Comment.notifiedto == x).first()
if not existing: send_notification(x, message)
@ -233,9 +233,52 @@ def settings_profile_post(v):
g.db.commit()
return render_template("settings_profile.html",
v=v,
msg="Your top friends have been updated.")
msg="Your friends list has been updated.")
if request.values.get("enemies"):
enemies = request.values.get("enemies")[:500]
for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', enemies, re.MULTILINE):
if "wikipedia" not in i.group(1): enemies = enemies.replace(i.group(1), f'![]({i.group(1)})')
enemies_html = CustomRenderer().render(mistletoe.Document(enemies))
enemies_html = sanitize(enemies_html)
bans = filter_comment_html(enemies_html)
if bans:
ban = bans[0]
reason = f"Remove the {ban.domain} link from your enemies list and try again."
if ban.reason: reason += f" {ban.reason}"
return {"error": reason}, 401
if len(enemies_html) > 2000:
return render_template("settings_profile.html",
v=v,
error="Your enemies list is too long")
notify_users = set()
soup = BeautifulSoup(enemies_html, features="html.parser")
for mention in soup.find_all("a", href=re.compile("^/@(\w+)")):
username = mention["href"].split("@")[1]
user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first()
if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id)
if request.host == 'rdrama.net' and 'aevann' in enemies_html.lower() and 1 not in notify_users: notify_users.add(1)
for x in notify_users:
message = f"@{v.username} has added you to their enemies list!"
existing = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message, Comment.notifiedto == x).first()
if not existing: send_notification(x, message)
v.enemies = enemies[:500]
v.enemies_html=enemies_html
g.db.add(v)
g.db.commit()
return render_template("settings_profile.html",
v=v,
msg="Your enemies list has been updated.")
if request.values.get("bio") or request.files.get('file') and request.headers.get("cf-ipcountry") != "T1":
@ -728,14 +771,14 @@ def settings_css(v):
@auth_required
def settings_profilecss_get(v):
if v.coins < 1000 and not v.patron and v.admin_level < 6: return f"You must have +1000 {COINS_NAME} or be a patron to set profile css."
if v.truecoins < 1000 and not v.patron and v.admin_level < 6: return f"You must have +1000 {COINS_NAME} or be a patron to set profile css."
return render_template("settings_profilecss.html", v=v)
@app.post("/settings/profilecss")
@limiter.limit("1/second")
@auth_required
def settings_profilecss(v):
if v.coins < 1000 and not v.patron: return f"You must have +1000 {COINS_NAME} or be a patron to set profile css."
if v.truecoins < 1000 and not v.patron: return f"You must have +1000 {COINS_NAME} or be a patron to set profile css."
profilecss = request.values.get("profilecss").strip().replace('\\', '').strip()[:4000]
v.profilecss = profilecss
g.db.add(v)

View File

@ -15,11 +15,11 @@
{% if v %}
<style>:root{--primary:#{{v.themecolor}}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=110"><link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=96">
<link rel="stylesheet" href="/assets/css/main.css?v=111"><link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=96">
{% if v.agendaposter %}<link rel="stylesheet" href="/assets/css/agendaposter.css?v=96">{% elif v.css %}<link rel="stylesheet" href="/@{{v.username}}/css">{% endif %}
{% else %}
<style>:root{--primary:#{{'DEFAULT_COLOR' | app_config}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=110"><link rel="stylesheet" href="/assets/css/{{'DEFAULT_THEME' | app_config}}.css?v=96">
<link rel="stylesheet" href="/assets/css/main.css?v=111"><link rel="stylesheet" href="/assets/css/{{'DEFAULT_THEME' | app_config}}.css?v=96">
{% endif %}
</head>

View File

@ -326,6 +326,12 @@
<pre></pre>
{% endif %}
{% if c.author.sig_html and (c.author_id == 1904 or not (v and v.sigs_disabled)) %}
<hr>
{{c.author.sig_html | safe}}
{% endif %}
{% if not c.parent_submission and c.author_id!=NOTIFICATIONS_ACCOUNT and c.author_id!=AUTOJANNY_ACCOUNT and c.author_id!=v.id %}
<a class="btn btn-primary" href="javascript:void(0)" onclick="document.getElementById('reply-m-{{c.id}}').classList.toggle('d-none')">Reply</a>
<pre></pre>

View File

@ -254,12 +254,12 @@
{% if v %}
<style>:root{--primary:#{{v.themecolor}}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=110">
<link rel="stylesheet" href="/assets/css/main.css?v=111">
<link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=96">
{% if v.agendaposter %}<link rel="stylesheet" href="/assets/css/agendaposter.css?v=96">{% elif v.css %}<link rel="stylesheet" href="/@{{v.username}}/css">{% endif %}
{% else %}
<style>:root{--primary:#{{'DEFAULT_COLOR' | app_config}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=110"><link rel="stylesheet" href="/assets/css/{{'DEFAULT_THEME' | app_config}}.css?v=96">
<link rel="stylesheet" href="/assets/css/main.css?v=111"><link rel="stylesheet" href="/assets/css/{{'DEFAULT_THEME' | app_config}}.css?v=96">
{% endif %}
{% endblock %}

View File

@ -459,41 +459,71 @@ line breaks
</tbody>
</table>
<h2>Allowed Attributes</h2>
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>href</td>
</tr>
<tr>
<td>style</td>
</tr>
<tr>
<td>src</td>
</tr>
<tr>
<td>class</td>
</tr>
<tr>
<td>title</td>
</tr>
<tr>
<td>rel</td>
</tr>
<tr>
<td>data-bs-original-name</td>
</tr>
<tr>
<td>direction</td>
</tr>
<tr>
<td>behavior</td>
</tr>
<tr>
<td>scrollamount</td>
</tr>
</tbody>
</table>
<h2>Allowed Styles</h2>
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th>Name</th>
<th>Type</th>
<th>Displays as</th>
</tr>
</thead>
<tbody>
<tr>
<td>color</td>
<td></td>
<td></td>
</tr>
<tr>
<td>background-color</td>
<td></td>
<td></td>
</tr>
<tr>
<td>font-weight</td>
<td></td>
<td></td>
</tr>
<tr>
<td>transform</td>
<td></td>
<td></td>
</tr>
<tr>
<td>-webkit-transform</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>

View File

@ -17,11 +17,11 @@
{% if v %}
<style>:root{--primary:#{{v.themecolor}}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=110"><link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=96">
<link rel="stylesheet" href="/assets/css/main.css?v=111"><link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=96">
{% if v.agendaposter %}<link rel="stylesheet" href="/assets/css/agendaposter.css?v=96">{% elif v.css %}<link rel="stylesheet" href="/@{{v.username}}/css">{% endif %}
{% else %}
<style>:root{--primary:#{{'DEFAULT_COLOR' | app_config}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=110"><link rel="stylesheet" href="/assets/css/{{'DEFAULT_THEME' | app_config}}.css?v=96">
<link rel="stylesheet" href="/assets/css/main.css?v=111"><link rel="stylesheet" href="/assets/css/{{'DEFAULT_THEME' | app_config}}.css?v=96">
{% endif %}
<div class="row justify-content-around">

View File

@ -12,7 +12,7 @@
<title>2-Step Login - {{'SITE_NAME' | app_config}}</title>
<style>:root{--primary:#{{'DEFAULT_COLOR' | app_config}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=110"><link rel="stylesheet" href="/assets/css/{{'DEFAULT_THEME' | app_config}}.css?v=96">
<link rel="stylesheet" href="/assets/css/main.css?v=111"><link rel="stylesheet" href="/assets/css/{{'DEFAULT_THEME' | app_config}}.css?v=96">
</head>

View File

@ -55,7 +55,7 @@
<style>:root{--primary:#{{v.themecolor}}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=110"><link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=96">
<link rel="stylesheet" href="/assets/css/main.css?v=111"><link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=96">
{% if v.agendaposter %}<link rel="stylesheet" href="/assets/css/agendaposter.css?v=96">{% elif v.css %}<link rel="stylesheet" href="/@{{v.username}}/css">{% endif %}
<link href="/assets/css/fa.css?v=52" rel="stylesheet">

View File

@ -40,10 +40,10 @@
{% if v %}
<style>:root{--primary:#{{v.themecolor}}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=110"><link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=96">
<link rel="stylesheet" href="/assets/css/main.css?v=111"><link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=96">
{% else %}
<style>:root{--primary:#{{'DEFAULT_COLOR' | app_config}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=110"><link rel="stylesheet" href="/assets/css/{{'DEFAULT_THEME' | app_config}}.css?v=96">
<link rel="stylesheet" href="/assets/css/main.css?v=111"><link rel="stylesheet" href="/assets/css/{{'DEFAULT_THEME' | app_config}}.css?v=96">
{% endif %}
<link href="/assets/css/fa.css?v=52" rel="stylesheet">

View File

@ -590,7 +590,7 @@
<div class="body d-lg-flex border-bottom">
<label class="text-black w-lg-25">Top friends</label>
<label class="text-black w-lg-25">Friends</label>
<div class="w-lg-100">
<form id="profile-friends" action="/settings/profile" method="post" enctype="multipart/form-data">
@ -609,6 +609,27 @@
</div>
<div class="body d-lg-flex border-bottom">
<label class="text-black w-lg-25">Enemies</label>
<div class="w-lg-100">
<form id="profile-enemies" action="/settings/profile" method="post" enctype="multipart/form-data">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<div class="input-group mb-2">
<textarea id="enemies-text" class="form-control rounded" aria-label="With textarea" placeholder="Enter your top enemies on the site..." rows="3" name="enemies" form="profile-enemies" maxlength="1500">{% if v.enemies %}{{v.enemies}}{% endif %}</textarea>
</div>
<pre></pre>
<div class="d-flex">
<small>Limit of 500 characters</small>
<input class="btn btn-primary ml-auto" id="enemiesSave" type="submit" value="Save Changes">
</div>
</form>
</div>
</div>
{% if v.patron or v.id == 1904 %}
<div class="body d-lg-flex border-bottom">
<label class="text-black w-lg-25">Signature</label>

View File

@ -36,7 +36,7 @@
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600&display=swap" rel="stylesheet">
<style>:root{--primary:#{{'DEFAULT_COLOR' | app_config}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=110"><link rel="stylesheet" href="/assets/css/{{'DEFAULT_THEME' | app_config}}.css?v=96">
<link rel="stylesheet" href="/assets/css/main.css?v=111"><link rel="stylesheet" href="/assets/css/{{'DEFAULT_THEME' | app_config}}.css?v=96">
</head>

View File

@ -31,7 +31,7 @@
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600&display=swap" rel="stylesheet">
<style>:root{--primary:#{{'DEFAULT_COLOR' | app_config}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=110"><link rel="stylesheet" href="/assets/css/{{'DEFAULT_THEME' | app_config}}.css?v=96">
<link rel="stylesheet" href="/assets/css/main.css?v=111"><link rel="stylesheet" href="/assets/css/{{'DEFAULT_THEME' | app_config}}.css?v=96">
</head>

View File

@ -517,6 +517,11 @@
</div>
{% endfor %}
{% if p.author.sig_html and (p.author_id == 1904 or not (v and v.sigs_disabled)) %}
<hr>
{{p.author.sig_html | safe}}
{% endif %}
{% if p.is_banned and p.ban_reason %}
<div class="text-removed mb-0">removed by @{{p.ban_reason}}</div>
{% endif %}

View File

@ -489,6 +489,11 @@
{% if p.realbody(v) %}
<div class="d-none card rounded border pb-0 pt-3 my-2" id="post-text-{{p.id}}">
{{p.realbody(v) | safe}}
{% if p.author.sig_html and (p.author_id == 1904 or not (v and v.sigs_disabled)) %}
<hr>
{{p.author.sig_html | safe}}
{% endif %}
</div>
{% endif %}

View File

@ -25,11 +25,11 @@
{% block stylesheets %}
{% if v %}
<style>:root{--primary:#{{v.themecolor}}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=110"><link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=96">
<link rel="stylesheet" href="/assets/css/main.css?v=111"><link rel="stylesheet" href="/assets/css/{{v.theme}}.css?v=96">
{% if v.agendaposter %}<link rel="stylesheet" href="/assets/css/agendaposter.css?v=96">{% elif v.css %}<link rel="stylesheet" href="/@{{v.username}}/css">{% endif %}
{% else %}
<style>:root{--primary:#{{'DEFAULT_COLOR' | app_config}}</style>
<link rel="stylesheet" href="/assets/css/main.css?v=110">
<link rel="stylesheet" href="/assets/css/main.css?v=111">
<link rel="stylesheet" href="/assets/css/{{'DEFAULT_THEME' | app_config}}.css?v=96">
{% endif %}
{% endblock %}
@ -133,7 +133,7 @@
<label class="custom-control-label" for="privateCheck">Draft</label>
</div>
{% if v.admin_level == 6 or (v.coins >= 750 and not v.club_banned) %}
{% if v.admin_level == 6 or (v.truecoins >= 750 and not v.club_banned) %}
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="clubCheck" name="club">
<label class="custom-control-label" for="clubCheck">Country Club thread</label>

View File

@ -177,10 +177,15 @@
{% endif %}
{% if u.friends_html %}
<p class="text-muted font-weight-bold">Top friends:</p>
<p class="text-muted font-weight-bold">Friends:</p>
{{u.friends_html | safe}}
{% endif %}
{% if u.enemies_html %}
<p class="text-muted font-weight-bold">Enemies:</p>
{{u.enemies_html | safe}}
{% endif %}
{% if u.received_awards %}
<div class="text-white rounded p-2 mb-3" style="background-color: rgba(50, 50, 50, 0.6); width: 30%;">
<p class="text-uppercase my-0" style="font-weight: bold; font-size: 12px;">Awards received</p>
@ -448,10 +453,15 @@
{% endif %}
{% if u.friends_html %}
<p class="text-muted font-weight-bold mt-3">Top friends:</p>
<p class="text-muted font-weight-bold mt-3">Friends:</p>
{{u.friends_html | safe}}
{% endif %}
{% if u.enemies_html %}
<p class="text-muted font-weight-bold mt-3">Enemies:</p>
{{u.enemies_html | safe}}
{% endif %}
{% if u.received_awards %}
<div class="text-white rounded p-2 my-3 text-center" style="background-color: rgba(50, 50, 50, 0.6);">
<p class="text-uppercase my-0" style="font-weight: bold; font-size: 12px;">Awards received</p>

View File

@ -820,6 +820,8 @@ CREATE TABLE public.users (
sig_html character varying(1000),
friends character varying(500),
friends_html character varying(2000)
enemies character varying(500),
enemies_html character varying(2000)
);