]> git.lizzy.rs Git - cheatdb.git/commitdiff
Increase thread/comment ratelimiting based on rank
authorrubenwardy <rw@rubenwardy.com>
Tue, 18 Aug 2020 17:10:42 +0000 (18:10 +0100)
committerrubenwardy <rw@rubenwardy.com>
Tue, 18 Aug 2020 17:10:42 +0000 (18:10 +0100)
app/models.py
app/tasks/minetestcheck/tree.py

index 568981a427075d4089a797a142252ac9c566621e..4c0ccc348fe08c442ff00b75530570f390cd89f7 100644 (file)
@@ -222,22 +222,34 @@ class User(db.Model, UserMixin):
                        raise Exception("Permission {} is not related to users".format(perm.name))
 
        def canCommentRL(self):
+               factor = 1
+               if self.rank.atLeast(UserRank.ADMIN):
+                       return True
+               elif self.rank.atLeast(UserRank.TRUSTED_MEMBER):
+                       factor *= 2
+
                one_min_ago = datetime.datetime.utcnow() - datetime.timedelta(minutes=1)
                if ThreadReply.query.filter_by(author=self) \
-                               .filter(ThreadReply.created_at > one_min_ago).count() >= 3:
+                               .filter(ThreadReply.created_at > one_min_ago).count() >= 3 * factor:
                        return False
 
                hour_ago = datetime.datetime.utcnow() - datetime.timedelta(hours=1)
                if ThreadReply.query.filter_by(author=self) \
-                               .filter(ThreadReply.created_at > hour_ago).count() >= 20:
+                               .filter(ThreadReply.created_at > hour_ago).count() >= 20 * factor:
                        return False
 
                return True
 
        def canOpenThreadRL(self):
+               factor = 1
+               if self.rank.atLeast(UserRank.ADMIN):
+                       return True
+               elif self.rank.atLeast(UserRank.TRUSTED_MEMBER):
+                       factor *= 5
+
                hour_ago = datetime.datetime.utcnow() - datetime.timedelta(hours=1)
                return Thread.query.filter_by(author=self) \
-                       .filter(Thread.created_at > hour_ago).count() < 2
+                       .filter(Thread.created_at > hour_ago).count() < 2 * factor
 
        def __eq__(self, other):
                if other is None:
index 07e67f68261600d96beafca9dbefedfc57016e47..57a769f6297e66aa9a0c557f9277b2dcbaa95cb8 100644 (file)
@@ -128,17 +128,20 @@ class PackageTreeNode:
                        result["optional_depends"] = []
 
 
-               # Check dependencies
-               for dep in result["depends"]:
-                       if not basenamePattern.match(dep):
-                               raise MinetestCheckError(("Invalid dependency name '{}' for mod at {}, names must only contain a-z0-9_.") \
-                                       .format(dep, self.relative))
+               def checkDependencies(deps):
+                       for dep in result["depends"]:
+                               if not basenamePattern.match(dep):
+                                       if " " in dep:
+                                               raise MinetestCheckError(("Invalid dependency name '{}' for mod at {}, did you forget a comma?") \
+                                                       .format(dep, self.relative))
+                                       else:
+                                               raise MinetestCheckError(("Invalid dependency name '{}' for mod at {}, names must only contain a-z0-9_.") \
+                                                       .format(dep, self.relative))
 
-               for dep in result["optional_depends"]:
-                       if not basenamePattern.match(dep):
-                               raise MinetestCheckError(("Invalid dependency name '{}' for mod at {}, names must only contain a-z0-9_.") \
-                                       .format(dep, self.relative))
 
+               # Check dependencies
+               checkDependencies(result["depends"])
+               checkDependencies(result["optional_depends"])
 
                # Fix games using "name" as "title"
                if self.type == ContentType.GAME: