From 74a7854f40b4b5fe1ddfddf3d47265275e214295 Mon Sep 17 00:00:00 2001 From: Ayrat Hudaygulov Date: Wed, 27 Sep 2023 22:25:54 +0100 Subject: [PATCH] delete messages --- src/VahterBanBot/Bot.fs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/VahterBanBot/Bot.fs b/src/VahterBanBot/Bot.fs index 338b170..1b5595a 100644 --- a/src/VahterBanBot/Bot.fs +++ b/src/VahterBanBot/Bot.fs @@ -112,19 +112,28 @@ let onUpdate // and check that user is allowed to ban others elif isBanOnReplyMessage message && isBanAuthorized botConfig message logger then + // delete command message + let deleteCmdTask = botClient.DeleteMessageAsync(ChatId(message.Chat.Id), message.MessageId) + // delete message that was replied to + let deleteReplyTask = botClient.DeleteMessageAsync(ChatId(message.Chat.Id), message.ReplyToMessage.MessageId) + // try ban user in all monitored chats let! banResults = banInAllChats botConfig botClient message.ReplyToMessage.From.Id // produce aggregated log message let logMsg = aggregateBanResultInLogMsg logger message banResults - + // log both to logger and to logs channel let! _ = botClient.SendTextMessageAsync(ChatId(botConfig.LogsChannelId), logMsg) logger.LogInformation logMsg + do! deleteCmdTask + do! deleteReplyTask + // ping command for testing that bot works and you can talk to it elif isPingCommand message && isMessageFromAdmin botConfig message then + // delete command message + let deleteCmdTask = botClient.DeleteMessageAsync(ChatId(message.Chat.Id), message.MessageId) let! _ = botClient.SendTextMessageAsync(ChatId(message.Chat.Id), "pong") - () + do! deleteCmdTask } -