Maybe SignUps are removed 15min before the raid starts

This commit is contained in:
Sarah Faey 2022-12-10 21:13:14 +01:00
parent 9045de9b9d
commit 058cc89cbc
3 changed files with 30 additions and 11 deletions

View file

@ -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
{

View file

@ -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<Raid> 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
};
}
}
}

View file

@ -48,6 +48,7 @@ namespace Lieb.Data
scope.ServiceProvider
.GetRequiredService<RaidService>();
await raidService.SendReminders();
await raidService.RemoveMaybes();
}
}