diff --git a/files/__main__.py b/files/__main__.py index 58a6f5927..9628f0d13 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -65,11 +65,11 @@ app.config["HCAPTCHA_SITEKEY"] = environ.get("HCAPTCHA_SITEKEY","").strip() app.config["HCAPTCHA_SECRET"] = environ.get("HCAPTCHA_SECRET","").strip() # antispam configs -app.config["SPAM_SIMILARITY_THRESHOLD"] = float(environ.get("SPAM_SIMILARITY_THRESHOLD")) -app.config["SPAM_SIMILAR_COUNT_THRESHOLD"] = int(environ.get("SPAM_SIMILAR_COUNT_THRESHOLD")) -app.config["SPAM_URL_SIMILARITY_THRESHOLD"] = float(environ.get("SPAM_URL_SIMILARITY_THRESHOLD")) -app.config["COMMENT_SPAM_SIMILAR_THRESHOLD"] = float(environ.get("COMMENT_SPAM_SIMILAR_THRESHOLD")) -app.config["COMMENT_SPAM_COUNT_THRESHOLD"] = int(environ.get("COMMENT_SPAM_COUNT_THRESHOLD")) +app.config["SPAM_SIMILARITY_THRESHOLD"] = float(environ.get("SPAM_SIMILARITY_THRESHOLD", 0.5)) +app.config["SPAM_SIMILAR_COUNT_THRESHOLD"] = int(environ.get("SPAM_SIMILAR_COUNT_THRESHOLD", 5)) +app.config["SPAM_URL_SIMILARITY_THRESHOLD"] = float(environ.get("SPAM_URL_SIMILARITY_THRESHOLD", 0.5)) +app.config["COMMENT_SPAM_SIMILAR_THRESHOLD"] = float(environ.get("COMMENT_SPAM_SIMILAR_THRESHOLD", 0.5)) +app.config["COMMENT_SPAM_COUNT_THRESHOLD"] = int(environ.get("COMMENT_SPAM_COUNT_THRESHOLD", 0.5)) app.config["CACHE_REDIS_URL"] = environ.get("REDIS_URL").strip() app.config["CACHE_DEFAULT_TIMEOUT"] = 60 @@ -83,7 +83,7 @@ redispool=ConnectionPool( ) if app.config["CACHE_TYPE"]=="redis" else None app.config["CACHE_OPTIONS"]={'connection_pool':redispool} if app.config["CACHE_TYPE"]=="redis" else {} -app.config["READ_ONLY"]=bool(int(environ.get("READ_ONLY"))) +app.config["READ_ONLY"]=bool(int(environ.get("READ_ONLY", "0"))) app.config["BOT_DISABLE"]=bool(int(environ.get("BOT_DISABLE", False))) app.config["TENOR_KEY"]=environ.get("TENOR_KEY",'').strip() diff --git a/files/classes/user.py b/files/classes/user.py index 34bc29895..c5e3cbdce 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -7,6 +7,7 @@ from files.helpers.images import * from .alts import Alt from .submission import SaveRelationship from .comment import Notification +from .award import AwardRelationship from .subscriptions import * from .userblock import * from .badges import * @@ -314,6 +315,29 @@ class User(Base, Stndrd, Age_times): return sorted(list(awards.values()), key=lambda x: x['kind'], reverse=True) + @property + @lazy + def received_awards(self): + + awards = {} + + posts_idlist = g.db.query(Submission.id).filter_by(author_id=self.id).subquery() + comments_idlist = g.db.query(Comment.id).filter_by(author_id=self.id).subquery() + + post_awards = g.db.query(AwardRelationship).filter(AwardRelationship.submission_id.in_(posts_idlist)).all() + comment_awards = g.db.query(AwardRelationship).filter(AwardRelationship.comment_id.in_(comments_idlist)).all() + + total_awards = post_awards + comment_awards + + for a in total_awards: + if a.kind in awards: + awards[a.kind]['count'] += 1 + else: + awards[a.kind] = a.type + awards[a.kind]['count'] = 1 + + return sorted(list(awards.values()), key=lambda x: x['kind'], reverse=True) + @property @lazy def post_notifications_count(self): diff --git a/files/helpers/images.py b/files/helpers/images.py index 759947636..96d72681a 100644 --- a/files/helpers/images.py +++ b/files/helpers/images.py @@ -4,9 +4,9 @@ from PIL import Image as IImage, ImageSequence import base64 from files.classes.images import * -CF_KEY = environ.get("CLOUDFLARE_KEY").strip() -CF_ZONE = environ.get("CLOUDFLARE_ZONE").strip() -IMGUR_KEY = environ.get("IMGUR_KEY").strip() +CF_KEY = environ.get("CLOUDFLARE_KEY", "").strip() +CF_ZONE = environ.get("CLOUDFLARE_ZONE", "").strip() +IMGUR_KEY = environ.get("IMGUR_KEY", "").strip() def upload_file(file=None, resize=False, png=False): diff --git a/files/mail/mail.py b/files/mail/mail.py index 34953ae76..29e33af10 100644 --- a/files/mail/mail.py +++ b/files/mail/mail.py @@ -11,7 +11,7 @@ from files.__main__ import app site = environ.get("DOMAIN").strip() name = environ.get("SITE_NAME").strip() -mailgun_domain = environ.get("MAILGUN_DOMAIN").strip() +mailgun_domain = environ.get("MAILGUN_DOMAIN", "").strip() def send_mail(to_address, subject, html, plaintext=None, files={}, from_address=f"{name} "): diff --git a/files/routes/settings.py b/files/routes/settings.py index 62549a2f2..e03b46315 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -13,7 +13,7 @@ valid_username_regex = re.compile("^[a-zA-Z0-9_\-]{3,25}$") valid_title_regex = re.compile("^((?!<).){3,100}$") valid_password_regex = re.compile("^.{8,100}$") -YOUTUBE_KEY = environ.get("YOUTUBE_KEY").strip() +YOUTUBE_KEY = environ.get("YOUTUBE_KEY", "").strip() COINS_NAME = environ.get("COINS_NAME").strip() @app.post("/settings/profile") diff --git a/files/templates/userpage.html b/files/templates/userpage.html index b44fecbca..a319105dc 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -104,7 +104,7 @@
{% if u.is_suspended %}
BANNED USER{% if u.ban_reason %}: {{u.ban_reason}}{% endif %}
-
{{u.unban_string}}
+ {% if u.unban_utc %}
{{u.unban_string}}
{% endif %} {% endif %}
@@ -166,6 +166,18 @@ {% if u.bio_html and v %} {% endif %} + {% if u.received_awards %} +
+

Awards received

+ {% for a in u.received_awards %} + + + x{{ a['count'] }} + + {% endfor %} +
+ {% endif %} +
{% if v and v.id != u.id %} @@ -335,7 +347,7 @@
{% if u.is_suspended %}
BANNED USER{% if u.ban_reason %}: {{u.ban_reason}}{% endif %}
-
{{u.unban_string}}
+ {% if u.unban_utc %}
{{u.unban_string}}
{% endif %} {% endif %}

{{u.username}}

@@ -363,6 +375,19 @@ {% if u.bio_html %}

{{u.bio_html | safe}}

{% endif %} + + {% if u.received_awards %} +
+

Awards received

+ {% for a in u.received_awards %} + + + x{{ a['count'] }} + + {% endfor %} +
+ {% endif %} +
{% for b in u.badges %} {% if b.url %}