From 299b9cc0ca5ae830260e41c9539f384c218997c8 Mon Sep 17 00:00:00 2001 From: AlanMoonbase Date: Tue, 11 Feb 2025 13:37:11 -0800 Subject: [PATCH] implement auto mod mechanism after 3 reports of the same reason over the span of a week --- .../Common/AuthenticationController.cs | 36 +++++++++++++++++++ src/Model/Report.cs | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Controllers/Common/AuthenticationController.cs b/src/Controllers/Common/AuthenticationController.cs index 554cedc..4a055f2 100644 --- a/src/Controllers/Common/AuthenticationController.cs +++ b/src/Controllers/Common/AuthenticationController.cs @@ -7,6 +7,7 @@ using sodoff.Schema; using sodoff.Util; using sodoff.Configuration; using sodoff.Services; +using System.Linq.Expressions; namespace sodoff.Controllers.Common; @@ -215,6 +216,41 @@ public class AuthenticationController : Controller { return Unauthorized(); } + // check report amount, if more than 3 of the same report type are found and they are less than a week old, add ban + // TODO - this is complete dogshit, find a better way to do this + List reportsType1 = moderationService.GetAllReportsReceivedFromViking(viking, 1); + List reportsType2 = moderationService.GetAllReportsReceivedFromViking(viking, 2); + List reportsType3 = moderationService.GetAllReportsReceivedFromViking(viking, 3); + + var i1 = 0; + var i2 = 0; + var i3 = 0; + + foreach(var report in reportsType1) + { + if (DateTime.Compare(report.CreatedAt, DateTime.UtcNow) < 0) i1++; + } + + foreach(var report in reportsType2) + { + if (DateTime.Compare(report.CreatedAt, DateTime.UtcNow) < 0) i2++; + } + + foreach(var report in reportsType3) + { + if (DateTime.Compare(report.CreatedAt, DateTime.UtcNow) < 0) i3++; + } + + if (i1 > 3 || i2 > 3 || i3 > 3) + { + // add a one week ban to the user, clear report history, and disallow login + moderationService.AddBanToUser(viking.User, UserBanType.TemporarySuspension, DateTime.UtcNow.AddDays(7)); + viking.ReportsReceived.Clear(); + ctx.SaveChanges(); + + return Unauthorized(); + } + // Create session Session session = new Session { Viking = viking, diff --git a/src/Model/Report.cs b/src/Model/Report.cs index 1362836..70aa387 100644 --- a/src/Model/Report.cs +++ b/src/Model/Report.cs @@ -15,7 +15,7 @@ public class Report public int ReportType { get; set; } - public DateTime? CreatedAt { get; set; } + public DateTime CreatedAt { get; set; } public virtual Viking? Viking { get; set; }