Skip to content

Commit

Permalink
even more robust now
Browse files Browse the repository at this point in the history
  • Loading branch information
Szer committed Nov 27, 2023
1 parent e1e9956 commit 051edcc
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/VahterBanBot/Bot.fs
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,18 @@ let banOnReply

let deletedUserMessagesTask = task {
let fromUserId = message.ReplyToMessage.From.Id
let! allUserMessages = DB.getUserMessages fromUserId

// delete all recorded messages from user in all chats
let! allUserMessages = DB.getUserMessages fromUserId
for msg in allUserMessages do
// try to delete each message separately
do! botClient.DeleteMessageAsync(ChatId(msg.Chat_Id), msg.Message_Id)
|> safeTaskAwait (fun e -> logger.LogError ($"Failed to delete message {msg.Message_Id} from chat {msg.Chat_Id}", e))
let! _ =
allUserMessages
|> Seq.map (fun msg -> task {
try
do! botClient.DeleteMessageAsync(ChatId(msg.Chat_Id), msg.Message_Id)
with e ->
logger.LogError ($"Failed to delete message {msg.Message_Id} from chat {msg.Chat_Id}", e)
})
|> Task.WhenAll

// delete recorded messages from DB
return! DB.deleteUserMessages fromUserId
Expand Down

0 comments on commit 051edcc

Please sign in to comment.