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

master
Aevann1 2022-10-16 10:10:52 +02:00
commit 87852c6e65
14 changed files with 68 additions and 272 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -120,64 +120,12 @@ class Comment(Base):
if notif_utc: timestamp = notif_utc if notif_utc: timestamp = notif_utc
elif self.created_utc: timestamp = self.created_utc elif self.created_utc: timestamp = self.created_utc
else: return None else: return None
return make_age_string(timestamp)
age = int(time.time()) - timestamp
if age < 60:
return "just now"
elif age < 3600:
minutes = int(age / 60)
return f"{minutes}m ago"
elif age < 86400:
hours = int(age / 3600)
return f"{hours}hr ago"
elif age < 2678400:
days = int(age / 86400)
return f"{days}d ago"
now = time.gmtime()
ctd = time.gmtime(timestamp)
months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year)
if now.tm_mday < ctd.tm_mday:
months -= 1
if months < 12:
return f"{months}mo ago"
else:
years = int(months / 12)
return f"{years}yr ago"
@property @property
@lazy @lazy
def edited_string(self): def edited_string(self):
return make_age_string(self.edited_utc)
age = int(time.time()) - self.edited_utc
if age < 60:
return "just now"
elif age < 3600:
minutes = int(age / 60)
return f"{minutes}m ago"
elif age < 86400:
hours = int(age / 3600)
return f"{hours}hr ago"
elif age < 2678400:
days = int(age / 86400)
return f"{days}d ago"
now = time.gmtime()
ctd = time.gmtime(self.edited_utc)
months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year)
if now.tm_mday < ctd.tm_mday:
months -= 1
if months < 12:
return f"{months}mo ago"
else:
years = int(months / 12)
return f"{years}yr ago"
@property @property
@lazy @lazy

View File

@ -6,6 +6,7 @@ from files.helpers.lazy import lazy
from copy import deepcopy from copy import deepcopy
from files.helpers.const import * from files.helpers.const import *
from files.helpers.regex import censor_slurs from files.helpers.regex import censor_slurs
from files.helpers.sorting_and_time import make_age_string
class ModAction(Base): class ModAction(Base):
__tablename__ = "modactions" __tablename__ = "modactions"
@ -32,37 +33,10 @@ class ModAction(Base):
@property @property
@lazy @lazy
def age_string(self): def age_string(self):
return make_age_string(self.created_utc)
age = int(time.time()) - self.created_utc
if age < 60:
return "just now"
elif age < 3600:
minutes = int(age / 60)
return f"{minutes}m ago"
elif age < 86400:
hours = int(age / 3600)
return f"{hours}hr ago"
elif age < 2678400:
days = int(age / 86400)
return f"{days}d ago"
now = time.gmtime()
ctd = time.gmtime(self.created_utc)
months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year)
if now.tm_mday < ctd.tm_mday:
months -= 1
if months < 12:
return f"{months}mo ago"
else:
years = int(months / 12)
return f"{years}yr ago"
@property @property
def note(self): def note(self):
if self.kind=="ban_user": if self.kind=="ban_user":
if self.target_post: return f'for <a href="{self.target_post.permalink}">post</a>' if self.target_post: return f'for <a href="{self.target_post.permalink}">post</a>'
elif self.target_comment_id: return f'for <a href="/comment/{self.target_comment_id}">comment</a>' elif self.target_comment_id: return f'for <a href="/comment/{self.target_comment_id}">comment</a>'
@ -73,11 +47,8 @@ class ModAction(Base):
@property @property
@lazy @lazy
def string(self): def string(self):
output = ACTIONTYPES[self.kind]["str"].format(self=self, cc=CC_TITLE) output = ACTIONTYPES[self.kind]["str"].format(self=self, cc=CC_TITLE)
if self.note: output += f" <i>({self.note})</i>" if self.note: output += f" <i>({self.note})</i>"
return output return output
@property @property

View File

@ -5,6 +5,7 @@ import time
from files.helpers.lazy import lazy from files.helpers.lazy import lazy
from files.helpers.const import * from files.helpers.const import *
from files.helpers.regex import censor_slurs from files.helpers.regex import censor_slurs
from files.helpers.sorting_and_time import make_age_string
class SubAction(Base): class SubAction(Base):
__tablename__ = "subactions" __tablename__ = "subactions"
@ -32,42 +33,13 @@ class SubAction(Base):
@property @property
@lazy @lazy
def age_string(self): def age_string(self):
return make_age_string(self.created_utc)
age = int(time.time()) - self.created_utc
if age < 60:
return "just now"
elif age < 3600:
minutes = int(age / 60)
return f"{minutes}m ago"
elif age < 86400:
hours = int(age / 3600)
return f"{hours}hr ago"
elif age < 2678400:
days = int(age / 86400)
return f"{days}d ago"
now = time.gmtime()
ctd = time.gmtime(self.created_utc)
months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year)
if now.tm_mday < ctd.tm_mday:
months -= 1
if months < 12:
return f"{months}mo ago"
else:
years = int(months / 12)
return f"{years}yr ago"
@property @property
@lazy @lazy
def string(self): def string(self):
output = ACTIONTYPES[self.kind]["str"].format(self=self, cc=CC_TITLE) output = ACTIONTYPES[self.kind]["str"].format(self=self, cc=CC_TITLE)
if self._note: output += f" <i>({self._note})</i>" if self._note: output += f" <i>({self._note})</i>"
return output return output
@property @property

View File

@ -9,6 +9,7 @@ from files.__main__ import Base
from files.helpers.const import * from files.helpers.const import *
from files.helpers.regex import * from files.helpers.regex import *
from files.helpers.lazy import lazy from files.helpers.lazy import lazy
from files.helpers.sorting_and_time import make_age_string
from .flags import Flag from .flags import Flag
from .comment import Comment, normalize_urls_runtime from .comment import Comment, normalize_urls_runtime
from .saves import SaveRelationship from .saves import SaveRelationship
@ -100,64 +101,12 @@ class Submission(Base):
@property @property
@lazy @lazy
def age_string(self): def age_string(self):
return make_age_string(self.created_utc)
age = int(time.time()) - self.created_utc
if age < 60:
return "just now"
elif age < 3600:
minutes = int(age / 60)
return f"{minutes}m ago"
elif age < 86400:
hours = int(age / 3600)
return f"{hours}hr ago"
elif age < 2678400:
days = int(age / 86400)
return f"{days}d ago"
now = time.gmtime()
ctd = time.gmtime(self.created_utc)
months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year)
if now.tm_mday < ctd.tm_mday:
months -= 1
if months < 12:
return f"{months}mo ago"
else:
years = int(months / 12)
return f"{years}yr ago"
@property @property
@lazy @lazy
def edited_string(self): def edited_string(self):
return make_age_string(self.edited_utc)
age = int(time.time()) - self.edited_utc
if age < 60:
return "just now"
elif age < 3600:
minutes = int(age / 60)
return f"{minutes}m ago"
elif age < 86400:
hours = int(age / 3600)
return f"{hours}hr ago"
elif age < 2678400:
days = int(age / 86400)
return f"{days}d ago"
now = time.gmtime()
ctd = time.gmtime(self.edited_utc)
months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year)
if now.tm_mday < ctd.tm_mday:
months -= 1
if months < 12:
return f"{months}mo ago"
else:
years = int(months / 12)
return f"{years}yr ago"
@property @property
@lazy @lazy

View File

@ -815,7 +815,7 @@ class User(Base):
def ban(self, admin=None, reason=None, days=0): def ban(self, admin=None, reason=None, days=0.0):
if days: if days:
self.unban_utc = int(time.time()) + (days * 86400) self.unban_utc = int(time.time()) + (days * 86400)
g.db.add(self) g.db.add(self)

View File

@ -4,6 +4,8 @@ from files.__main__ import Base
from files.helpers.lazy import * from files.helpers.lazy import *
import time import time
from files.helpers.sorting_and_time import make_age_string
class ViewerRelationship(Base): class ViewerRelationship(Base):
__tablename__ = "viewers" __tablename__ = "viewers"
@ -26,36 +28,9 @@ class ViewerRelationship(Base):
@property @property
@lazy @lazy
def last_view_since(self): def last_view_since(self):
return int(time.time()) - self.last_view_utc return int(time.time()) - self.last_view_utc
@property @property
@lazy @lazy
def last_view_string(self): def last_view_string(self):
return make_age_string(self.last_view_since)
age = self.last_view_since
if age < 60:
return "just now"
elif age < 3600:
minutes = int(age / 60)
return f"{minutes}m ago"
elif age < 86400:
hours = int(age / 3600)
return f"{hours}hr ago"
elif age < 2678400:
days = int(age / 86400)
return f"{days}d ago"
now = time.gmtime()
ctd = time.gmtime(self.last_view_utc)
months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year)
if now.tm_mday < ctd.tm_mday:
months -= 1
if months < 12:
return f"{months}mo ago"
else:
years = int(months / 12)
return f"{years}yr ago"

View File

@ -62,6 +62,7 @@ def execute_snappy(post, v):
else: SNAPPY_CHOICES = SNAPPY_QUOTES else: SNAPPY_CHOICES = SNAPPY_QUOTES
elif SNAPPY_MARSEYS: SNAPPY_CHOICES = SNAPPY_MARSEYS elif SNAPPY_MARSEYS: SNAPPY_CHOICES = SNAPPY_MARSEYS
elif SNAPPY_QUOTES: SNAPPY_CHOICES = SNAPPY_QUOTES elif SNAPPY_QUOTES: SNAPPY_CHOICES = SNAPPY_QUOTES
else: SNAPPY_CHOICES = [""]
body = random.choice(SNAPPY_CHOICES).strip() body = random.choice(SNAPPY_CHOICES).strip()
if body.startswith(''): if body.startswith(''):

View File

@ -29,34 +29,7 @@ def template_asset_siteimg(asset_path):
@app.template_filter("timestamp") @app.template_filter("timestamp")
def timestamp(timestamp): def timestamp(timestamp):
return make_age_string(timestamp)
age = int(time.time()) - timestamp
if age < 60:
return "just now"
elif age < 3600:
minutes = int(age / 60)
return f"{minutes}m ago"
elif age < 86400:
hours = int(age / 3600)
return f"{hours}hr ago"
elif age < 2678400:
days = int(age / 86400)
return f"{days}d ago"
now = time.gmtime()
ctd = time.gmtime(timestamp)
months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year)
if now.tm_mday < ctd.tm_mday:
months -= 1
if months < 12:
return f"{months}mo ago"
else:
years = int(months / 12)
return f"{years}yr ago"
@app.context_processor @app.context_processor
def inject_constants(): def inject_constants():

View File

@ -1,4 +1,5 @@
import time import time
from typing import Optional
from files.helpers.const import * from files.helpers.const import *
from sqlalchemy.sql import func from sqlalchemy.sql import func
@ -44,3 +45,30 @@ def sort_objects(sort, objects, cls, include_shadowbanned=False):
return objects.order_by(cls.upvotes - cls.downvotes, cls.created_utc.desc()) return objects.order_by(cls.upvotes - cls.downvotes, cls.created_utc.desc())
else: else:
return objects.order_by(cls.downvotes - cls.upvotes, cls.created_utc.desc()) return objects.order_by(cls.downvotes - cls.upvotes, cls.created_utc.desc())
def make_age_string(compare:Optional[int]) -> str:
if not compare or compare < 1577865600: return ""
age = int(time.time()) - compare
if age < 60:
return "just now"
elif age < 3600:
minutes = int(age / 60)
return f"{minutes}m ago"
elif age < 86400:
hours = int(age / 3600)
return f"{hours}hr ago"
elif age < 2678400:
days = int(age / 86400)
return f"{days}d ago"
now = time.gmtime()
ctd = time.gmtime(compare)
months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year)
if now.tm_mday < ctd.tm_mday:
months -= 1
if months < 12:
return f"{months}mo ago"
else:
years = int(months / 12)
return f"{years}yr ago"

View File

@ -993,7 +993,11 @@ def ban_user(user_id, v):
if user.admin_level > v.admin_level: if user.admin_level > v.admin_level:
abort(403) abort(403)
days = float(request.values.get("days")) if request.values.get('days') else 0 days = 0.0
try:
days = float(request.values.get("days"))
except:
pass
reason = request.values.get("reason").strip()[:256] reason = request.values.get("reason").strip()[:256]
reason = filter_emojis_only(reason) reason = filter_emojis_only(reason)
@ -1009,8 +1013,11 @@ def ban_user(user_id, v):
continue continue
x.ban(admin=v, reason=reason, days=days) x.ban(admin=v, reason=reason, days=days)
duration = "permanently"
if days: if days:
days_txt = str(days).rstrip('.0') days_txt = str(days).rstrip('.0')
duration = f"for {days_txt} day"
if days != 1: duration += "s"
if reason: text = f"@{v.username} (Admin) has banned you for **{days_txt}** days for the following reason:\n\n> {reason}" if reason: text = f"@{v.username} (Admin) has banned you for **{days_txt}** days for the following reason:\n\n> {reason}"
else: text = f"@{v.username} (Admin) has banned you for **{days_txt}** days." else: text = f"@{v.username} (Admin) has banned you for **{days_txt}** days."
else: else:
@ -1018,10 +1025,6 @@ def ban_user(user_id, v):
else: text = f"@{v.username} (Admin) has banned you permanently." else: text = f"@{v.username} (Admin) has banned you permanently."
send_repeatable_notification(user.id, text) send_repeatable_notification(user.id, text)
if days == 0: duration = "permanently"
elif days == 1: duration = "for 1 day"
else: duration = f"for {days_txt} days"
note = f'reason: "{reason}", duration: {duration}' note = f'reason: "{reason}", duration: {duration}'
ma=ModAction( ma=ModAction(

View File

@ -21,7 +21,7 @@ def login_get(v):
return render_template("login.html", failed=False, redirect=redir) return render_template("login.html", failed=False, redirect=redir)
def check_for_alts(current): def check_for_alts(current:User):
current_id = current.id current_id = current.id
if current_id in (1691,6790,7069,36152): if current_id in (1691,6790,7069,36152):
session["history"] = [] session["history"] = []
@ -29,8 +29,15 @@ def check_for_alts(current):
ids = [x[0] for x in g.db.query(User.id).all()] ids = [x[0] for x in g.db.query(User.id).all()]
past_accs = set(session.get("history", [])) past_accs = set(session.get("history", []))
def add_alt(user1:int, user2:int):
li = [user1, user2]
existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).one_or_none()
if not existing:
new_alt = Alt(user1=user1, user2=user2)
g.db.add(new_alt)
g.db.flush()
for past_id in list(past_accs): for past_id in list(past_accs):
if past_id not in ids: if past_id not in ids:
past_accs.remove(past_id) past_accs.remove(past_id)
continue continue
@ -39,46 +46,17 @@ def check_for_alts(current):
if past_id == current_id: continue if past_id == current_id: continue
li = [past_id, current_id] li = [past_id, current_id]
existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).one_or_none() add_alt(past_id, current_id)
other_alts = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).all()
if not existing: for a in other_alts:
new_alt = Alt(user1=past_id, user2=current_id)
g.db.add(new_alt)
g.db.flush()
otheralts = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).all()
for a in otheralts:
if a.user1 != past_id: if a.user1 != past_id:
li = [a.user1, past_id] add_alt(a.user1, past_id)
existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).one_or_none()
if not existing:
new_alt = Alt(user1=a.user1, user2=past_id)
g.db.add(new_alt)
g.db.flush()
if a.user1 != current_id: if a.user1 != current_id:
li = [a.user1, current_id] add_alt(a.user1, current_id)
existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).one_or_none()
if not existing:
new_alt = Alt(user1=a.user1, user2=current_id)
g.db.add(new_alt)
g.db.flush()
if a.user2 != past_id: if a.user2 != past_id:
li = [a.user2, past_id] add_alt(a.user2, past_id)
existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).one_or_none()
if not existing:
new_alt = Alt(user1=a.user2, user2=past_id)
g.db.add(new_alt)
g.db.flush()
if a.user2 != current_id: if a.user2 != current_id:
li = [a.user2, current_id] add_alt(a.user2, current_id)
existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).one_or_none()
if not existing:
new_alt = Alt(user1=a.user2, user2=current_id)
g.db.add(new_alt)
g.db.flush()
past_accs.add(current_id) past_accs.add(current_id)
session["history"] = list(past_accs) session["history"] = list(past_accs)

View File

@ -843,8 +843,8 @@ def submit_post(v, sub=None):
if len(url) > 2048: if len(url) > 2048:
return error("There's a 2048 character limit for URLs.") return error("There's a 2048 character limit for URLs.")
bets = []
if v and v.admin_level >= PERMS['POST_BETS']: if v and v.admin_level >= PERMS['POST_BETS']:
bets = []
for i in bet_regex.finditer(body): for i in bet_regex.finditer(body):
bets.append(i.group(1)) bets.append(i.group(1))
body = body.replace(i.group(0), "") body = body.replace(i.group(0), "")

View File

@ -11,9 +11,7 @@ from files.helpers.sanitize import filter_emojis_only
@limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}') @limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}')
@auth_required @auth_required
def flag_post(pid, v): def flag_post(pid, v):
post = get_post(pid) post = get_post(pid)
reason = request.values.get("reason", "").strip() reason = request.values.get("reason", "").strip()
if blackjack and any(i in reason.lower() for i in blackjack.split()): if blackjack and any(i in reason.lower() for i in blackjack.split()):