Skip to content

Commit

Permalink
Fix /reminder delete not working in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Pasi4K5 committed Nov 12, 2024
1 parent 27df1fb commit 43ed4a7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Numerous.Bot/Discord/ReminderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public async Task AddReminderAsync(ReminderDto reminder, CancellationToken ct =

private async Task AddReminderAsync(ReminderDto reminder, bool insertIntoDb, CancellationToken ct = default)
{
if (insertIntoDb)
{
await using var uow = uowFactory.Create();
await uow.Reminders.ExecuteInsertAsync(reminder, ct);
}

if (reminder.Timestamp < DateTimeOffset.Now + _cacheInterval)
{
var timer = new Timer
Expand All @@ -48,17 +54,11 @@ private async Task AddReminderAsync(ReminderDto reminder, bool insertIntoDb, Can

timer.Start();
}

if (insertIntoDb)
{
await using var uow = uowFactory.Create();
await uow.Reminders.ExecuteInsertAsync(reminder, ct);
}
}

public async Task RemoveReminderAsync(ReminderDto reminder)
{
if (_timerCache.TryGetValue(reminder.Id, out var timer))
if (_timerCache.Remove(reminder.Id, out var timer))
{
timer.Stop();
timer.Dispose();
Expand Down

0 comments on commit 43ed4a7

Please sign in to comment.