Raid messages are now deleted after the raid ends.

Raids are deleted after a year
This commit is contained in:
Sarah Faey 2022-11-19 00:22:08 +01:00
parent 25a381124d
commit 803332bc5c
2 changed files with 40 additions and 5 deletions

View file

@ -424,7 +424,7 @@ namespace Lieb.Data
using var context = _contextFactory.CreateDbContext();
await context.RaidLogs.AddAsync(log);
await context.SaveChangesAsync();
await SendDiscordSignUpLogMessage(signUp, userName, signedUpBy);
}
@ -485,6 +485,25 @@ namespace Lieb.Data
}
}
public async Task CleanUpRaids()
{
using var context = _contextFactory.CreateDbContext();
List<Raid> raids = GetRaids();
DateTimeOffset utcNow = DateTimeOffset.UtcNow;
foreach(Raid raid in raids.Where(r => r.EndTimeUTC < utcNow.AddYears(-1)))
{
await DeleteRaid(raid.RaidId);
}
foreach(Raid raid in raids.Where(r => r.EndTimeUTC < utcNow.AddHours(-1)))
{
await _discordService.DeleteRaidMessages(raid);
context.RaidReminders.RemoveRange(raid.Reminders);
context.DiscordRaidMessages.RemoveRange(raid.DiscordRaidMessages);
await context.SaveChangesAsync();
}
}
public RaidRole CreateRandomSignUpRole(RaidType raidType)
{
return new RaidRole()