implement auto mod mechanism after 3 reports of the same reason over the span of a week

This commit is contained in:
Alan Moon 2025-02-11 13:37:11 -08:00
parent f58e4d643c
commit 299b9cc0ca
2 changed files with 37 additions and 1 deletions

View File

@ -7,6 +7,7 @@ using sodoff.Schema;
using sodoff.Util; using sodoff.Util;
using sodoff.Configuration; using sodoff.Configuration;
using sodoff.Services; using sodoff.Services;
using System.Linq.Expressions;
namespace sodoff.Controllers.Common; namespace sodoff.Controllers.Common;
@ -215,6 +216,41 @@ public class AuthenticationController : Controller {
return Unauthorized(); 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<Report> reportsType1 = moderationService.GetAllReportsReceivedFromViking(viking, 1);
List<Report> reportsType2 = moderationService.GetAllReportsReceivedFromViking(viking, 2);
List<Report> 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 // Create session
Session session = new Session { Session session = new Session {
Viking = viking, Viking = viking,

View File

@ -15,7 +15,7 @@ public class Report
public int ReportType { get; set; } public int ReportType { get; set; }
public DateTime? CreatedAt { get; set; } public DateTime CreatedAt { get; set; }
public virtual Viking? Viking { get; set; } public virtual Viking? Viking { get; set; }