| | | 1 | | namespace TeleFlow.Telegram.Internal.Handlers; |
| | | 2 | | |
| | | 3 | | internal sealed class TelegramGeneratedHandlerRegistry : ITelegramGeneratedHandlerRegistry |
| | | 4 | | { |
| | 36 | 5 | | private readonly List<TelegramGeneratedHandlerDescriptor> _descriptors = []; |
| | 36 | 6 | | private readonly List<TelegramGeneratedErrorHandlerDescriptor> _errorDescriptors = []; |
| | | 7 | | |
| | | 8 | | public void RegisterHandler(TelegramGeneratedHandlerDescriptor descriptor) |
| | | 9 | | { |
| | 1062 | 10 | | ArgumentNullException.ThrowIfNull(descriptor); |
| | | 11 | | |
| | 1062 | 12 | | _descriptors.Add(descriptor); |
| | 1062 | 13 | | } |
| | | 14 | | |
| | | 15 | | public void RegisterErrorHandler(TelegramGeneratedErrorHandlerDescriptor descriptor) |
| | | 16 | | { |
| | 129 | 17 | | ArgumentNullException.ThrowIfNull(descriptor); |
| | | 18 | | |
| | 129 | 19 | | _errorDescriptors.Add(descriptor); |
| | 129 | 20 | | } |
| | | 21 | | |
| | | 22 | | public IReadOnlyList<TelegramHandlerDescriptor> BuildDescriptors( |
| | | 23 | | int firstRegistrationOrder, |
| | | 24 | | Func<TelegramGeneratedHandlerDescriptor, bool>? predicate = null) |
| | | 25 | | { |
| | 36 | 26 | | return _descriptors |
| | 1062 | 27 | | .OrderBy(static descriptor => descriptor.RegistrationOrder) |
| | 1062 | 28 | | .Where(descriptor => predicate?.Invoke(descriptor) ?? true) |
| | 832 | 29 | | .Select((descriptor, index) => BuildDescriptor(descriptor, firstRegistrationOrder + index)) |
| | 36 | 30 | | .ToArray(); |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | public IReadOnlyList<TelegramErrorHandlerDescriptor> BuildErrorDescriptors( |
| | | 34 | | int firstRegistrationOrder, |
| | | 35 | | Func<TelegramGeneratedErrorHandlerDescriptor, bool>? predicate = null) |
| | | 36 | | { |
| | 36 | 37 | | return _errorDescriptors |
| | 129 | 38 | | .OrderBy(static descriptor => descriptor.RegistrationOrder) |
| | 129 | 39 | | .Where(descriptor => predicate?.Invoke(descriptor) ?? true) |
| | 102 | 40 | | .Select((descriptor, index) => BuildErrorDescriptor(descriptor, firstRegistrationOrder + index)) |
| | 36 | 41 | | .ToArray(); |
| | | 42 | | } |
| | | 43 | | |
| | 29 | 44 | | public IReadOnlyList<Type> HandlerTypes => _descriptors |
| | 831 | 45 | | .Select(static descriptor => descriptor.HandlerType) |
| | 101 | 46 | | .Concat(_errorDescriptors.Select(static descriptor => descriptor.HandlerType)) |
| | 29 | 47 | | .Distinct() |
| | 29 | 48 | | .ToArray(); |
| | | 49 | | |
| | | 50 | | private static TelegramHandlerDescriptor BuildDescriptor( |
| | | 51 | | TelegramGeneratedHandlerDescriptor descriptor, |
| | | 52 | | int registrationOrder) |
| | | 53 | | { |
| | 832 | 54 | | var kind = MapKind(descriptor.Kind); |
| | 832 | 55 | | var parameters = descriptor.Parameters |
| | 1709 | 56 | | .Select(static parameter => new TelegramHandlerParameterDescriptor( |
| | 1709 | 57 | | parameter.ParameterType, |
| | 1709 | 58 | | MapParameterKind(parameter.Kind), |
| | 1709 | 59 | | parameter.Name)) |
| | 832 | 60 | | .ToArray(); |
| | 832 | 61 | | var routeValues = descriptor.RouteValues.Count > 0 |
| | 832 | 62 | | ? descriptor.RouteValues |
| | 50 | 63 | | .Select(static value => new TelegramRouteValueDescriptor( |
| | 50 | 64 | | value.Name, |
| | 50 | 65 | | value.ValueType, |
| | 50 | 66 | | value.IsOptional)) |
| | 832 | 67 | | .ToArray() |
| | 832 | 68 | | : parameters |
| | 1559 | 69 | | .Where(static parameter => parameter.Kind == TelegramHandlerParameterKind.RouteValue) |
| | 25 | 70 | | .Select(static parameter => new TelegramRouteValueDescriptor( |
| | 25 | 71 | | parameter.Name!, |
| | 25 | 72 | | Nullable.GetUnderlyingType(parameter.ParameterType) ?? parameter.ParameterType)) |
| | 832 | 73 | | .ToArray(); |
| | 832 | 74 | | var route = new TelegramRouteDescriptor( |
| | 832 | 75 | | MapRouteKind(descriptor.RouteKind), |
| | 832 | 76 | | descriptor.RoutePattern ?? descriptor.Command, |
| | 832 | 77 | | new TelegramCommandPolicy( |
| | 832 | 78 | | descriptor.CommandPrefixes, |
| | 832 | 79 | | descriptor.AllowSpaceAfterPrefix, |
| | 832 | 80 | | descriptor.IgnoreCase, |
| | 832 | 81 | | descriptor.PrefixMode), |
| | 832 | 82 | | descriptor.TextFilters |
| | 150 | 83 | | .Select(static filter => new TelegramTextFilter(filter.Value, filter.Mode, filter.IgnoreCase)) |
| | 832 | 84 | | .ToArray(), |
| | 832 | 85 | | descriptor.CallbackPayloadType, |
| | 832 | 86 | | routeValues, |
| | 832 | 87 | | descriptor.Filters |
| | 575 | 88 | | .Select(filter => MapFilter(filter, kind)) |
| | 832 | 89 | | .ToArray(), |
| | 832 | 90 | | descriptor.ChatMemberTransitions |
| | 25 | 91 | | .Select(static transition => new TelegramChatMemberTransitionDescriptor( |
| | 25 | 92 | | transition.OldStatus, |
| | 25 | 93 | | transition.NewStatus)) |
| | 832 | 94 | | .ToArray(), |
| | 832 | 95 | | descriptor.RoleRequirements |
| | 25 | 96 | | .Select(static requirement => new TelegramRoleRequirementDescriptor(requirement.AllowedStatuses)) |
| | 832 | 97 | | .ToArray()); |
| | | 98 | | |
| | 832 | 99 | | return new TelegramHandlerDescriptor( |
| | 832 | 100 | | descriptor.HandlerType, |
| | 832 | 101 | | descriptor.MethodName, |
| | 832 | 102 | | (services, arguments, cancellationToken) => |
| | 56 | 103 | | descriptor.Invoker(services, arguments, cancellationToken), |
| | 832 | 104 | | route, |
| | 832 | 105 | | registrationOrder, |
| | 832 | 106 | | descriptor.ModuleName, |
| | 832 | 107 | | descriptor.States.ToArray(), |
| | 832 | 108 | | parameters, |
| | 832 | 109 | | descriptor.SceneName, |
| | 832 | 110 | | MapAutoAnswerCallback(descriptor.AutoAnswerCallback)); |
| | | 111 | | } |
| | | 112 | | |
| | | 113 | | private static TelegramErrorHandlerDescriptor BuildErrorDescriptor( |
| | | 114 | | TelegramGeneratedErrorHandlerDescriptor descriptor, |
| | | 115 | | int registrationOrder) |
| | | 116 | | { |
| | 102 | 117 | | var parameters = descriptor.Parameters |
| | 256 | 118 | | .Select(static parameter => new TelegramErrorHandlerParameterDescriptor( |
| | 256 | 119 | | parameter.ParameterType, |
| | 256 | 120 | | MapErrorParameterKind(parameter.Kind), |
| | 256 | 121 | | parameter.Name)) |
| | 102 | 122 | | .ToArray(); |
| | | 123 | | |
| | 102 | 124 | | return new TelegramErrorHandlerDescriptor( |
| | 102 | 125 | | descriptor.HandlerType, |
| | 102 | 126 | | descriptor.MethodName, |
| | 102 | 127 | | (services, arguments, cancellationToken) => |
| | 4 | 128 | | descriptor.Invoker(services, arguments, cancellationToken), |
| | 102 | 129 | | descriptor.ExceptionType, |
| | 102 | 130 | | descriptor.TelegramContextType, |
| | 102 | 131 | | registrationOrder, |
| | 102 | 132 | | descriptor.ModuleName, |
| | 102 | 133 | | parameters); |
| | | 134 | | } |
| | | 135 | | |
| | | 136 | | private static TelegramAutoAnswerCallbackDescriptor? MapAutoAnswerCallback( |
| | | 137 | | TelegramGeneratedAutoAnswerCallbackDescriptor? descriptor) |
| | | 138 | | { |
| | 832 | 139 | | return descriptor is null |
| | 832 | 140 | | ? null |
| | 832 | 141 | | : new TelegramAutoAnswerCallbackDescriptor( |
| | 832 | 142 | | descriptor.Enabled, |
| | 832 | 143 | | descriptor.Text, |
| | 832 | 144 | | descriptor.ShowAlert); |
| | | 145 | | } |
| | | 146 | | |
| | | 147 | | private static TelegramHandlerKind MapKind(TelegramGeneratedHandlerKind kind) |
| | | 148 | | { |
| | 832 | 149 | | return kind switch |
| | 832 | 150 | | { |
| | 305 | 151 | | TelegramGeneratedHandlerKind.Command => TelegramHandlerKind.Command, |
| | 300 | 152 | | TelegramGeneratedHandlerKind.Message => TelegramHandlerKind.Message, |
| | 202 | 153 | | TelegramGeneratedHandlerKind.Callback => TelegramHandlerKind.Callback, |
| | 25 | 154 | | TelegramGeneratedHandlerKind.ChatMember => TelegramHandlerKind.ChatMember, |
| | 0 | 155 | | _ => throw new InvalidOperationException($"Unsupported generated Telegram handler kind '{kind}'.") |
| | 832 | 156 | | }; |
| | | 157 | | } |
| | | 158 | | |
| | | 159 | | private static TelegramRouteKind MapRouteKind(TelegramGeneratedRouteKind kind) |
| | | 160 | | { |
| | 832 | 161 | | return kind switch |
| | 832 | 162 | | { |
| | 150 | 163 | | TelegramGeneratedRouteKind.MessageAny => TelegramRouteKind.MessageAny, |
| | 125 | 164 | | TelegramGeneratedRouteKind.TextExact => TelegramRouteKind.TextExact, |
| | 255 | 165 | | TelegramGeneratedRouteKind.CommandExact => TelegramRouteKind.CommandExact, |
| | 25 | 166 | | TelegramGeneratedRouteKind.TextTemplate => TelegramRouteKind.TextTemplate, |
| | 50 | 167 | | TelegramGeneratedRouteKind.CommandTemplate => TelegramRouteKind.CommandTemplate, |
| | 0 | 168 | | TelegramGeneratedRouteKind.TextRegex => TelegramRouteKind.TextRegex, |
| | 0 | 169 | | TelegramGeneratedRouteKind.CommandRegex => TelegramRouteKind.CommandRegex, |
| | 202 | 170 | | TelegramGeneratedRouteKind.Callback => TelegramRouteKind.Callback, |
| | 25 | 171 | | TelegramGeneratedRouteKind.ChatMemberUpdated => TelegramRouteKind.ChatMemberUpdated, |
| | 0 | 172 | | TelegramGeneratedRouteKind.MyChatMemberUpdated => TelegramRouteKind.MyChatMemberUpdated, |
| | 0 | 173 | | _ => throw new InvalidOperationException($"Unsupported generated Telegram route kind '{kind}'.") |
| | 832 | 174 | | }; |
| | | 175 | | } |
| | | 176 | | |
| | | 177 | | private static TelegramFilterDescriptor MapFilter( |
| | | 178 | | TelegramGeneratedFilterDescriptor descriptor, |
| | | 179 | | TelegramHandlerKind kind) |
| | | 180 | | { |
| | 575 | 181 | | if (descriptor.Kind == TelegramGeneratedFilterKind.Custom) |
| | | 182 | | { |
| | 50 | 183 | | if (descriptor.CustomFilterType is null) |
| | | 184 | | { |
| | 0 | 185 | | throw new InvalidOperationException("Generated custom Telegram filter descriptor must provide a filter t |
| | | 186 | | } |
| | | 187 | | |
| | 50 | 188 | | ValidateCustomFilterType( |
| | 50 | 189 | | descriptor.CustomFilterType, |
| | 50 | 190 | | descriptor.CustomFilterContextType, |
| | 50 | 191 | | descriptor.CustomFilterAttribute, |
| | 50 | 192 | | kind); |
| | | 193 | | |
| | 50 | 194 | | if (descriptor.CustomFilterAttribute is null) |
| | | 195 | | { |
| | 25 | 196 | | return descriptor.CustomFilterContextType is null |
| | 25 | 197 | | ? new TelegramFilterDescriptor(descriptor.CustomFilterType) |
| | 25 | 198 | | : new TelegramFilterDescriptor( |
| | 25 | 199 | | descriptor.CustomFilterType, |
| | 25 | 200 | | descriptor.CustomFilterContextType); |
| | | 201 | | } |
| | | 202 | | |
| | 25 | 203 | | return descriptor.CustomFilterContextType is null |
| | 25 | 204 | | ? new TelegramFilterDescriptor( |
| | 25 | 205 | | descriptor.CustomFilterType, |
| | 25 | 206 | | descriptor.CustomFilterAttribute) |
| | 25 | 207 | | : new TelegramFilterDescriptor( |
| | 25 | 208 | | descriptor.CustomFilterType, |
| | 25 | 209 | | descriptor.CustomFilterContextType, |
| | 25 | 210 | | descriptor.CustomFilterAttribute); |
| | | 211 | | } |
| | | 212 | | |
| | 525 | 213 | | var filterKind = MapFilterKind(descriptor.Kind); |
| | | 214 | | |
| | 525 | 215 | | if (!TelegramFilterCompatibility.Supports(filterKind, kind)) |
| | | 216 | | { |
| | 0 | 217 | | throw new InvalidOperationException( |
| | 0 | 218 | | $"Generated {TelegramFilterCompatibility.GetInvalidPlacementMessage(filterKind, kind)}"); |
| | | 219 | | } |
| | | 220 | | |
| | 525 | 221 | | return new TelegramFilterDescriptor( |
| | 525 | 222 | | filterKind, |
| | 525 | 223 | | descriptor.StringValues.ToArray(), |
| | 525 | 224 | | descriptor.LongValues.ToArray()); |
| | | 225 | | } |
| | | 226 | | |
| | | 227 | | private static void ValidateCustomFilterType( |
| | | 228 | | Type filterType, |
| | | 229 | | Type? contextType, |
| | | 230 | | Attribute? attribute, |
| | | 231 | | TelegramHandlerKind kind) |
| | | 232 | | { |
| | 50 | 233 | | if (filterType.IsInterface || |
| | 50 | 234 | | filterType.IsAbstract || |
| | 50 | 235 | | filterType.ContainsGenericParameters) |
| | | 236 | | { |
| | 0 | 237 | | throw new InvalidOperationException( |
| | 0 | 238 | | $"Generated custom Telegram filter type '{filterType.FullName}' must be a concrete closed type."); |
| | | 239 | | } |
| | | 240 | | |
| | 50 | 241 | | var expectedContextType = kind switch |
| | 50 | 242 | | { |
| | 0 | 243 | | TelegramHandlerKind.Callback => typeof(CallbackQueryContext), |
| | 0 | 244 | | TelegramHandlerKind.ChatMember => typeof(ChatMemberUpdatedContext), |
| | 50 | 245 | | _ => typeof(MessageContext) |
| | 50 | 246 | | }; |
| | | 247 | | |
| | 50 | 248 | | if (contextType is not null) |
| | | 249 | | { |
| | 25 | 250 | | if (contextType != expectedContextType && |
| | 25 | 251 | | contextType != typeof(TelegramUpdateContext)) |
| | | 252 | | { |
| | 0 | 253 | | throw new InvalidOperationException( |
| | 0 | 254 | | $"Generated custom Telegram filter type '{filterType.FullName}' is not compatible with {expectedCont |
| | | 255 | | } |
| | | 256 | | |
| | 25 | 257 | | var requiredContract = attribute is null |
| | 25 | 258 | | ? typeof(ITelegramFilter<>).MakeGenericType(contextType) |
| | 25 | 259 | | : typeof(ITelegramFilter<,>).MakeGenericType(contextType, attribute.GetType()); |
| | | 260 | | |
| | 25 | 261 | | if (!requiredContract.IsAssignableFrom(filterType)) |
| | | 262 | | { |
| | 0 | 263 | | throw new InvalidOperationException( |
| | 0 | 264 | | attribute is null |
| | 0 | 265 | | ? $"Generated custom Telegram filter type '{filterType.FullName}' must implement ITelegramFilter |
| | 0 | 266 | | : $"Generated parameterized custom Telegram filter type '{filterType.FullName}' must implement I |
| | | 267 | | } |
| | | 268 | | |
| | 25 | 269 | | return; |
| | | 270 | | } |
| | | 271 | | |
| | 25 | 272 | | if (attribute is null) |
| | | 273 | | { |
| | 25 | 274 | | var contextTypes = GetCustomFilterContextTypes(filterType, attributeType: null); |
| | | 275 | | |
| | 25 | 276 | | if (contextTypes.Length == 0) |
| | | 277 | | { |
| | 0 | 278 | | throw new InvalidOperationException( |
| | 0 | 279 | | $"Generated custom Telegram filter type '{filterType.FullName}' must implement ITelegramFilter<TCont |
| | | 280 | | } |
| | | 281 | | |
| | 25 | 282 | | if (!SupportsContextType(contextTypes, expectedContextType)) |
| | | 283 | | { |
| | 0 | 284 | | throw new InvalidOperationException( |
| | 0 | 285 | | $"Generated custom Telegram filter type '{filterType.FullName}' is not compatible with {expectedCont |
| | | 286 | | } |
| | | 287 | | |
| | 25 | 288 | | return; |
| | | 289 | | } |
| | | 290 | | |
| | 0 | 291 | | var attributeType = attribute.GetType(); |
| | | 292 | | |
| | 0 | 293 | | if (attributeType.IsGenericType) |
| | | 294 | | { |
| | 0 | 295 | | throw new InvalidOperationException( |
| | 0 | 296 | | $"Generated custom Telegram filter attribute type '{attributeType.FullName}' must be non-generic."); |
| | | 297 | | } |
| | | 298 | | |
| | 0 | 299 | | var typedContextTypes = GetCustomFilterContextTypes(filterType, attributeType); |
| | | 300 | | |
| | 0 | 301 | | if (typedContextTypes.Length == 0) |
| | | 302 | | { |
| | 0 | 303 | | throw new InvalidOperationException( |
| | 0 | 304 | | $"Generated parameterized custom Telegram filter type '{filterType.FullName}' must implement ITelegramFi |
| | | 305 | | } |
| | | 306 | | |
| | 0 | 307 | | if (!SupportsContextType(typedContextTypes, expectedContextType)) |
| | | 308 | | { |
| | 0 | 309 | | throw new InvalidOperationException( |
| | 0 | 310 | | $"Generated custom Telegram filter type '{filterType.FullName}' is not compatible with {expectedContextT |
| | | 311 | | } |
| | 0 | 312 | | } |
| | | 313 | | |
| | | 314 | | private static Type[] GetCustomFilterContextTypes( |
| | | 315 | | Type filterType, |
| | | 316 | | Type? attributeType) |
| | | 317 | | { |
| | 25 | 318 | | var interfaces = filterType.GetInterfaces(); |
| | | 319 | | |
| | 25 | 320 | | if (attributeType is null) |
| | | 321 | | { |
| | 25 | 322 | | return interfaces |
| | 25 | 323 | | .Where(static type => type.IsGenericType && |
| | 25 | 324 | | type.GetGenericTypeDefinition() == typeof(ITelegramFilter<>)) |
| | 25 | 325 | | .Select(static type => type.GetGenericArguments()[0]) |
| | 25 | 326 | | .ToArray(); |
| | | 327 | | } |
| | | 328 | | |
| | 0 | 329 | | return interfaces |
| | 0 | 330 | | .Where(type => type.IsGenericType && |
| | 0 | 331 | | type.GetGenericTypeDefinition() == typeof(ITelegramFilter<,>) && |
| | 0 | 332 | | type.GetGenericArguments()[1] == attributeType) |
| | 0 | 333 | | .Select(static type => type.GetGenericArguments()[0]) |
| | 0 | 334 | | .ToArray(); |
| | | 335 | | } |
| | | 336 | | |
| | | 337 | | private static bool SupportsContextType( |
| | | 338 | | IReadOnlyCollection<Type> contextTypes, |
| | | 339 | | Type expectedContextType) |
| | | 340 | | { |
| | 25 | 341 | | return contextTypes.Contains(expectedContextType) || |
| | 25 | 342 | | contextTypes.Contains(typeof(TelegramUpdateContext)); |
| | | 343 | | } |
| | | 344 | | |
| | | 345 | | private static TelegramFilterKind MapFilterKind(TelegramGeneratedFilterKind kind) |
| | | 346 | | { |
| | 525 | 347 | | return kind switch |
| | 525 | 348 | | { |
| | 50 | 349 | | TelegramGeneratedFilterKind.ChatType => TelegramFilterKind.ChatType, |
| | 50 | 350 | | TelegramGeneratedFilterKind.ChatId => TelegramFilterKind.ChatId, |
| | 25 | 351 | | TelegramGeneratedFilterKind.ChatUsername => TelegramFilterKind.ChatUsername, |
| | 50 | 352 | | TelegramGeneratedFilterKind.FromUser => TelegramFilterKind.FromUser, |
| | 25 | 353 | | TelegramGeneratedFilterKind.HasText => TelegramFilterKind.HasText, |
| | 0 | 354 | | TelegramGeneratedFilterKind.HasPhoto => TelegramFilterKind.HasPhoto, |
| | 0 | 355 | | TelegramGeneratedFilterKind.HasDocument => TelegramFilterKind.HasDocument, |
| | 25 | 356 | | TelegramGeneratedFilterKind.HasCaption => TelegramFilterKind.HasCaption, |
| | 0 | 357 | | TelegramGeneratedFilterKind.HasVideo => TelegramFilterKind.HasVideo, |
| | 0 | 358 | | TelegramGeneratedFilterKind.HasAnimation => TelegramFilterKind.HasAnimation, |
| | 0 | 359 | | TelegramGeneratedFilterKind.HasAudio => TelegramFilterKind.HasAudio, |
| | 0 | 360 | | TelegramGeneratedFilterKind.HasVoice => TelegramFilterKind.HasVoice, |
| | 0 | 361 | | TelegramGeneratedFilterKind.HasVideoNote => TelegramFilterKind.HasVideoNote, |
| | 0 | 362 | | TelegramGeneratedFilterKind.HasSticker => TelegramFilterKind.HasSticker, |
| | 0 | 363 | | TelegramGeneratedFilterKind.HasContact => TelegramFilterKind.HasContact, |
| | 0 | 364 | | TelegramGeneratedFilterKind.HasLocation => TelegramFilterKind.HasLocation, |
| | 0 | 365 | | TelegramGeneratedFilterKind.HasVenue => TelegramFilterKind.HasVenue, |
| | 0 | 366 | | TelegramGeneratedFilterKind.HasPoll => TelegramFilterKind.HasPoll, |
| | 0 | 367 | | TelegramGeneratedFilterKind.HasDice => TelegramFilterKind.HasDice, |
| | 25 | 368 | | TelegramGeneratedFilterKind.FromBot => TelegramFilterKind.FromBot, |
| | 0 | 369 | | TelegramGeneratedFilterKind.FromPremiumUser => TelegramFilterKind.FromPremiumUser, |
| | 0 | 370 | | TelegramGeneratedFilterKind.IsReply => TelegramFilterKind.IsReply, |
| | 0 | 371 | | TelegramGeneratedFilterKind.ReplyToBot => TelegramFilterKind.ReplyToBot, |
| | 25 | 372 | | TelegramGeneratedFilterKind.MessageThreadId => TelegramFilterKind.MessageThreadId, |
| | 25 | 373 | | TelegramGeneratedFilterKind.HasMessageThread => TelegramFilterKind.HasMessageThread, |
| | 25 | 374 | | TelegramGeneratedFilterKind.HasCallbackData => TelegramFilterKind.HasCallbackData, |
| | 175 | 375 | | TelegramGeneratedFilterKind.CallbackDataPrefix => TelegramFilterKind.CallbackDataPrefix, |
| | 25 | 376 | | TelegramGeneratedFilterKind.SenderChatType => TelegramFilterKind.SenderChatType, |
| | 0 | 377 | | TelegramGeneratedFilterKind.Custom => throw new InvalidOperationException("Custom generated Telegram filters |
| | 0 | 378 | | _ => throw new InvalidOperationException($"Unsupported generated Telegram filter kind '{kind}'.") |
| | 525 | 379 | | }; |
| | | 380 | | } |
| | | 381 | | |
| | | 382 | | private static TelegramHandlerParameterKind MapParameterKind(TelegramGeneratedHandlerParameterKind kind) |
| | | 383 | | { |
| | 1709 | 384 | | return kind switch |
| | 1709 | 385 | | { |
| | 832 | 386 | | TelegramGeneratedHandlerParameterKind.Context => TelegramHandlerParameterKind.Context, |
| | 26 | 387 | | TelegramGeneratedHandlerParameterKind.CallbackPayload => TelegramHandlerParameterKind.CallbackPayload, |
| | 75 | 388 | | TelegramGeneratedHandlerParameterKind.RouteValue => TelegramHandlerParameterKind.RouteValue, |
| | 776 | 389 | | TelegramGeneratedHandlerParameterKind.Service => TelegramHandlerParameterKind.Service, |
| | 0 | 390 | | TelegramGeneratedHandlerParameterKind.CancellationToken => TelegramHandlerParameterKind.CancellationToken, |
| | 0 | 391 | | _ => throw new InvalidOperationException($"Unsupported generated Telegram handler parameter kind '{kind}'.") |
| | 1709 | 392 | | }; |
| | | 393 | | } |
| | | 394 | | |
| | | 395 | | private static TelegramErrorHandlerParameterKind MapErrorParameterKind(TelegramGeneratedErrorHandlerParameterKind ki |
| | | 396 | | { |
| | 256 | 397 | | return kind switch |
| | 256 | 398 | | { |
| | 26 | 399 | | TelegramGeneratedErrorHandlerParameterKind.ErrorContext => TelegramErrorHandlerParameterKind.ErrorContext, |
| | 26 | 400 | | TelegramGeneratedErrorHandlerParameterKind.TelegramContext => TelegramErrorHandlerParameterKind.TelegramCont |
| | 102 | 401 | | TelegramGeneratedErrorHandlerParameterKind.Exception => TelegramErrorHandlerParameterKind.Exception, |
| | 0 | 402 | | TelegramGeneratedErrorHandlerParameterKind.RouteValue => TelegramErrorHandlerParameterKind.RouteValue, |
| | 101 | 403 | | TelegramGeneratedErrorHandlerParameterKind.Service => TelegramErrorHandlerParameterKind.Service, |
| | 1 | 404 | | TelegramGeneratedErrorHandlerParameterKind.CancellationToken => TelegramErrorHandlerParameterKind.Cancellati |
| | 0 | 405 | | _ => throw new InvalidOperationException($"Unsupported generated Telegram error handler parameter kind '{kin |
| | 256 | 406 | | }; |
| | | 407 | | } |
| | | 408 | | } |