Skip to content

Commit

Permalink
added more tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
Szer committed Nov 30, 2023
1 parent 8b92ce0 commit 24cf665
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/VahterBanBot/Bot.fs
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,19 @@ let banOnReply
%banOnReplyActivity
.SetTag("vahterId", message.From.Id)
.SetTag("vahterUsername", message.From.Username)
.SetTag("targetId", message.ReplyToMessage.From.Id)
.SetTag("targetUsername", message.ReplyToMessage.From.Username)

// delete message that was replied to
let deleteReplyTask =
botClient.DeleteMessageAsync(ChatId(message.Chat.Id), message.ReplyToMessage.MessageId)
|> safeTaskAwait (fun e -> logger.LogError ($"Failed to delete reply message {message.ReplyToMessage.MessageId} from chat {message.Chat.Id}", e))

let deleteReplyTask = task {
use _ =
botActivity
.StartActivity("deleteReplyMsg")
.SetTag("msgId", message.ReplyToMessage.MessageId)
.SetTag("chatId", message.Chat.Id)
do! botClient.DeleteMessageAsync(ChatId(message.Chat.Id), message.ReplyToMessage.MessageId)
|> safeTaskAwait (fun e -> logger.LogError ($"Failed to delete reply message {message.ReplyToMessage.MessageId} from chat {message.Chat.Id}", e))
}
// update user in DB
let banUserInDb =
message.ReplyToMessage.From
Expand All @@ -177,6 +184,11 @@ let banOnReply
allUserMessages
|> Seq.map (fun msg -> task {
try
use _ =
botActivity
.StartActivity("deleteMsg")
.SetTag("msgId", msg.Message_Id)
.SetTag("chatId", msg.Chat_Id)
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)
Expand Down Expand Up @@ -232,10 +244,15 @@ let onUpdate
elif isKnownCommand message && isMessageFromAdmin botConfig message then
use _ = botActivity.StartActivity("adminCommand")
// delete command message
let deleteCmdTask =
botClient.DeleteMessageAsync(ChatId(message.Chat.Id), message.MessageId)
|> safeTaskAwait (fun e -> logger.LogError ($"Failed to delete ping message {message.MessageId} from chat {message.Chat.Id}", e))

let deleteCmdTask = task {
use _ =
botActivity
.StartActivity("deleteCmdMsg")
.SetTag("msgId", message.MessageId)
.SetTag("chatId", message.Chat.Id)
do! botClient.DeleteMessageAsync(ChatId(message.Chat.Id), message.MessageId)
|> safeTaskAwait (fun e -> logger.LogError ($"Failed to delete ping message {message.MessageId} from chat {message.Chat.Id}", e))
}
// check that user is allowed to ban others
if isBanOnReplyCommand message && isBanAuthorized botConfig message logger then
do! banOnReply botClient botConfig message logger
Expand All @@ -248,6 +265,9 @@ let onUpdate
// if message is not a command from authorized user, just save it ID to DB
else
use _ = botActivity.StartActivity("justMessage")
%banOnReplyActivity
.SetTag("userId", message.From.Id)
.SetTag("userUsername", message.From.Username)
do!
message
|> DbMessage.newMessage
Expand Down

0 comments on commit 24cf665

Please sign in to comment.