mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 23:18:56 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
namespace RadicadeServer.Utils
|
||||
{
|
||||
public static class ModerationPolicy
|
||||
{
|
||||
public const string VoiceModerationBanMethod = "Voice Moderation";
|
||||
public const string AutomaticTimeoutBanMethod = "Automatic Timeout";
|
||||
public const string ModeratorReportBanMethod = "Moderator Report";
|
||||
public const string TimeoutBanMethod = "Timeout";
|
||||
|
||||
public const string AutomaticVoiceModerationBanText =
|
||||
"You have been banned as a result of our voice moderation system detecting language that violates our code of conduct.";
|
||||
|
||||
public static readonly TimeSpan DefaultTimeoutDuration = TimeSpan.FromMinutes(60);
|
||||
|
||||
public static readonly TimeSpan MinimumTimeoutDuration = TimeSpan.FromMinutes(60);
|
||||
|
||||
public static readonly TimeSpan MaximumTimeoutDuration = TimeSpan.FromHours(24);
|
||||
|
||||
public static bool IsTimeout(string? banMethod) =>
|
||||
Matches(banMethod, AutomaticTimeoutBanMethod)
|
||||
|| Matches(banMethod, ModeratorReportBanMethod)
|
||||
|| Matches(banMethod, TimeoutBanMethod);
|
||||
|
||||
public static bool IsVoiceModeration(string? banMethod) => Matches(banMethod, VoiceModerationBanMethod);
|
||||
|
||||
public static bool IssuesAppealCode(string? banMethod) => !IsTimeout(banMethod);
|
||||
|
||||
public static bool RefusesAppeal(string? banMethod) => IsVoiceModeration(banMethod);
|
||||
|
||||
public static TimeSpan ClampTimeout(TimeSpan duration)
|
||||
{
|
||||
if (duration < MinimumTimeoutDuration) return MinimumTimeoutDuration;
|
||||
if (duration > MaximumTimeoutDuration) return MaximumTimeoutDuration;
|
||||
return duration;
|
||||
}
|
||||
|
||||
public static DateTime TimeoutExpiry(DateTime startedAtUtc, TimeSpan? duration = null) =>
|
||||
startedAtUtc + ClampTimeout(duration ?? DefaultTimeoutDuration);
|
||||
|
||||
public static DateTime ExtendedTimeoutExpiry(DateTime startedAtUtc, DateTime currentExpiryUtc, TimeSpan? duration = null)
|
||||
{
|
||||
var capped = startedAtUtc + MaximumTimeoutDuration;
|
||||
var proposed = TimeoutExpiry(startedAtUtc, duration);
|
||||
var expiry = proposed > currentExpiryUtc ? proposed : currentExpiryUtc;
|
||||
return expiry > capped ? capped : expiry;
|
||||
}
|
||||
|
||||
private static bool Matches(string? banMethod, string expected) =>
|
||||
string.Equals(banMethod?.Trim(), expected, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace RadicadeServer.RecNet.Moderation
|
||||
{
|
||||
public class OkResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using RadicadeServer.RecNet.Moderation;
|
||||
using RadicadeServer.RecNet.Responses;
|
||||
using RadicadeServer.Utils;
|
||||
using System.Linq;
|
||||
|
||||
namespace RadicadeServer.API
|
||||
{
|
||||
[Route("api/sanitize")]
|
||||
public class SanitizeAPI : Controller
|
||||
{
|
||||
[HttpPost("v1/isPure")]
|
||||
public IsPureResponse GetIsPure([FromBody] IsPureRequest req)
|
||||
{
|
||||
if (req.Value == null) return new IsPureResponse { IsPure = false };
|
||||
return new IsPureResponse { IsPure = req.Value.IsPure() };
|
||||
}
|
||||
|
||||
[HttpPost("v1")]
|
||||
public string GetSanitized([FromBody] SanitizeStringRequest req)
|
||||
{
|
||||
if (req.Value == null) return "";
|
||||
return $"\"{req.Value.Sanitize()}\"";
|
||||
}
|
||||
|
||||
[HttpPost("v2/isAllowed/bulk")]
|
||||
public Success IsAllowedBulk()
|
||||
{
|
||||
var values = ReadBulkValues();
|
||||
var arePure = values.Select(value => value.IsPure()).ToList();
|
||||
|
||||
return new Success(true, null, new { ArePure = arePure });
|
||||
}
|
||||
|
||||
private List<string> ReadBulkValues()
|
||||
{
|
||||
if (Request.HasFormContentType)
|
||||
{
|
||||
var form = Request.Form["Values"];
|
||||
if (form.Count > 0) return form.Where(value => value != null).Select(value => value!).ToList();
|
||||
}
|
||||
|
||||
var query = Request.Query["Values"];
|
||||
if (query.Count > 0) return query.Where(value => value != null).Select(value => value!).ToList();
|
||||
|
||||
return new List<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using RadicadeServer.RecNet.Enums.Moderation;
|
||||
|
||||
namespace RadicadeServer.RecNet.Moderation
|
||||
{
|
||||
public class VoiceChatRestriction
|
||||
{
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public long Id { get; set; }
|
||||
|
||||
public long PlayerId { get; set; }
|
||||
|
||||
public string Reason { get; set; } = "";
|
||||
|
||||
public ReportCategory Category { get; set; }
|
||||
|
||||
public DateTime StartedAt { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public DateTime ExpiresAt { get; set; }
|
||||
|
||||
public string IssuedBy { get; set; } = "Admin Panel";
|
||||
|
||||
public string? IssuedByUsername { get; set; }
|
||||
|
||||
public string? ModeratorNote { get; set; }
|
||||
|
||||
public DateTime? ClearedAt { get; set; }
|
||||
|
||||
public string? ClearedBy { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user