From 058cc89cbc4c2b24c09fbaf965c2a8b5cd4bc303 Mon Sep 17 00:00:00 2001 From: Sarah Faey Date: Sat, 10 Dec 2022 21:13:14 +0100 Subject: [PATCH] Maybe SignUps are removed 15min before the raid starts --- Lieb/Data/Constants.cs | 1 + Lieb/Data/RaidService.cs | 39 ++++++++++++++++++++++++++++----------- Lieb/Data/TimerService.cs | 1 + 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/Lieb/Data/Constants.cs b/Lieb/Data/Constants.cs index 047247e..f1e6df1 100644 --- a/Lieb/Data/Constants.cs +++ b/Lieb/Data/Constants.cs @@ -6,6 +6,7 @@ public const string ClaimType = "Role"; public const string GW2_ACCOUNT_REGEX = "^[a-zA-z ]{3,27}\\.[0-9]{4}$"; public static readonly int RaidEditPowerLevel = Roles.Moderator.PowerLevel; + public const int REMOVE_MAYBE_MINUTES = 15; public static class Roles { diff --git a/Lieb/Data/RaidService.cs b/Lieb/Data/RaidService.cs index e7c6bb9..d52d1a3 100644 --- a/Lieb/Data/RaidService.cs +++ b/Lieb/Data/RaidService.cs @@ -590,6 +590,34 @@ namespace Lieb.Data } } + public RaidRole CreateRandomSignUpRole(RaidType raidType, int spots = 10) + { + return new RaidRole() + { + Spots = spots, + Name = "Random", + Description = raidType.ToString(), + IsRandomSignUpRole = true + }; + } + + public async Task RemoveMaybes() + { + using var context = _contextFactory.CreateDbContext(); + List raids = context.Raids.Include(r => r.SignUps).ToList(); + foreach(Raid raid in raids.Where(r => r.StartTimeUTC < DateTimeOffset.UtcNow.AddMinutes(Constants.REMOVE_MAYBE_MINUTES) + && r.SignUps.Where(s => s.SignUpType == SignUpType.Maybe).Any())) + { + foreach(RaidSignUp signup in raid.SignUps) + { + if(signup.SignUpType == SignUpType.Maybe && signup.LiebUserId.HasValue) + { + await SignOff(raid.RaidId, signup.LiebUserId.Value); + } + } + } + } + public async Task CleanUpRaids() { using var context = _contextFactory.CreateDbContext(); @@ -609,16 +637,5 @@ namespace Lieb.Data await context.SaveChangesAsync(); } } - - public RaidRole CreateRandomSignUpRole(RaidType raidType, int spots = 10) - { - return new RaidRole() - { - Spots = spots, - Name = "Random", - Description = raidType.ToString(), - IsRandomSignUpRole = true - }; - } } } diff --git a/Lieb/Data/TimerService.cs b/Lieb/Data/TimerService.cs index f30d79b..d1814fe 100644 --- a/Lieb/Data/TimerService.cs +++ b/Lieb/Data/TimerService.cs @@ -48,6 +48,7 @@ namespace Lieb.Data scope.ServiceProvider .GetRequiredService(); await raidService.SendReminders(); + await raidService.RemoveMaybes(); } }