mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-23 06:22:24 +01:00
Increase thread/comment ratelimiting based on rank
This commit is contained in:
parent
1c4fe1b80c
commit
e85d1755f0
@ -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:
|
||||
|
@ -128,17 +128,20 @@ class PackageTreeNode:
|
||||
result["optional_depends"] = []
|
||||
|
||||
|
||||
# Check dependencies
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user