changed reminders to use DateTimeOffset
This commit is contained in:
parent
62dc3d1efa
commit
ed7a1905fd
3 changed files with 19 additions and 19 deletions
|
@ -410,14 +410,13 @@ namespace Lieb.Data
|
|||
public async Task SendReminders()
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
DateTimeOffset now = DateTimeOffset.UtcNow;
|
||||
List<Raid> raids = context.Raids
|
||||
.Include(r => r.Reminders)
|
||||
List<RaidReminder> reminders = context.RaidReminders
|
||||
.Include(r => r.Raid)
|
||||
.Where(r => !r.Sent)
|
||||
.ToList();
|
||||
|
||||
foreach(Raid raid in raids.Where(r => r.StartTimeUTC > now))
|
||||
{
|
||||
foreach(RaidReminder reminder in raid.Reminders.Where(reminder => !reminder.Sent && raid.StartTimeUTC.AddHours(-reminder.HoursBeforeRaid) < DateTime.UtcNow))
|
||||
DateTimeOffset now = DateTimeOffset.UtcNow;
|
||||
foreach(RaidReminder reminder in reminders.Where(r => r.ReminderTime < now))
|
||||
{
|
||||
switch(reminder.Type)
|
||||
{
|
||||
|
@ -430,7 +429,6 @@ namespace Lieb.Data
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RaidRole CreateRandomSignUpRole(RaidType raidType)
|
||||
{
|
||||
|
|
|
@ -60,7 +60,8 @@ namespace Lieb.Models.GuildWars2.Raid
|
|||
{
|
||||
Description = role.Description,
|
||||
Name = role.Name,
|
||||
Spots = role.Spots
|
||||
Spots = role.Spots,
|
||||
IsRandomSignUpRole = role.IsRandomSignUpRole
|
||||
});
|
||||
}
|
||||
foreach (RaidReminder reminder in template.Reminders)
|
||||
|
@ -69,10 +70,11 @@ namespace Lieb.Models.GuildWars2.Raid
|
|||
{
|
||||
DiscordServerId = reminder.DiscordServerId,
|
||||
DiscordChannelId = reminder.DiscordChannelId,
|
||||
HoursBeforeRaid = reminder.HoursBeforeRaid,
|
||||
ReminderTime = reminder.ReminderTime,
|
||||
Message = reminder.Message,
|
||||
Sent = reminder.Sent,
|
||||
Type = reminder.Type
|
||||
Type = reminder.Type,
|
||||
RaidId = reminder.RaidId
|
||||
});
|
||||
}
|
||||
foreach (DiscordRaidMessage message in template.DiscordRaidMessages)
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace Lieb.Models.GuildWars2.Raid
|
|||
public string Message { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double HoursBeforeRaid { get; set; }
|
||||
public DateTimeOffset ReminderTime { get; set; } = DateTime.Now;
|
||||
|
||||
public ulong DiscordServerId { get; set; }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue