From de3b2fc3fbfecde4a922ef4789d000b261b61bf1 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 14 Dec 2021 23:08:18 +0200 Subject: [PATCH 1/2] fsd --- files/classes/user.py | 10 ++-- files/helpers/const.py | 47 +++++++++++++++++ files/routes/awards.py | 111 +++++++++++++++++++++++++++++++++++++++ files/routes/settings.py | 12 +++-- 4 files changed, 173 insertions(+), 7 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 5e702d067..b5cca7bb9 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -83,6 +83,8 @@ class User(Base): oldreddit = Column(Boolean, default=True) teddit = Column(Boolean) nitter = Column(Boolean) + grinch = Column(Boolean) + grincheffect = Column(Boolean) mute = Column(Boolean) unmutable = Column(Boolean) eye = Column(Boolean) @@ -281,6 +283,7 @@ class User(Base): if not self.is_suspended: return None return g.db.query(User).filter_by(id=self.is_banned).first() + @lazy def has_badge(self, badge_id): return g.db.query(Badge).filter_by(user_id=self.id, badge_id=badge_id).first() @@ -413,14 +416,15 @@ class User(Base): @lazy def banner_url(self): if self.bannerurl: return self.bannerurl - else: return f"https://{site}/assets/images/{site_name}/preview.webp?v=190" + else: return f"https://{site}/assets/images/{site_name}/preview.webp?v=200" @property @lazy def profile_url(self): - if self.agendaposter: return f"https://{site}/assets/images/defaultpictures/agendaposter/{random.randint(1, 50)}.webp?v=190" + if self.grincheffect: return f"https://{site}/assets/images/grinch.webp?v=200" + if self.agendaposter: return f"https://{site}/assets/images/defaultpictures/agendaposter/{random.randint(1, 50)}.webp?v=200" if self.profileurl: return self.profileurl - if "rama" in site: return f"https://{site}/assets/images/defaultpictures/{random.randint(1, 150)}.webp?v=190" + if "rama" in site: return f"https://{site}/assets/images/defaultpictures/{random.randint(1, 150)}.webp?v=200" return f"https://{site}/assets/images/default-profile-pic.webp" @property diff --git a/files/helpers/const.py b/files/helpers/const.py index 15cfd1e5d..b6160f26c 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -674,6 +674,53 @@ AWARDS = { } AWARDS2 = { + "snow": { + "kind": "snow", + "title": "Snow", + "description": "???", + "icon": "fas fa-snowflake", + "color": "text-blue-200", + "price": 300 + }, + "gingerbread": { + "kind": "gingerbread", + "title": "Gingerbread", + "description": "???", + "icon": "fas fa-gingerbread-man", + "color": "", + "price": 300 + }, + "lights": { + "kind": "lights", + "title": "Lights", + "description": "???", + "icon": "fad fa-lights-holiday", + "color": "", + "price": 300 + }, + "candycane": { + "kind": "candycane", + "title": "Candy Cane", + "description": "???", + "icon": "fad fa-candy-cane", + "color": "", + "price": 400 + }, + "fireplace": { + "kind": "fireplace", + "title": "Fireplace", + "description": "???", + "icon": "fad fa-fireplace", + "color": "", + "price": 600 + }, + "grinch": { + "kind": "grinch", + "title": "Grinch", + "description": "???", + "icon": "fas fa-angry", + "color": "text-green-500", + }, "lootbox": { "kind": "lootbox", "title": "Lootstocking", diff --git a/files/routes/awards.py b/files/routes/awards.py index 63fb8563c..5dc02abb7 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -48,6 +48,58 @@ AWARDS3 = { @auth_required def shop(v): AWARDS = { + "snow": { + "kind": "snow", + "title": "Snow", + "description": "???", + "icon": "fas fa-snowflake", + "color": "text-blue-200", + "owned": 0, + "price": 300 + }, + "gingerbread": { + "kind": "gingerbread", + "title": "Gingerbread", + "description": "???", + "icon": "fas fa-gingerbread-man", + "color": "", + "owned": 0, + "price": 300 + }, + "lights": { + "kind": "lights", + "title": "Lights", + "description": "???", + "icon": "fad fa-lights-holiday", + "color": "", + "owned": 0, + "price": 300 + }, + "candycane": { + "kind": "candycane", + "title": "Candy Cane", + "description": "???", + "icon": "fad fa-candy-cane", + "color": "", + "owned": 0, + "price": 400 + }, + "fireplace": { + "kind": "fireplace", + "title": "Fireplace", + "description": "???", + "icon": "fad fa-fireplace", + "color": "", + "owned": 0, + "price": 600 + }, + "grinch": { + "kind": "grinch", + "title": "Grinch", + "description": "???", + "icon": "fas fa-angry", + "color": "text-green-500", + }, "lootbox": { "kind": "lootbox", "title": "Lootstocking", @@ -255,6 +307,53 @@ def shop(v): @validate_formkey def buy(v, award): AWARDS = { + "snow": { + "kind": "snow", + "title": "Snow", + "description": "???", + "icon": "fas fa-snowflake", + "color": "text-blue-200", + "price": 300 + }, + "gingerbread": { + "kind": "gingerbread", + "title": "Gingerbread", + "description": "???", + "icon": "fas fa-gingerbread-man", + "color": "", + "price": 300 + }, + "lights": { + "kind": "lights", + "title": "Lights", + "description": "???", + "icon": "fad fa-lights-holiday", + "color": "", + "price": 300 + }, + "candycane": { + "kind": "candycane", + "title": "Candy Cane", + "description": "???", + "icon": "fad fa-candy-cane", + "color": "", + "price": 400 + }, + "fireplace": { + "kind": "fireplace", + "title": "Fireplace", + "description": "???", + "icon": "fad fa-fireplace", + "color": "", + "price": 600 + }, + "grinch": { + "kind": "grinch", + "title": "Grinch", + "description": "???", + "icon": "fas fa-angry", + "color": "text-green-500", + }, "lootbox": { "kind": "lootbox", "title": "Lootstocking", @@ -645,6 +744,12 @@ def award_post(pid, v): if not author.has_badge(90): new_badge = Badge(badge_id=90, user_id=author.id) g.db.add(new_badge) + elif kind == "grinch": + author.grinch = True + send_notification(CARP_ID, f"@{v.username} used {kind} award!") + if not author.has_badge(91): + new_badge = Badge(badge_id=91, user_id=author.id) + g.db.add(new_badge) if post.author.received_award_count: post.author.received_award_count += 1 else: post.author.received_award_count = 1 @@ -807,6 +912,12 @@ def award_comment(cid, v): if not author.has_badge(90): new_badge = Badge(badge_id=90, user_id=author.id) g.db.add(new_badge) + elif kind == "grinch": + author.grinch = True + send_notification(CARP_ID, f"@{v.username} used {kind} award!") + if not author.has_badge(91): + new_badge = Badge(badge_id=91, user_id=author.id) + g.db.add(new_badge) if c.author.received_award_count: c.author.received_award_count += 1 else: c.author.received_award_count = 1 diff --git a/files/routes/settings.py b/files/routes/settings.py index e06e7520c..348fa4504 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -52,7 +52,11 @@ def settings_profile_post(v): updated = False - if request.values.get("background", v.background) != v.background: + if request.values.get("grincheffect", v.grincheffect) != v.grincheffect: + updated = True + v.grincheffect = request.values.get("grincheffect", None) == 'true' + + elif request.values.get("background", v.background) != v.background: updated = True v.background = request.values.get("background", None) @@ -732,8 +736,8 @@ def settings_images_profile(v): if not imageurl: abort(400) - if v.highres and '/images/' in v.highres : os.remove('images/' + v.highres.split('/images/')[1]) - if v.profileurl and '/images/' in v.profileurl : os.remove('images/' + v.profileurl.split('/images/')[1]) + if v.highres and '/images/' in v.highres : os.remove('/images/' + v.highres.split('/images/')[1]) + if v.profileurl and '/images/' in v.profileurl : os.remove('/images/' + v.profileurl.split('/images/')[1]) v.highres = highres v.profileurl = imageurl g.db.add(v) @@ -761,7 +765,7 @@ def settings_images_banner(v): bannerurl = process_image(name) if bannerurl: - if v.bannerurl and '/images/' in v.bannerurl : os.remove('images/' + v.bannerurl.split('/images/')[1]) + if v.bannerurl and '/images/' in v.bannerurl : os.remove('/images/' + v.bannerurl.split('/images/')[1]) v.bannerurl = bannerurl g.db.add(v) g.db.commit() From 3f0ef520fc163fe07d0e8cd555dcab75a350d7e2 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 14 Dec 2021 23:32:58 +0200 Subject: [PATCH 2/2] sdfsdf --- files/__main__.py | 2 +- files/helpers/sanitize.py | 10 +++++----- files/routes/admin.py | 12 ++++++------ files/routes/login.py | 4 ++-- files/routes/static.py | 18 ++++++++++++------ files/templates/{marseys.html => emojis.html} | 8 ++++---- 6 files changed, 30 insertions(+), 24 deletions(-) rename files/templates/{marseys.html => emojis.html} (56%) diff --git a/files/__main__.py b/files/__main__.py index 4fcb842e6..cf27ec39c 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -16,7 +16,7 @@ import gevent from werkzeug.middleware.proxy_fix import ProxyFix import redis -app = Flask(__name__, template_folder='./templates') +app = Flask(__name__, template_folder='templates') app.wsgi_app = ProxyFix(app.wsgi_app, x_for=3) app.url_map.strict_slashes = False app.jinja_env.cache = {} diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 59cdfed8c..dd391d48c 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -182,7 +182,7 @@ def sanitize(sanitized, noimages=False): classes = 'height=60 class="emoji" ' remoji = emoji - if path.isfile(f'./files/assets/images/emojis/{remoji}.webp'): + if path.isfile(f'files/assets/images/emojis/{remoji}.webp'): new = re.sub(f'(?', new, flags=re.I) sanitized = sanitized.replace(old, new) @@ -192,10 +192,10 @@ def sanitize(sanitized, noimages=False): emoji = i.group(1).lower() if emoji.startswith("!"): emoji = emoji[1:] - if path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): + if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): sanitized = re.sub(f'(?', sanitized, flags=re.I) - elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): + elif path.isfile(f'files/assets/images/emojis/{emoji}.webp'): sanitized = re.sub(f'(?', sanitized, flags=re.I) sanitized = sanitized.replace("https://www.", "https://").replace("https://youtu.be/", "https://youtube.com/watch?v=").replace("https://music.youtube.com/watch?v=", "https://youtube.com/watch?v=").replace("https://open.spotify.com/", "https://open.spotify.com/embed/").replace("https://streamable.com/", "https://streamable.com/e/").replace("https://youtube.com/shorts/", "https://youtube.com/watch?v=").replace("https://mobile.twitter", "https://twitter").replace("https://m.facebook", "https://facebook").replace("https://m.wikipedia", "https://wikipedia").replace("https://m.youtube", "https://youtube") @@ -239,10 +239,10 @@ def filter_emojis_only(title): if emoji.startswith("!"): emoji = emoji[1:] - if path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): + if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): title = re.sub(f'(?', title, flags=re.I) - elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): + elif path.isfile(f'files/assets/images/emojis/{emoji}.webp'): title = re.sub(f'(?', title, flags=re.I) if len(title) > 1500: abort(400) diff --git a/files/routes/admin.py b/files/routes/admin.py index 4c4c2050f..cafa8d9ce 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -204,7 +204,7 @@ def monthly(v): def get_rules(v): try: - with open(f'./rules_{SITE_NAME}.html', 'r') as f: rules = f.read() + with open(f'rules_{SITE_NAME}.html', 'r') as f: rules = f.read() except Exception: rules = None @@ -219,9 +219,9 @@ def post_rules(v): text = request.values.get('rules', '').strip() - with open(f'./rules_{SITE_NAME}.html', 'w+') as f: f.write(text) + with open(f'rules_{SITE_NAME}.html', 'w+') as f: f.write(text) - with open(f'./rules_{SITE_NAME}.html', 'r') as f: rules = f.read() + with open(f'rules_{SITE_NAME}.html', 'r') as f: rules = f.read() ma = ModAction( kind="change_rules", @@ -317,7 +317,7 @@ def reported_comments(v): @app.get("/admin") @admin_level_required(2) def admin_home(v): - with open('./disablesignups', 'r') as f: + with open('disablesignups', 'r') as f: x = f.read() return render_template("admin/admin_home.html", v=v, x=x) @@ -325,9 +325,9 @@ def admin_home(v): @admin_level_required(2) @validate_formkey def disablesignups(v): - with open('./disablesignups', 'r') as f: content = f.read() + with open('disablesignups', 'r') as f: content = f.read() - with open('./disablesignups', 'w') as f: + with open('disablesignups', 'w') as f: if content == "yes": f.write("no") return {"message": "Signups enabed!"} diff --git a/files/routes/login.py b/files/routes/login.py index 547381366..3a7bdf41a 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -169,7 +169,7 @@ def logout(v): @app.get("/signup") @auth_desired def sign_up_get(v): - with open('./disablesignups', 'r') as f: + with open('disablesignups', 'r') as f: if f.read() == "yes": return "New account registration is currently closed. Please come back later.", 403 if v: return redirect("/") @@ -217,7 +217,7 @@ def sign_up_get(v): @limiter.limit("5/day") @auth_desired def sign_up_post(v): - with open('./disablesignups', 'r') as f: + with open('disablesignups', 'r') as f: if f.read() == "yes": return "New account registration is currently closed. Please come back later.", 403 if v: abort(403) diff --git a/files/routes/static.py b/files/routes/static.py index 71d9db856..754b3f833 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -12,17 +12,23 @@ from files.classes.mod_logs import ACTIONTYPES, ACTIONTYPES2 site = environ.get("DOMAIN").strip() site_name = environ.get("SITE_NAME").strip() +@app.get("/emojis") +@auth_desired +def emojis(v): + emojis = (x.replace('.webp','') for x in os.listdir("files/assets/images/emojis")) + return render_template("emojis.html", v=v, emojis=emojis) + @app.get('/rules') @auth_desired def static_rules(v): - if not path.exists(f'./rules_{site_name}.html'): + if not path.exists(f'rules_{site_name}.html'): if v and v.admin_level > 1: return render_template('norules.html', v=v) else: abort(404) - with open(f'./rules_{site_name}.html', 'r') as f: + with open(f'rules_{site_name}.html', 'r') as f: rules = f.read() return render_template('rules.html', rules=rules, v=v) @@ -69,7 +75,7 @@ def participation_stats(v): @auth_required def chart(v): file = cached_chart() - return send_file(f"../{file}") + return send_file(f".{file}") @cache.memoize(timeout=86400) @@ -212,7 +218,7 @@ def log_item(id, v): @app.get("/assets/favicon.ico") def favicon(): - return send_file(f"./assets/images/{site_name}/icon.webp?v=190") + return send_file(f"assets/images/{site_name}/icon.webp?v=190") @app.get("/api") @auth_desired @@ -250,7 +256,7 @@ def archives(path): @app.get('/assets/') @limiter.exempt def static_service(path): - resp = make_response(send_from_directory('./assets', path)) + resp = make_response(send_from_directory('assets', path)) if request.path.endswith('.webp') or request.path.endswith('.gif') or request.path.endswith('.ttf') or request.path.endswith('.woff') or request.path.endswith('.woff2'): resp.headers.remove("Cache-Control") resp.headers.add("Cache-Control", "public, max-age=2628000") @@ -275,7 +281,7 @@ def images(path): @app.get("/robots.txt") def robots_txt(): - return send_file("./assets/robots.txt") + return send_file("assets/robots.txt") @app.get("/settings") @auth_required diff --git a/files/templates/marseys.html b/files/templates/emojis.html similarity index 56% rename from files/templates/marseys.html rename to files/templates/emojis.html index 0cecf8967..bb7d2f409 100644 --- a/files/templates/marseys.html +++ b/files/templates/emojis.html @@ -9,15 +9,15 @@ # Name - Marsey + Emoji -{% for marsey in marseys %} +{% for emoji in emojis %} {{loop.index}} - {{marsey}} - :{{marsey}}: + {{emoji}} + :{{emoji}}: {% endfor %}