| | | 1 | | using TeleFlow.Telegram.Internal.Handlers; |
| | | 2 | | using TeleFlow.Telegram.Schema.Types; |
| | | 3 | | |
| | | 4 | | namespace TeleFlow.Telegram.Internal; |
| | | 5 | | |
| | | 6 | | internal static class TelegramUpdateLogFormatter |
| | | 7 | | { |
| | | 8 | | public static string GetUpdateType(Update update) |
| | | 9 | | { |
| | 21 | 10 | | return TelegramUpdateClassifier.Classify(update).Type; |
| | | 11 | | } |
| | | 12 | | |
| | | 13 | | public static string FormatAllowedUpdates(IReadOnlyList<string>? allowedUpdates) |
| | | 14 | | { |
| | 16 | 15 | | return allowedUpdates is null || allowedUpdates.Count == 0 |
| | 16 | 16 | | ? "unset" |
| | 16 | 17 | | : $"[{string.Join(",", allowedUpdates)}]"; |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | public static string FormatHandler(TelegramHandlerDescriptor handler) |
| | | 21 | | { |
| | 19 | 22 | | ArgumentNullException.ThrowIfNull(handler); |
| | 19 | 23 | | return $"{handler.HandlerType.Name}.{handler.MethodName}"; |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | public static string FormatRoute(TelegramRouteDescriptor route) |
| | | 27 | | { |
| | 19 | 28 | | ArgumentNullException.ThrowIfNull(route); |
| | | 29 | | |
| | 19 | 30 | | return route.RouteKind switch |
| | 19 | 31 | | { |
| | 4 | 32 | | TelegramRouteKind.CommandExact => FormatPatternRoute(route, "CommandExact"), |
| | 0 | 33 | | TelegramRouteKind.CommandTemplate => FormatPatternRoute(route, "CommandTemplate"), |
| | 0 | 34 | | TelegramRouteKind.CommandRegex => FormatPatternRoute(route, "CommandRegex"), |
| | 0 | 35 | | TelegramRouteKind.TextExact => FormatPatternRoute(route, "TextExact"), |
| | 0 | 36 | | TelegramRouteKind.TextTemplate => FormatPatternRoute(route, "TextTemplate"), |
| | 0 | 37 | | TelegramRouteKind.TextRegex => FormatPatternRoute(route, "TextRegex"), |
| | 6 | 38 | | TelegramRouteKind.Callback when route.CallbackPayloadType is not null => |
| | 3 | 39 | | $"Callback<{route.CallbackPayloadType.Name}>", |
| | 3 | 40 | | TelegramRouteKind.Callback => "Callback", |
| | 9 | 41 | | TelegramRouteKind.MessageAny when route.TextFilters.Count > 0 => |
| | 0 | 42 | | $"MessageAny(text_filters={route.TextFilters.Count})", |
| | 9 | 43 | | TelegramRouteKind.MessageAny => "MessageAny", |
| | 0 | 44 | | _ => route.RouteKind.ToString() |
| | 19 | 45 | | }; |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | private static string FormatPatternRoute(TelegramRouteDescriptor route, string name) |
| | | 49 | | { |
| | 4 | 50 | | return string.IsNullOrWhiteSpace(route.Pattern) |
| | 4 | 51 | | ? name |
| | 4 | 52 | | : $"{name}('{route.Pattern}')"; |
| | | 53 | | } |
| | | 54 | | } |