From 1c159c37ff8dda3cebfe60ba0c2968f7730b6b6f Mon Sep 17 00:00:00 2001 From: Iris System Date: Sun, 5 Feb 2023 01:29:41 +1300 Subject: [PATCH] fix(bot): wait for database insert before deleting original message Closes #495 Co-authored-by: spiral --- PluralKit.Bot/Proxy/ProxyService.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index dfb125d2..5a3290da 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -420,8 +420,7 @@ public class ProxyService Sender = triggerMessage.Author.Id }; - Task SaveMessageInDatabase() - => _repo.AddMessage(sentMessage); + Task saveMessageInDatabase = _repo.AddMessage(sentMessage); async Task SaveMessageInRedis() { @@ -458,6 +457,10 @@ public class ProxyService // Wait a second or so before deleting the original message await Task.Delay(MessageDeletionDelay); + + // Wait until the message info is done saving in the database + await saveMessageInDatabase; + try { await _rest.DeleteMessage(triggerMessage.ChannelId, triggerMessage.Id); @@ -475,7 +478,7 @@ public class ProxyService // Run post-proxy actions (simultaneously; order doesn't matter) await Task.WhenAll( DeleteProxyTriggerMessage(), - SaveMessageInDatabase(), + saveMessageInDatabase, SaveMessageInRedis(), UpdateMemberForSentMessage(), LogMessageToChannel(),