From b1dee92e9def63346043c9c8233e5020a5a5a502 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 26 Nov 2021 21:56:20 +0200 Subject: [PATCH] fdsfds --- files/classes/flags.py | 11 +++++++++- files/helpers/const.py | 2 +- files/routes/users.py | 20 ++++++++++++++++++ files/templates/comments.html | 2 +- files/templates/most_downvoted.html | 28 +++++++++++++++++++++++++ files/templates/submission.html | 2 +- files/templates/submission_listing.html | 2 +- 7 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 files/templates/most_downvoted.html diff --git a/files/classes/flags.py b/files/classes/flags.py index 476ea9760..e719c403c 100644 --- a/files/classes/flags.py +++ b/files/classes/flags.py @@ -2,6 +2,7 @@ from sqlalchemy import * from sqlalchemy.orm import relationship from files.__main__ import Base from files.helpers.lazy import lazy +from files.helpers.const import censor_slurs import time class Flag(Base): @@ -29,6 +30,10 @@ class Flag(Base): def created_datetime(self): return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))) + @lazy + def realreason(self, v): + return censor_slurs(self.reason, v) + class CommentFlag(Base): @@ -53,4 +58,8 @@ class CommentFlag(Base): @property @lazy def created_datetime(self): - return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))) \ No newline at end of file + return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))) + + @lazy + def realreason(self, v): + return censor_slurs(self.reason, v) \ No newline at end of file diff --git a/files/helpers/const.py b/files/helpers/const.py index 41afaa0f6..e68eb5e0f 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -180,7 +180,7 @@ PUSHER_INSTANCE_ID = '02ddcc80-b8db-42be-9022-44c546b4dce6' PUSHER_KEY = environ.get("PUSHER_KEY", "").strip() single_words = "|".join([slur.lower() for slur in SLURS.keys()]) -SLUR_REGEX = re.compile(rf"(?i)((?<=\s|>)|^)(nigger)((?=[\s<,.]|s[\s<,.])|$)") +SLUR_REGEX = re.compile(rf"(?i)((?<=\s|>)|^)({single_words})((?=[\s<,.]|s[\s<,.])|$)") def sub_matcher(match: re.Match) -> str: return SLURS[match.group(0).lower()] diff --git a/files/routes/users.py b/files/routes/users.py index 284240d50..057cbebd3 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -17,6 +17,26 @@ site = environ.get("DOMAIN").strip() beams_client = PushNotifications(instance_id=PUSHER_INSTANCE_ID, secret_key=PUSHER_KEY) + + +@app.get("/most_downvoted") +@auth_desired +def most_downvoted(v): + votes = g.db.query(Submission.author_id, func.count(Submission.author_id)).join(Vote, Vote.submission_id==Submission.id).filter(Vote.vote_type==-1).group_by(Submission.author_id).order_by(func.count(Submission.author_id).desc()).limit(25).all() + + votes2 = g.db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote, CommentVote.comment_id==Comment.id).filter(CommentVote.vote_type==-1).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).limit(25).all() + + votes = Counter(dict(votes)) + Counter(dict(votes2)) + + users = g.db.query(User).filter(User.id.in_(votes.keys())).all() + users2 = [] + for user in users: users2.append((user, votes[user.id])) + + users = sorted(users2, key=lambda x: x[1], reverse=True)[:25] + + return render_template("most_downvoted.html", v=v, users=users) + + @app.get("/@/upvoters") @auth_desired def upvoters(v, username): diff --git a/files/templates/comments.html b/files/templates/comments.html index 9b33b7aba..b8241d999 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -319,7 +319,7 @@

 				
 			
diff --git a/files/templates/most_downvoted.html b/files/templates/most_downvoted.html
new file mode 100644
index 000000000..b419f1460
--- /dev/null
+++ b/files/templates/most_downvoted.html
@@ -0,0 +1,28 @@
+{% extends "default.html" %}
+{% block content %}
+
+
+	
+
+
Most downvoted users
+

+
+
+	
+		
+		
+		
+	
+
+
+{% for user in users %}
+	
+		
+		
+		
+	
+{% endfor %}
+
+
#NameDownvotes
{{loop.index}}{{user[0].username}}{{user[1]}}
+ +{% endblock %} \ No newline at end of file diff --git a/files/templates/submission.html b/files/templates/submission.html index a7014db0d..0613a3028 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -459,7 +459,7 @@

 						
 					
diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html
index fcabdb7d2..7beca6c03 100644
--- a/files/templates/submission_listing.html
+++ b/files/templates/submission_listing.html
@@ -125,7 +125,7 @@