forked from rDrama/rDrama
1
0
Fork 0
master
Aevann1 2022-01-04 15:13:02 +02:00
parent d2167f3af4
commit 6357a86ecf
5 changed files with 27 additions and 20 deletions

View File

@ -324,6 +324,11 @@ class User(Base):
def url(self):
return f"/@{self.username}"
@property
@lazy
def url2(self):
return f"/id/{self.id}"
def __repr__(self):
return f"<User(username={self.username})>"

View File

@ -27,7 +27,9 @@ def send_repeatable_notification(uid, text, autojanny=False):
text_html = sanitize(Renderer2().render(mistletoe.Document(text)))
for i in re.finditer("<p>@((\w|-){1,25})", text_html):
text_html = text_html.replace(f'@{i.group(1)}', f'<a href="/@{i.group(1)}"><img loading="lazy" src="/@{i.group(1)}/pic" class="pp20">@{i.group(1)}</a>')
u = get_user(i.group(1), graceful=True)
if u:
text_html = text_html.replace(f'<p>@{u.username}', f'<p><a href="{u.url2}"><img loading="lazy" src="/uid/{u.id}/pic" class="pp20">@{u.username}</a>')
existing_comment = g.db.query(Comment.id).filter_by(author_id=author_id, parent_submission=None, distinguish_level=6, body_html=text_html, created_utc=0).first()
@ -55,7 +57,9 @@ def notif_comment(text, autojanny=False):
text_html = sanitize(Renderer2().render(mistletoe.Document(text)))
for i in re.finditer("<p>@((\w|-){1,25})", text_html):
text_html = text_html.replace(f'<p>@{i.group(1)}', f'<p><a href="/@{i.group(1)}"><img loading="lazy" src="/@{i.group(1)}/pic" class="pp20">@{i.group(1)}</a>')
u = get_user(i.group(1), graceful=True)
if u:
text_html = text_html.replace(f'<p>@{u.username}', f'<p><a href="{user.url2}"><img loading="lazy" src="/uid/{u.id}/pic" class="pp20">@{u.username}</a>')
existing = g.db.query(Comment.id).filter_by(author_id=author_id, parent_submission=None, distinguish_level=6, body_html=text_html, created_utc=0).first()

View File

@ -42,7 +42,7 @@ class CustomRenderer(HTMLRenderer):
if not user: return f"{space}@{target}"
return f'''{space}<a href="{user.url}"><img alt="@{user.username}'s profile picture" loading="lazy" src="/uid/{user.id}/pic" class="pp20">@{user.username}</a>'''
return f'''{space}<a href="{user.url2}"><img alt="@{user.username}'s profile picture" loading="lazy" src="/uid/{user.id}/pic" class="pp20">@{user.username}</a>'''
def render_sub_mention(self, token):
space = token.target[0]
@ -69,7 +69,7 @@ class Renderer(HTMLRenderer):
if not user: return f"{space}@{target}"
return f'{space}<a href="{user.url}">@{user.username}</a>'
return f'{space}<a href="{user.url2}">@{user.username}</a>'
def render_sub_mention(self, token):
space = token.target[0]

View File

@ -206,9 +206,9 @@ def searchcomments(v):
except: page = 1
sort = request.values.get("sort", "new").lower()
t = request.values.get('t', 'all').lower()
t = request.values.get('t', 'month').lower()
criteria=searchparse(query)
criteria = searchparse(query)
comments = g.db.query(Comment.id).filter(Comment.parent_submission != None)
@ -223,14 +223,14 @@ def searchcomments(v):
else: comments = comments.filter(Comment.author_id == author.id)
if 'q' in criteria:
words=criteria['q'].split()
words=[Comment.body_html.ilike('%'+x+'%') for x in words]
words=tuple(words)
comments=comments.filter(*words)
words = criteria['q'].split()
words = [Comment.body.ilike('%'+x+'%') for x in words]
words = tuple(words)
comments = comments.filter(*words)
if 'over18' in criteria: comments = comments.filter(Comment.over_18==True)
if 'over18' in criteria: comments = comments.filter(Comment.over_18 == True)
if not(v and v.admin_level > 1): comments = comments.filter(Comment.deleted_utc == 0, Comment.is_banned == False)
if not (v and v.admin_level > 1): comments = comments.filter(Comment.deleted_utc == 0, Comment.is_banned == False)
if t:
now = int(time.time())
@ -264,11 +264,9 @@ def searchcomments(v):
total = comments.count()
comments = comments.offset(25 * (page - 1)).limit(26).all()
ids = [x[0] for x in comments]
next_exists = (len(ids) > 25)
ids = ids[:25]

View File

@ -205,7 +205,7 @@ def suicide(v, username):
t = int(time.time())
if v.admin_level == 0 and t - v.suicide_utc < 86400: return {"message": "You're on 1-day cooldown!"}
user = get_user(username)
suicide = f"Hi there,\n\nA [concerned user]({v.url}) reached out to us about you.\n\nWhen you're in the middle of something painful, it may feel like you don't have a lot of options. But whatever you're going through, you deserve help and there are people who are here for you.\n\nThere are resources available in your area that are free, confidential, and available 24/7:\n\n- Call, Text, or Chat with Canada's [Crisis Services Canada](https://www.crisisservicescanada.ca/en/)\n- Call, Email, or Visit the UK's [Samaritans](https://www.samaritans.org/)\n- Text CHAT to America's [Crisis Text Line](https://www.crisistextline.org/) at 741741.\nIf you don't see a resource in your area above, the moderators keep a comprehensive list of resources and hotlines for people organized by location. Find Someone Now\n\nIf you think you may be depressed or struggling in another way, don't ignore it or brush it aside. Take yourself and your feelings seriously, and reach out to someone.\n\nIt may not feel like it, but you have options. There are people available to listen to you, and ways to move forward.\n\nYour fellow users care about you and there are people who want to help."
suicide = f"Hi there,\n\nA [concerned user]({v.url2}) reached out to us about you.\n\nWhen you're in the middle of something painful, it may feel like you don't have a lot of options. But whatever you're going through, you deserve help and there are people who are here for you.\n\nThere are resources available in your area that are free, confidential, and available 24/7:\n\n- Call, Text, or Chat with Canada's [Crisis Services Canada](https://www.crisisservicescanada.ca/en/)\n- Call, Email, or Visit the UK's [Samaritans](https://www.samaritans.org/)\n- Text CHAT to America's [Crisis Text Line](https://www.crisistextline.org/) at 741741.\nIf you don't see a resource in your area above, the moderators keep a comprehensive list of resources and hotlines for people organized by location. Find Someone Now\n\nIf you think you may be depressed or struggling in another way, don't ignore it or brush it aside. Take yourself and your feelings seriously, and reach out to someone.\n\nIt may not feel like it, but you have options. There are people available to listen to you, and ways to move forward.\n\nYour fellow users care about you and there are people who want to help."
send_repeatable_notification(user.id, suicide)
v.suicide_utc = t
g.db.add(v)
@ -241,14 +241,14 @@ def transfer_coins(v, username):
tax = math.ceil(amount*0.03)
tax_receiver = g.db.query(User).filter_by(id=TAX_RECEIVER_ID).one_or_none()
tax_receiver.coins += tax
log_message = f"[@{v.username}]({v.url}) has transferred {amount} {app.config['COINS_NAME']} to [@{receiver.username}]({receiver.url})"
log_message = f"[@{v.username}]({v.url2}) has transferred {amount} {app.config['COINS_NAME']} to [@{receiver.username}]({receiver.url2})"
send_repeatable_notification(TAX_RECEIVER_ID, log_message)
g.db.add(tax_receiver)
else: tax = 0
receiver.coins += amount-tax
v.coins -= amount
send_repeatable_notification(receiver.id, f"🤑 [@{v.username}]({v.url}) has gifted you {amount-tax} {app.config['COINS_NAME']}!")
send_repeatable_notification(receiver.id, f"🤑 [@{v.username}]({v.url2}) has gifted you {amount-tax} {app.config['COINS_NAME']}!")
g.db.add(receiver)
g.db.add(v)
@ -277,7 +277,7 @@ def transfer_bux(v, username):
receiver.procoins += amount
v.procoins -= amount
send_repeatable_notification(receiver.id, f"🤑 [@{v.username}]({v.url}) has gifted you {amount} marseybux!")
send_repeatable_notification(receiver.id, f"🤑 [@{v.username}]({v.url2}) has gifted you {amount} marseybux!")
g.db.add(receiver)
g.db.add(v)
@ -714,7 +714,7 @@ def u_username_comments(username, v=None):
user = get_user(username, v=v)
if username != user.username: return redirect(f'{user.url}/comments')
if username != user.username: return redirect(f'{user.url2}/comments')
u = user