make spam bans generate modlog items + dedup

pull/165/head
Aevann 2023-07-01 18:25:23 +03:00
parent 864a6ff321
commit eed7410277
2 changed files with 25 additions and 11 deletions

View File

@ -947,12 +947,14 @@ class User(Base):
def ban(self, admin=None, reason=None, days=0.0):
g.db.add(self)
if days:
if self.unban_utc:
self.unban_utc += days * 86400
else:
self.unban_utc = int(time.time()) + (days * 86400)
g.db.add(self)
else:
self.unban_utc = 0
self.is_banned = admin.id if admin else AUTOJANNY_ID
if reason and len(reason) <= 256:

View File

@ -363,6 +363,21 @@ def execute_longpostbot(c:Comment, level:int, body, body_html, post_target:post_
push_notif({v.id}, f'New reply by @{c2.author_name}', c2.body, c2)
def tempban_for_spam(v):
text = "Your account has been banned for **1 day** for the following reason:\n\n> Too much spam!"
send_repeatable_notification(v.id, text)
v.ban(reason="Spam", days=1)
ma=ModAction(
kind="ban_user",
user_id=AUTOJANNY_ID,
target_user_id=v.id,
_note=f'duration: for 1 day, reason: "Spam"'
)
g.db.add(ma)
def execute_antispam_post_check(title, v, url):
now = int(time.time())
cutoff = now - 60 * 60 * 24
@ -386,10 +401,7 @@ def execute_antispam_post_check(title, v, url):
elif v.age >= (60 * 60 * 24): threshold *= 2
if max(len(similar_urls), len(similar_posts)) >= threshold:
text = "Your account has been banned for **1 day** for the following reason:\n\n> Too much spam!"
send_repeatable_notification(v.id, text)
v.ban(reason="Spam", days=1)
tempban_for_spam(v)
for post in similar_posts + similar_urls:
post.is_banned = True
@ -420,9 +432,9 @@ def execute_antispam_duplicate_comment_check(v:User, body_html:str):
count = g.db.query(Comment.id).filter(Comment.body_html == body_html,
Comment.created_utc >= compare_time).count()
if count <= ANTISPAM_DUPLICATE_THRESHOLD: return
v.ban(reason="Spam", days=0.0)
send_repeatable_notification(v.id, "Your account has been banned **permanently** for the following reason:\n\n> Too much spam!")
g.db.add(v)
tempban_for_spam(v)
g.db.commit()
abort(403, "Too much spam!")
@ -447,9 +459,9 @@ def execute_antispam_comment_check(body:str, v:User):
threshold *= 2
if len(similar_comments) <= threshold: return
text = "Your account has been banned for **1 day** for the following reason:\n\n> Too much spam!"
send_repeatable_notification(v.id, text)
v.ban(reason="Spam", days=1)
tempban_for_spam(v)
for comment in similar_comments:
comment.is_banned = True
comment.ban_reason = "AutoJanny"