From b27114eaad24bc3cb13f650b8953c19c78574c11 Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 15 Apr 2024 14:50:03 +0200 Subject: [PATCH] April Fools Mode https://github.com/C9Glax/tranga/issues/155 --- Tranga/Server.cs | 13 +++++++++++++ Tranga/Tranga.cs | 15 ++++++++++++++- Tranga/TrangaSettings.cs | 9 ++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Tranga/Server.cs b/Tranga/Server.cs index cf2d15a..75b159f 100644 --- a/Tranga/Server.cs +++ b/Tranga/Server.cs @@ -206,6 +206,9 @@ public class Server : GlobalBase case "Settings/customRequestLimit": SendResponse(HttpStatusCode.OK, response, settings.requestLimits); break; + case "Settings/AprilFoolsMode": + SendResponse(HttpStatusCode.OK, response, settings.aprilFoolsMode); + break; case "NotificationConnectors": SendResponse(HttpStatusCode.OK, response, notificationConnectors); break; @@ -405,6 +408,16 @@ public class Server : GlobalBase settings.UpdateDownloadLocation(downloadLocation, moveFiles); SendResponse(HttpStatusCode.Accepted, response); break; + case "Settings/AprilFoolsMode": + if (!requestVariables.TryGetValue("enabled", out string? aprilFoolsModeEnabledStr) || + bool.TryParse(aprilFoolsModeEnabledStr, out bool aprilFoolsModeEnabled)) + { + SendResponse(HttpStatusCode.BadRequest, response); + break; + } + settings.UpdateAprilFoolsMode(aprilFoolsModeEnabled); + SendResponse(HttpStatusCode.Accepted, response); + break; /*case "Settings/UpdateWorkingDirectory": if (!requestVariables.TryGetValue("workingDirectory", out string? workingDirectory)) { diff --git a/Tranga/Tranga.cs b/Tranga/Tranga.cs index 9dcc387..f5a0f91 100644 --- a/Tranga/Tranga.cs +++ b/Tranga/Tranga.cs @@ -73,10 +73,23 @@ public partial class Tranga : GlobalBase { while (keepRunning) { - jobBoss.CheckJobs(); + if(!settings.aprilFoolsMode & !IsAprilFirst()) + jobBoss.CheckJobs(); + else + Log("April Fools Mode in Effect"); Thread.Sleep(100); } }); t.Start(); } + + private bool IsAprilFirst() + { + //UTC 01 Apr +-12hrs + DateTime start = new DateTime(DateTime.Now.Year, 03, 31, 12, 0, 0, DateTimeKind.Utc); + DateTime end = new DateTime(DateTime.Now.Year, 04, 02, 12, 0, 0, DateTimeKind.Utc); + if (DateTime.UtcNow > start && DateTime.UtcNow < end) + return true; + return false; + } } \ No newline at end of file diff --git a/Tranga/TrangaSettings.cs b/Tranga/TrangaSettings.cs index 4fae2fb..0bb8399 100644 --- a/Tranga/TrangaSettings.cs +++ b/Tranga/TrangaSettings.cs @@ -20,7 +20,8 @@ public class TrangaSettings [JsonIgnore] public string jobsFolderPath => Path.Join(workingDirectory, "jobs"); [JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache"); [JsonIgnore] internal static readonly string DefaultUserAgent = $"Tranga ({Enum.GetName(Environment.OSVersion.Platform)}; {(Environment.Is64BitOperatingSystem ? "x64" : "")}) / 1.0"; - public ushort? version { get; set; } = 1; + public ushort? version { get; } = 1; + public bool aprilFoolsMode { get; private set; } = true; [JsonIgnore]internal static readonly Dictionary DefaultRequestLimits = new () { {RequestType.MangaInfo, 250}, @@ -102,6 +103,12 @@ public class TrangaSettings })!; } + public void UpdateAprilFoolsMode(bool enabled) + { + this.aprilFoolsMode = enabled; + ExportSettings(); + } + public void UpdateDownloadLocation(string newPath, bool moveFiles = true) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))