diff --git a/src/VahterBanBot/Bot.fs b/src/VahterBanBot/Bot.fs index 3528769..9d40f35 100644 --- a/src/VahterBanBot/Bot.fs +++ b/src/VahterBanBot/Bot.fs @@ -79,17 +79,17 @@ let aggregateBanResultInLogMsg let targetUserId = message.ReplyToMessage.From.Id let targetUsername = message.ReplyToMessage.From.Username let logMsgBuilder = StringBuilder() - %logMsgBuilder.AppendLine($"Vahter {vahterUsername}({vahterUserId}) banned {targetUsername} ({targetUserId})") + %logMsgBuilder.AppendLine($"Vahter {prependUsername vahterUsername}({vahterUserId}) banned {prependUsername targetUsername} ({targetUserId})") %logMsgBuilder.AppendLine($"Deleted {deletedUserMessages} messages in chats:") (logMsgBuilder, banResults) ||> Array.fold (fun (sb: StringBuilder) result -> match result with | Ok (chatUsername, chatId) -> - sb.AppendLine($"{chatUsername} ({chatId}) - OK") + sb.AppendLine($"{prependUsername chatUsername} ({chatId}) - OK") | Error (chatUsername, chatId, e) -> - logger.LogError($"Failed to ban user {targetUsername} ({targetUserId}) in chat {chatUsername} ({chatId})", e) - sb.AppendLine($"{chatUsername} ({chatId}) - FAILED. {e.Message}") + logger.LogError($"Failed to ban user {prependUsername targetUsername} ({targetUserId}) in chat {prependUsername chatUsername} ({chatId})", e) + sb.AppendLine($"{prependUsername chatUsername} ({chatId}) - FAILED. {e.Message}") ) |> string diff --git a/src/VahterBanBot/Program.fs b/src/VahterBanBot/Program.fs index ab83f17..091edc9 100644 --- a/src/VahterBanBot/Program.fs +++ b/src/VahterBanBot/Program.fs @@ -83,8 +83,6 @@ let server = app.RunAsync() let telegramClient = app.Services.GetRequiredService() let startLogMsg = - let prependUsername (s: string) = - if s.StartsWith("@") then s else "@" + s let sb = System.Text.StringBuilder() %sb.AppendLine("Bot started with following configuration") %sb.AppendLine("AllowedUsers:") diff --git a/src/VahterBanBot/Utils.fs b/src/VahterBanBot/Utils.fs index 381ab09..782c675 100644 --- a/src/VahterBanBot/Utils.fs +++ b/src/VahterBanBot/Utils.fs @@ -15,3 +15,10 @@ let getEnv name = let getEnvOr name defaultValue = let value = Environment.GetEnvironmentVariable name if value = null then defaultValue else value + +let prependUsername (s: string) = + if isNull s then + null + elif s.StartsWith "@" then + s + else "@" + s