From: rubenwardy Date: Tue, 18 Aug 2020 17:10:42 +0000 (+0100) Subject: Increase thread/comment ratelimiting based on rank X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=e85d1755f058e661e451f0ab77401f820d0c836e;p=cheatdb.git Increase thread/comment ratelimiting based on rank --- diff --git a/app/models.py b/app/models.py index 568981a..4c0ccc3 100644 --- a/app/models.py +++ b/app/models.py @@ -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: diff --git a/app/tasks/minetestcheck/tree.py b/app/tasks/minetestcheck/tree.py index 07e67f6..57a769f 100644 --- a/app/tasks/minetestcheck/tree.py +++ b/app/tasks/minetestcheck/tree.py @@ -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: