4 Commits

Author SHA1 Message Date
Rikitav 3d2d21f6c0 * Added building delegate to UseTelegrator method
* Fixed Webhooker trying to resolve IEndpointRouteBuildr from DI
2026-03-15 17:20:53 +04:00
Rikitav 0dedd3c0f4 * warnings fixes 2026-03-09 13:40:58 +04:00
Rikitav 79d5df8291 * Syntaxual refactoring 2026-03-09 13:23:21 +04:00
Rikitav 899243c62b * Added default state storage registering
* Added extension method for replacing default state storage
2026-03-09 13:10:49 +04:00
146 changed files with 9860 additions and 9893 deletions
@@ -148,6 +148,7 @@ public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
.AddMembers([.. targetters.Values, .. extensions]); .AddMembers([.. targetters.Values, .. extensions]);
NamespaceDeclarationSyntax namespaceDeclaration = SyntaxFactory.NamespaceDeclaration(SyntaxFactory.ParseName("Telegrator")) NamespaceDeclarationSyntax namespaceDeclaration = SyntaxFactory.NamespaceDeclaration(SyntaxFactory.ParseName("Telegrator"))
.WithLeadingTrivia(SyntaxFactory.ParseLeadingTrivia("#pragma warning disable CS1591"))
.WithMembers([extensionsClass]); .WithMembers([extensionsClass]);
CompilationUnitSyntax compilationUnit = SyntaxFactory.CompilationUnit() CompilationUnitSyntax compilationUnit = SyntaxFactory.CompilationUnit()
+22 -3
View File
@@ -28,6 +28,9 @@
This application's logger This application's logger
</summary> </summary>
</member> </member>
<member name="P:Telegrator.Hosting.Web.TelegramBotWebHost.Properties">
<inheritdoc/>
</member>
<member name="M:Telegrator.Hosting.Web.TelegramBotWebHost.#ctor(Microsoft.AspNetCore.Builder.WebApplicationBuilder)"> <member name="M:Telegrator.Hosting.Web.TelegramBotWebHost.#ctor(Microsoft.AspNetCore.Builder.WebApplicationBuilder)">
<summary> <summary>
Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.Builder.WebApplicationBuilder"/> class. Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.Builder.WebApplicationBuilder"/> class.
@@ -181,7 +184,7 @@
Service for receiving updates for Hosted telegram bots via Webhooks Service for receiving updates for Hosted telegram bots via Webhooks
</summary> </summary>
</member> </member>
<member name="M:Telegrator.Mediation.HostedUpdateWebhooker.#ctor(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder,Telegram.Bot.ITelegramBotClient,Telegrator.Core.IUpdateRouter,Microsoft.Extensions.Options.IOptions{Telegrator.Hosting.Web.WebhookerOptions})"> <member name="M:Telegrator.Mediation.HostedUpdateWebhooker.#ctor(Telegram.Bot.ITelegramBotClient,Telegrator.Core.IUpdateRouter,Microsoft.Extensions.Options.IOptions{Telegrator.Hosting.Web.WebhookerOptions})">
<summary> <summary>
Initiallizes new instance of <see cref="T:Telegrator.Mediation.HostedUpdateWebhooker"/> Initiallizes new instance of <see cref="T:Telegrator.Mediation.HostedUpdateWebhooker"/>
</summary> </summary>
@@ -197,6 +200,12 @@
<member name="M:Telegrator.Mediation.HostedUpdateWebhooker.StopAsync(System.Threading.CancellationToken)"> <member name="M:Telegrator.Mediation.HostedUpdateWebhooker.StopAsync(System.Threading.CancellationToken)">
<inheritdoc/> <inheritdoc/>
</member> </member>
<member name="M:Telegrator.Mediation.HostedUpdateWebhooker.MapWebhook(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder)">
<summary>
Maps bot webhook to application builder
</summary>
<param name="routeBuilder"></param>
</member>
<member name="T:Telegrator.ServicesCollectionExtensions"> <member name="T:Telegrator.ServicesCollectionExtensions">
<summary> <summary>
Contains extensions for <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection"/> Contains extensions for <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection"/>
@@ -211,12 +220,22 @@
<member name="M:Telegrator.ServicesCollectionExtensions.get_Handlers(Microsoft.AspNetCore.Builder.WebApplicationBuilder)"> <member name="M:Telegrator.ServicesCollectionExtensions.get_Handlers(Microsoft.AspNetCore.Builder.WebApplicationBuilder)">
<inheritdoc cref="P:Telegrator.ServicesCollectionExtensions.&lt;G&gt;$41F16C2D39AF52899E745C9C9F42FF83.Handlers"/> <inheritdoc cref="P:Telegrator.ServicesCollectionExtensions.&lt;G&gt;$41F16C2D39AF52899E745C9C9F42FF83.Handlers"/>
</member> </member>
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegratorWeb(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection)"> <member name="M:Telegrator.ServicesCollectionExtensions.AddTelegratorWeb(Telegrator.Hosting.ITelegramBotHostBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection,System.Action{Telegrator.Hosting.ITelegramBotHostBuilder})">
<summary> <summary>
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers. Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
</summary> </summary>
</member> </member>
<member name="M:Telegrator.ServicesCollectionExtensions.UseTelegratorWeb(Microsoft.AspNetCore.Builder.WebApplication)"> <member name="M:Telegrator.ServicesCollectionExtensions.AddTelegratorWeb(Microsoft.AspNetCore.Builder.WebApplicationBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection,System.Action{Telegrator.Hosting.ITelegramBotHostBuilder})">
<summary>
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
</summary>
</member>
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegratorWebInternal(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection)">
<summary>
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
</summary>
</member>
<member name="M:Telegrator.ServicesCollectionExtensions.UseTelegratorWeb``1(``0)">
<summary> <summary>
Replaces the initialization logic from TelegramBotWebHost constructor. Replaces the initialization logic from TelegramBotWebHost constructor.
Initializes the bot and logs handlers on application startup. Initializes the bot and logs handlers on application startup.
+25 -7
View File
@@ -221,7 +221,7 @@
<member name="T:Telegrator.Providers.HostAwaitingProvider"> <member name="T:Telegrator.Providers.HostAwaitingProvider">
<inheritdoc/> <inheritdoc/>
</member> </member>
<member name="M:Telegrator.Providers.HostAwaitingProvider.#ctor(Microsoft.Extensions.Options.IOptions{Telegrator.TelegratorOptions},Microsoft.Extensions.Logging.ILogger{Telegrator.Providers.HostAwaitingProvider})"> <member name="M:Telegrator.Providers.HostAwaitingProvider.#ctor(Microsoft.Extensions.Options.IOptions{Telegrator.TelegratorOptions})">
<inheritdoc/> <inheritdoc/>
</member> </member>
<member name="T:Telegrator.Providers.HostHandlersCollection"> <member name="T:Telegrator.Providers.HostHandlersCollection">
@@ -239,7 +239,7 @@
<member name="T:Telegrator.Providers.HostHandlersProvider"> <member name="T:Telegrator.Providers.HostHandlersProvider">
<inheritdoc/> <inheritdoc/>
</member> </member>
<member name="M:Telegrator.Providers.HostHandlersProvider.#ctor(Telegrator.Core.IHandlersCollection,Microsoft.Extensions.Options.IOptions{Telegrator.TelegratorOptions},System.IServiceProvider,Microsoft.Extensions.Logging.ILogger{Telegrator.Providers.HostHandlersProvider})"> <member name="M:Telegrator.Providers.HostHandlersProvider.#ctor(Telegrator.Core.IHandlersCollection,Microsoft.Extensions.Options.IOptions{Telegrator.TelegratorOptions},System.IServiceProvider)">
<inheritdoc/> <inheritdoc/>
</member> </member>
<member name="M:Telegrator.Providers.HostHandlersProvider.GetHandlerInstance(Telegrator.Core.Descriptors.HandlerDescriptor,System.Threading.CancellationToken)"> <member name="M:Telegrator.Providers.HostHandlersProvider.GetHandlerInstance(Telegrator.Core.Descriptors.HandlerDescriptor,System.Threading.CancellationToken)">
@@ -255,15 +255,25 @@
The key used to store the <see cref="T:Telegrator.Core.IHandlersCollection"/> in the builder properties. The key used to store the <see cref="T:Telegrator.Core.IHandlersCollection"/> in the builder properties.
</summary> </summary>
</member> </member>
<member name="M:Telegrator.HostBuilderExtensions.get_Handlers(Microsoft.Extensions.Hosting.IHostApplicationBuilder)"> <member name="M:Telegrator.HostBuilderExtensions.get_Handlers(Microsoft.Extensions.Hosting.HostApplicationBuilder)">
<inheritdoc cref="P:Telegrator.HostBuilderExtensions.&lt;G&gt;$605D8CCF64349EA050C790D67C500BD9.Handlers"/> <inheritdoc cref="P:Telegrator.HostBuilderExtensions.&lt;G&gt;$BF7227490CCA365283B3A9274C9033C7.Handlers"/>
</member> </member>
<member name="M:Telegrator.HostBuilderExtensions.AddTelegrator(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection)"> <member name="M:Telegrator.HostBuilderExtensions.AddTelegrator(Telegrator.Hosting.ITelegramBotHostBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection,System.Action{Telegrator.Hosting.ITelegramBotHostBuilder})">
<summary> <summary>
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers. Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
</summary> </summary>
</member> </member>
<member name="P:Telegrator.HostBuilderExtensions.&lt;G&gt;$605D8CCF64349EA050C790D67C500BD9.Handlers"> <member name="M:Telegrator.HostBuilderExtensions.AddTelegrator(Microsoft.Extensions.Hosting.HostApplicationBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection,System.Action{Telegrator.Hosting.ITelegramBotHostBuilder})">
<summary>
Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
</summary>
</member>
<member name="M:Telegrator.HostBuilderExtensions.AddTelegratorInternal(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection)">
<summary>
Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
</summary>
</member>
<member name="P:Telegrator.HostBuilderExtensions.&lt;G&gt;$BF7227490CCA365283B3A9274C9033C7.Handlers">
<summary> <summary>
Gets the <see cref="T:Telegrator.Core.IHandlersCollection"/> from the builder properties. Gets the <see cref="T:Telegrator.Core.IHandlersCollection"/> from the builder properties.
</summary> </summary>
@@ -274,6 +284,14 @@
Provides method to configure Telegram Bot Host Provides method to configure Telegram Bot Host
</summary> </summary>
</member> </member>
<member name="M:Telegrator.ServicesCollectionExtensions.AddStateStorage``1(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
<summary>
Registers <see cref="T:Telegrator.Core.States.IStateStorage"/> service
</summary>
<typeparam name="TStorage"></typeparam>
<param name="services"></param>
<returns></returns>
</member>
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegramBotHostDefaults(Microsoft.Extensions.DependencyInjection.IServiceCollection)"> <member name="M:Telegrator.ServicesCollectionExtensions.AddTelegramBotHostDefaults(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
<summary> <summary>
Registers <see cref="T:Telegrator.Hosting.TelegramBotHost"/> default services Registers <see cref="T:Telegrator.Hosting.TelegramBotHost"/> default services
+5
View File
@@ -7161,6 +7161,11 @@
Provides extension methods for working with Telegram Update objects. Provides extension methods for working with Telegram Update objects.
</summary> </summary>
</member> </member>
<member name="M:Telegrator.UpdateExtensions.GetUserLanguageCode(Telegram.Bot.Types.Update)">
<summary>
Extracts the IETF language tag of the user's client from the update.
</summary>
</member>
<member name="M:Telegrator.UpdateExtensions.GetSenderId(Telegram.Bot.Types.Update)"> <member name="M:Telegrator.UpdateExtensions.GetSenderId(Telegram.Bot.Types.Update)">
<summary> <summary>
Selects from Update an object from which you can get the sender's ID Selects from Update an object from which you can get the sender's ID
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
@@ -15,7 +15,7 @@
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild> <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<Title>Telegrator.RedisStateStorage</Title> <Title>Telegrator.RedisStateStorage</Title>
<Version>1.16.4</Version> <Version>1.16.6</Version>
<Authors>Rikitav Tim4ik</Authors> <Authors>Rikitav Tim4ik</Authors>
<Company>Rikitav Tim4ik</Company> <Company>Rikitav Tim4ik</Company>
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl> <RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
@@ -9,3 +9,4 @@ using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Style", "IDE0090")] [assembly: SuppressMessage("Style", "IDE0090")]
[assembly: SuppressMessage("Usage", "CA2254")] [assembly: SuppressMessage("Usage", "CA2254")]
[assembly: SuppressMessage("Maintainability", "CA1510")] [assembly: SuppressMessage("Maintainability", "CA1510")]
[assembly: SuppressMessage("Style", "IDE0270")]
@@ -7,8 +7,8 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Telegrator.Core; using Telegrator.Core;
namespace Telegrator.Hosting.Web namespace Telegrator.Hosting.Web;
{
/// <summary> /// <summary>
/// Represents a web hosted telegram bot /// Represents a web hosted telegram bot
/// </summary> /// </summary>
@@ -39,11 +39,13 @@ namespace Telegrator.Hosting.Web
/// </summary> /// </summary>
public ILogger<TelegramBotWebHost> Logger => _logger; public ILogger<TelegramBotWebHost> Logger => _logger;
/// <inheritdoc/>
public IDictionary<string, object?> Properties => ((IApplicationBuilder)_innerApp).Properties;
// Private interface fields // Private interface fields
IServiceProvider IEndpointRouteBuilder.ServiceProvider => Services; IServiceProvider IEndpointRouteBuilder.ServiceProvider => Services;
IServiceProvider IApplicationBuilder.ApplicationServices { get => Services; set => throw new NotImplementedException(); } IServiceProvider IApplicationBuilder.ApplicationServices { get => Services; set => throw new NotImplementedException(); }
IFeatureCollection IApplicationBuilder.ServerFeatures => ((IApplicationBuilder)_innerApp).ServerFeatures; IFeatureCollection IApplicationBuilder.ServerFeatures => ((IApplicationBuilder)_innerApp).ServerFeatures;
IDictionary<string, object?> IApplicationBuilder.Properties => ((IApplicationBuilder)_innerApp).Properties;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WebApplicationBuilder"/> class. /// Initializes a new instance of the <see cref="WebApplicationBuilder"/> class.
@@ -68,9 +70,7 @@ namespace Telegrator.Hosting.Web
ArgumentNullException.ThrowIfNull(settings, nameof(settings)); ArgumentNullException.ThrowIfNull(settings, nameof(settings));
WebApplicationBuilder innerApp = WebApplication.CreateBuilder(settings); WebApplicationBuilder innerApp = WebApplication.CreateBuilder(settings);
TelegramBotWebHostBuilder builder = new TelegramBotWebHostBuilder(innerApp, settings); TelegramBotWebHostBuilder builder = new TelegramBotWebHostBuilder(innerApp, settings);
builder.AddTelegratorWeb();
builder.Services.AddTelegramBotHostDefaults();
builder.Services.AddTelegramWebhook();
return builder; return builder;
} }
@@ -83,9 +83,7 @@ namespace Telegrator.Hosting.Web
ArgumentNullException.ThrowIfNull(settings, nameof(settings)); ArgumentNullException.ThrowIfNull(settings, nameof(settings));
WebApplicationBuilder innerApp = WebApplication.CreateSlimBuilder(settings); WebApplicationBuilder innerApp = WebApplication.CreateSlimBuilder(settings);
TelegramBotWebHostBuilder builder = new TelegramBotWebHostBuilder(innerApp, settings); TelegramBotWebHostBuilder builder = new TelegramBotWebHostBuilder(innerApp, settings);
builder.AddTelegratorWeb();
builder.Services.AddTelegramBotHostDefaults();
builder.Services.AddTelegramWebhook();
return builder; return builder;
} }
@@ -97,7 +95,9 @@ namespace Telegrator.Hosting.Web
{ {
ArgumentNullException.ThrowIfNull(settings, nameof(settings)); ArgumentNullException.ThrowIfNull(settings, nameof(settings));
WebApplicationBuilder innerApp = WebApplication.CreateEmptyBuilder(settings); WebApplicationBuilder innerApp = WebApplication.CreateEmptyBuilder(settings);
return new TelegramBotWebHostBuilder(innerApp, settings); TelegramBotWebHostBuilder builder = new TelegramBotWebHostBuilder(innerApp, settings);
builder.AddTelegratorWeb();
return builder;
} }
/// <inheritdoc/> /// <inheritdoc/>
@@ -157,4 +157,3 @@ namespace Telegrator.Hosting.Web
_disposed = true; _disposed = true;
} }
} }
}
@@ -7,12 +7,12 @@ using Microsoft.Extensions.Logging;
using Telegrator.Core; using Telegrator.Core;
#pragma warning disable IDE0001 #pragma warning disable IDE0001
namespace Telegrator.Hosting.Web namespace Telegrator.Hosting.Web;
{
/// <summary> /// <summary>
/// Represents a web hosted telegram bots and services builder that helps manage configuration, logging, lifetime, and more. /// Represents a web hosted telegram bots and services builder that helps manage configuration, logging, lifetime, and more.
/// </summary> /// </summary>
public class TelegramBotWebHostBuilder : IHostApplicationBuilder, ICollectingProvider public class TelegramBotWebHostBuilder : ITelegramBotHostBuilder
{ {
private readonly WebApplicationBuilder _innerBuilder; private readonly WebApplicationBuilder _innerBuilder;
private readonly WebApplicationOptions _settings; private readonly WebApplicationOptions _settings;
@@ -48,8 +48,6 @@ namespace Telegrator.Hosting.Web
{ {
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder)); _innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
_settings = settings ?? throw new ArgumentNullException(nameof(settings)); _settings = settings ?? throw new ArgumentNullException(nameof(settings));
this.AddTelegratorWeb();
} }
/// <summary> /// <summary>
@@ -62,8 +60,6 @@ namespace Telegrator.Hosting.Web
{ {
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder)); _innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
_settings = settings ?? throw new ArgumentNullException(nameof(settings)); _settings = settings ?? throw new ArgumentNullException(nameof(settings));
this.AddTelegratorWeb(options, null);
} }
/// <summary> /// <summary>
@@ -76,8 +72,6 @@ namespace Telegrator.Hosting.Web
{ {
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder)); _innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
_settings = settings ?? throw new ArgumentNullException(nameof(settings)); _settings = settings ?? throw new ArgumentNullException(nameof(settings));
this.AddTelegratorWeb(null, handlers);
} }
/// <summary> /// <summary>
@@ -91,8 +85,6 @@ namespace Telegrator.Hosting.Web
{ {
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder)); _innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
_settings = settings ?? throw new ArgumentNullException(nameof(settings)); _settings = settings ?? throw new ArgumentNullException(nameof(settings));
this.AddTelegratorWeb(options, handlers);
} }
/// <summary> /// <summary>
@@ -112,4 +104,3 @@ namespace Telegrator.Hosting.Web
((IHostApplicationBuilder)_innerBuilder).ConfigureContainer(factory, configure); ((IHostApplicationBuilder)_innerBuilder).ConfigureContainer(factory, configure);
} }
} }
}
@@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
namespace Telegrator.Hosting.Web namespace Telegrator.Hosting.Web;
{
/// <summary> /// <summary>
/// Configuration options for Telegram bot behavior and execution settings. /// Configuration options for Telegram bot behavior and execution settings.
/// Controls various aspects of bot operation including concurrency, routing, webhook receiving, and execution policies. /// Controls various aspects of bot operation including concurrency, routing, webhook receiving, and execution policies.
@@ -32,4 +32,3 @@ namespace Telegrator.Hosting.Web
/// </summary> /// </summary>
public bool DropPendingUpdates { get; set; } = false; public bool DropPendingUpdates { get; set; } = false;
} }
}
@@ -10,8 +10,8 @@ using Telegram.Bot.Types;
using Telegrator.Core; using Telegrator.Core;
using Telegrator.Hosting.Web; using Telegrator.Hosting.Web;
namespace Telegrator.Mediation namespace Telegrator.Mediation;
{
/// <summary> /// <summary>
/// Service for receiving updates for Hosted telegram bots via Webhooks /// Service for receiving updates for Hosted telegram bots via Webhooks
/// </summary> /// </summary>
@@ -19,7 +19,6 @@ namespace Telegrator.Mediation
{ {
private const string SecretTokenHeader = "X-Telegram-Bot-Api-Secret-Token"; private const string SecretTokenHeader = "X-Telegram-Bot-Api-Secret-Token";
private readonly IEndpointRouteBuilder _botHost;
private readonly ITelegramBotClient _botClient; private readonly ITelegramBotClient _botClient;
private readonly IUpdateRouter _updateRouter; private readonly IUpdateRouter _updateRouter;
private readonly WebhookerOptions _options; private readonly WebhookerOptions _options;
@@ -32,12 +31,11 @@ namespace Telegrator.Mediation
/// <param name="updateRouter"></param> /// <param name="updateRouter"></param>
/// <param name="options"></param> /// <param name="options"></param>
/// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentNullException"></exception>
public HostedUpdateWebhooker(IEndpointRouteBuilder botHost, ITelegramBotClient botClient, IUpdateRouter updateRouter, IOptions<WebhookerOptions> options) public HostedUpdateWebhooker(ITelegramBotClient botClient, IUpdateRouter updateRouter, IOptions<WebhookerOptions> options)
{ {
if (string.IsNullOrEmpty(options.Value.WebhookUri)) if (string.IsNullOrEmpty(options.Value.WebhookUri))
throw new ArgumentNullException(nameof(options), "Option \"WebhookUrl\" must be set to subscribe for update recieving"); throw new ArgumentNullException(nameof(options), "Option \"WebhookUrl\" must be set to subscribe for update recieving");
_botHost = botHost;
_botClient = botClient; _botClient = botClient;
_updateRouter = updateRouter; _updateRouter = updateRouter;
_options = options.Value; _options = options.Value;
@@ -52,9 +50,6 @@ namespace Telegrator.Mediation
private async void StartInternal(CancellationToken cancellationToken) private async void StartInternal(CancellationToken cancellationToken)
{ {
string pattern = new UriBuilder(_options.WebhookUri).Path;
_botHost.MapPost(pattern, (Delegate)ReceiveUpdate);
await _botClient.SetWebhook( await _botClient.SetWebhook(
url: _options.WebhookUri, url: _options.WebhookUri,
maxConnections: _options.MaxConnections, maxConnections: _options.MaxConnections,
@@ -71,6 +66,16 @@ namespace Telegrator.Mediation
return Task.CompletedTask; return Task.CompletedTask;
} }
/// <summary>
/// Maps bot webhook to application builder
/// </summary>
/// <param name="routeBuilder"></param>
public void MapWebhook(IEndpointRouteBuilder routeBuilder)
{
string pattern = new UriBuilder(_options.WebhookUri).Path;
routeBuilder.MapPost(pattern, (Delegate)ReceiveUpdate);
}
private async Task<IResult> ReceiveUpdate(HttpContext ctx) private async Task<IResult> ReceiveUpdate(HttpContext ctx)
{ {
if (_options.SecretToken != null) if (_options.SecretToken != null)
@@ -94,4 +99,3 @@ namespace Telegrator.Mediation
return Results.Ok(); return Results.Ok();
} }
} }
}
@@ -15,7 +15,7 @@
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild> <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<Title>Telegrator.Hosting.Web</Title> <Title>Telegrator.Hosting.Web</Title>
<Version>1.16.4</Version> <Version>1.16.6</Version>
<Authors>Rikitav Tim4ik</Authors> <Authors>Rikitav Tim4ik</Authors>
<Company>Rikitav Tim4ik</Company> <Company>Rikitav Tim4ik</Company>
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl> <RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
+28 -5
View File
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -42,7 +43,27 @@ namespace Telegrator
/// <summary> /// <summary>
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers. /// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
/// </summary> /// </summary>
public static IHostApplicationBuilder AddTelegratorWeb(this IHostApplicationBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null) public static ITelegramBotHostBuilder AddTelegratorWeb(this ITelegramBotHostBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null, Action<ITelegramBotHostBuilder>? action = null)
{
builder.AddTelegratorWebInternal(options, handlers);
action?.Invoke(builder);
return builder;
}
/// <summary>
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
/// </summary>
public static IHostApplicationBuilder AddTelegratorWeb(this WebApplicationBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null, Action<ITelegramBotHostBuilder>? action = null)
{
builder.AddTelegratorWebInternal(options, handlers);
action?.Invoke(new TelegramBotWebHostBuilder(builder));
return builder;
}
/// <summary>
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
/// </summary>
internal static IHostApplicationBuilder AddTelegratorWebInternal(this IHostApplicationBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null)
{ {
IServiceCollection services = builder.Services; IServiceCollection services = builder.Services;
IConfigurationManager configuration = builder.Configuration; IConfigurationManager configuration = builder.Configuration;
@@ -103,11 +124,12 @@ namespace Telegrator
/// Replaces the initialization logic from TelegramBotWebHost constructor. /// Replaces the initialization logic from TelegramBotWebHost constructor.
/// Initializes the bot and logs handlers on application startup. /// Initializes the bot and logs handlers on application startup.
/// </summary> /// </summary>
public static WebApplication UseTelegratorWeb(this WebApplication app) public static T UseTelegratorWeb<T>(this T app) where T : IEndpointRouteBuilder, IHost
{ {
ITelegramBotInfo info = app.Services.GetRequiredService<ITelegramBotInfo>(); HostedUpdateWebhooker webhooker = app.ServiceProvider.GetRequiredService<HostedUpdateWebhooker>();
IHandlersCollection handlers = app.Services.GetRequiredService<IHandlersCollection>(); ITelegramBotInfo info = app.ServiceProvider.GetRequiredService<ITelegramBotInfo>();
ILoggerFactory loggerFactory = app.Services.GetRequiredService<ILoggerFactory>(); IHandlersCollection handlers = app.ServiceProvider.GetRequiredService<IHandlersCollection>();
ILoggerFactory loggerFactory = app.ServiceProvider.GetRequiredService<ILoggerFactory>();
ILogger logger = loggerFactory.CreateLogger("Telegrator.Hosting.Web.TelegratorHost"); ILogger logger = loggerFactory.CreateLogger("Telegrator.Hosting.Web.TelegratorHost");
if (logger.IsEnabled(LogLevel.Information)) if (logger.IsEnabled(LogLevel.Information))
@@ -117,6 +139,7 @@ namespace Telegrator
logger.LogHandlers(handlers); logger.LogHandlers(handlers);
} }
webhooker.MapWebhook(app);
return app; return app;
} }
@@ -9,3 +9,4 @@ using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Style", "IDE0090")] [assembly: SuppressMessage("Style", "IDE0090")]
[assembly: SuppressMessage("Usage", "CA2254")] [assembly: SuppressMessage("Usage", "CA2254")]
[assembly: SuppressMessage("Maintainability", "CA1510")] [assembly: SuppressMessage("Maintainability", "CA1510")]
[assembly: SuppressMessage("Style", "IDE0270")]
@@ -3,8 +3,8 @@ using Telegram.Bot;
using Telegram.Bot.Types; using Telegram.Bot.Types;
using Telegrator.Core; using Telegrator.Core;
namespace Telegrator.Hosting namespace Telegrator.Hosting;
{
/// <summary> /// <summary>
/// Implementation of <see cref="ITelegramBotInfo"/> that provides bot information. /// Implementation of <see cref="ITelegramBotInfo"/> that provides bot information.
/// Contains metadata about the Telegram bot including user details and service provider for wider filterring abilities /// Contains metadata about the Telegram bot including user details and service provider for wider filterring abilities
@@ -27,4 +27,3 @@ namespace Telegrator.Hosting
/// </summary> /// </summary>
public IConfiguration Configuration { get; } = configuration; public IConfiguration Configuration { get; } = configuration;
} }
}
@@ -0,0 +1,12 @@
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Text;
using Telegrator.Core;
namespace Telegrator.Hosting;
public interface ITelegramBotHostBuilder : IHostApplicationBuilder, ICollectingProvider
{
}
@@ -3,8 +3,8 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Telegrator.Core; using Telegrator.Core;
namespace Telegrator.Hosting namespace Telegrator.Hosting;
{
/// <summary> /// <summary>
/// Represents a hosted telegram bot /// Represents a hosted telegram bot
/// </summary> /// </summary>
@@ -112,4 +112,3 @@ namespace Telegrator.Hosting
_disposed = true; _disposed = true;
} }
} }
}
@@ -3,17 +3,15 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.Metrics; using Microsoft.Extensions.Diagnostics.Metrics;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Telegrator.Core; using Telegrator.Core;
using Telegrator.Providers;
#pragma warning disable IDE0001 #pragma warning disable IDE0001
namespace Telegrator.Hosting namespace Telegrator.Hosting;
{
/// <summary> /// <summary>
/// Represents a hosted telegram bots and services builder that helps manage configuration, logging, lifetime, and more. /// Represents a hosted telegram bots and services builder that helps manage configuration, logging, lifetime, and more.
/// </summary> /// </summary>
public class TelegramBotHostBuilder : IHostApplicationBuilder, ICollectingProvider public class TelegramBotHostBuilder : ITelegramBotHostBuilder
{ {
private readonly HostApplicationBuilder _innerBuilder; private readonly HostApplicationBuilder _innerBuilder;
private readonly HostApplicationBuilderSettings _settings; private readonly HostApplicationBuilderSettings _settings;
@@ -49,8 +47,6 @@ namespace Telegrator.Hosting
{ {
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder)); _innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
_settings = settings ?? new HostApplicationBuilderSettings(); _settings = settings ?? new HostApplicationBuilderSettings();
this.AddTelegrator();
} }
/// <summary> /// <summary>
@@ -63,8 +59,6 @@ namespace Telegrator.Hosting
{ {
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder)); _innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
_settings = settings ?? new HostApplicationBuilderSettings(); _settings = settings ?? new HostApplicationBuilderSettings();
this.AddTelegrator(options, null);
} }
/// <summary> /// <summary>
@@ -77,8 +71,6 @@ namespace Telegrator.Hosting
{ {
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder)); _innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
_settings = settings ?? new HostApplicationBuilderSettings(); _settings = settings ?? new HostApplicationBuilderSettings();
this.AddTelegrator(null, handlers);
} }
/// <summary> /// <summary>
@@ -92,8 +84,6 @@ namespace Telegrator.Hosting
{ {
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder)); _innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
_settings = settings ?? new HostApplicationBuilderSettings(); _settings = settings ?? new HostApplicationBuilderSettings();
this.AddTelegrator(options, handlers);
} }
/// <summary> /// <summary>
@@ -110,7 +100,6 @@ namespace Telegrator.Hosting
/// <inheritdoc/> /// <inheritdoc/>
public void ConfigureContainer<TContainerBuilder>(IServiceProviderFactory<TContainerBuilder> factory, Action<TContainerBuilder>? configure = null) where TContainerBuilder : notnull public void ConfigureContainer<TContainerBuilder>(IServiceProviderFactory<TContainerBuilder> factory, Action<TContainerBuilder>? configure = null) where TContainerBuilder : notnull
{ {
this.ConfigureContainer(factory, configure); _innerBuilder.ConfigureContainer(factory, configure);
}
} }
} }
@@ -1,20 +1,18 @@
using Microsoft.Extensions.Logging; namespace Telegrator.Logging;
namespace Telegrator.Logging
{
/// <summary> /// <summary>
/// Adapter for Microsoft.Extensions.Logging to work with Telegrator logging system. /// Adapter for Microsoft.Extensions.Logging to work with Telegrator logging system.
/// This allows seamless integration with ASP.NET Core logging infrastructure. /// This allows seamless integration with ASP.NET Core logging infrastructure.
/// </summary> /// </summary>
public class MicrosoftLoggingAdapter : ITelegratorLogger public class MicrosoftLoggingAdapter : ITelegratorLogger
{ {
private readonly ILogger _logger; private readonly Microsoft.Extensions.Logging.ILogger _logger;
/// <summary> /// <summary>
/// Initializes a new instance of MicrosoftLoggingAdapter. /// Initializes a new instance of MicrosoftLoggingAdapter.
/// </summary> /// </summary>
/// <param name="logger">The Microsoft.Extensions.Logging logger instance.</param> /// <param name="logger">The Microsoft.Extensions.Logging logger instance.</param>
public MicrosoftLoggingAdapter(ILogger logger) public MicrosoftLoggingAdapter(Microsoft.Extensions.Logging.ILogger logger)
{ {
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); _logger = logger ?? throw new ArgumentNullException(nameof(logger));
} }
@@ -24,11 +22,11 @@ namespace Telegrator.Logging
{ {
var msLogLevel = level switch var msLogLevel = level switch
{ {
Telegrator.Logging.LogLevel.Trace => Microsoft.Extensions.Logging.LogLevel.Trace, LogLevel.Trace => Microsoft.Extensions.Logging.LogLevel.Trace,
Telegrator.Logging.LogLevel.Debug => Microsoft.Extensions.Logging.LogLevel.Debug, LogLevel.Debug => Microsoft.Extensions.Logging.LogLevel.Debug,
Telegrator.Logging.LogLevel.Information => Microsoft.Extensions.Logging.LogLevel.Information, LogLevel.Information => Microsoft.Extensions.Logging.LogLevel.Information,
Telegrator.Logging.LogLevel.Warning => Microsoft.Extensions.Logging.LogLevel.Warning, LogLevel.Warning => Microsoft.Extensions.Logging.LogLevel.Warning,
Telegrator.Logging.LogLevel.Error => Microsoft.Extensions.Logging.LogLevel.Error, LogLevel.Error => Microsoft.Extensions.Logging.LogLevel.Error,
_ => Microsoft.Extensions.Logging.LogLevel.Information _ => Microsoft.Extensions.Logging.LogLevel.Information
}; };
@@ -42,4 +40,3 @@ namespace Telegrator.Logging
} }
} }
} }
}
@@ -7,8 +7,8 @@ using Telegrator.Core;
using Telegrator.Core.States; using Telegrator.Core.States;
using Telegrator.Mediation; using Telegrator.Mediation;
namespace Telegrator.Polling namespace Telegrator.Polling;
{
/// <inheritdoc/> /// <inheritdoc/>
public class HostUpdateRouter : UpdateRouter public class HostUpdateRouter : UpdateRouter
{ {
@@ -57,4 +57,3 @@ namespace Telegrator.Polling
Logger.LogError("Exception was thrown during update routing faulted :\n{exception}", exception.ToString()); Logger.LogError("Exception was thrown during update routing faulted :\n{exception}", exception.ToString());
} }
} }
}
@@ -6,8 +6,8 @@ using Telegram.Bot.Polling;
using Telegrator.Core; using Telegrator.Core;
using Telegrator.Mediation; using Telegrator.Mediation;
namespace Telegrator.Polling namespace Telegrator.Polling;
{
/// <summary> /// <summary>
/// Service for receiving updates for Hosted telegram bots /// Service for receiving updates for Hosted telegram bots
/// </summary> /// </summary>
@@ -29,4 +29,3 @@ namespace Telegrator.Polling
await updateReceiver.ReceiveAsync(_updateRouter, stoppingToken).ConfigureAwait(false); await updateReceiver.ReceiveAsync(_updateRouter, stoppingToken).ConfigureAwait(false);
} }
} }
}
@@ -1,11 +1,9 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
namespace Telegrator.Providers;
namespace Telegrator.Providers
{
/// <inheritdoc/> /// <inheritdoc/>
public class HostAwaitingProvider(IOptions<TelegratorOptions> options, ILogger<HostAwaitingProvider> logger) : AwaitingProvider(options.Value) public class HostAwaitingProvider(IOptions<TelegratorOptions> options) : AwaitingProvider(options.Value)
{ {
private readonly ILogger<HostAwaitingProvider> _logger = logger;
}
} }
@@ -2,8 +2,8 @@
using Telegrator.Core; using Telegrator.Core;
using Telegrator.Core.Descriptors; using Telegrator.Core.Descriptors;
namespace Telegrator.Providers namespace Telegrator.Providers;
{
/// <inheritdoc/> /// <inheritdoc/>
public class HostHandlersCollection(IServiceCollection hostServiceColletion, TelegratorOptions options) : HandlersCollection(options) public class HostHandlersCollection(IServiceCollection hostServiceColletion, TelegratorOptions options) : HandlersCollection(options)
{ {
@@ -59,4 +59,3 @@ namespace Telegrator.Providers
return base.AddDescriptor(descriptor); return base.AddDescriptor(descriptor);
} }
} }
}
@@ -1,27 +1,23 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Telegrator.Core; using Telegrator.Core;
using Telegrator.Core.Descriptors; using Telegrator.Core.Descriptors;
using Telegrator.Core.Handlers; using Telegrator.Core.Handlers;
namespace Telegrator.Providers namespace Telegrator.Providers;
{
/// <inheritdoc/> /// <inheritdoc/>
public class HostHandlersProvider : HandlersProvider public class HostHandlersProvider : HandlersProvider
{ {
private readonly IServiceProvider Services; private readonly IServiceProvider Services;
private readonly ILogger<HostHandlersProvider> Logger;
/// <inheritdoc/> /// <inheritdoc/>
public HostHandlersProvider( public HostHandlersProvider(
IHandlersCollection handlers, IHandlersCollection handlers,
IOptions<TelegratorOptions> options, IOptions<TelegratorOptions> options,
IServiceProvider serviceProvider, IServiceProvider serviceProvider) : base(handlers, options.Value)
ILogger<HostHandlersProvider> logger) : base(handlers, options.Value)
{ {
Services = serviceProvider; Services = serviceProvider;
Logger = logger;
} }
/// <inheritdoc/> /// <inheritdoc/>
@@ -42,4 +38,3 @@ namespace Telegrator.Providers
return updateHandler; return updateHandler;
} }
} }
}
@@ -15,7 +15,7 @@
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild> <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<Title>Telegrator.Hosting</Title> <Title>Telegrator.Hosting</Title>
<Version>1.16.4</Version> <Version>1.16.6</Version>
<Authors>Rikitav Tim4ik</Authors> <Authors>Rikitav Tim4ik</Authors>
<Company>Rikitav Tim4ik</Company> <Company>Rikitav Tim4ik</Company>
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl> <RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
+39 -8
View File
@@ -11,10 +11,12 @@ using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.Enums;
using Telegrator.Core; using Telegrator.Core;
using Telegrator.Core.Descriptors; using Telegrator.Core.Descriptors;
using Telegrator.Core.States;
using Telegrator.Hosting; using Telegrator.Hosting;
using Telegrator.Logging; using Telegrator.Logging;
using Telegrator.Polling; using Telegrator.Polling;
using Telegrator.Providers; using Telegrator.Providers;
using Telegrator.States;
namespace Telegrator; namespace Telegrator;
@@ -28,7 +30,7 @@ public static class HostBuilderExtensions
/// </summary> /// </summary>
public const string HandlersCollectionPropertyKey = nameof(IHandlersCollection); public const string HandlersCollectionPropertyKey = nameof(IHandlersCollection);
extension (IHostApplicationBuilder builder) extension (HostApplicationBuilder builder)
{ {
/// <summary> /// <summary>
/// Gets the <see cref="IHandlersCollection"/> from the builder properties. /// Gets the <see cref="IHandlersCollection"/> from the builder properties.
@@ -37,18 +39,35 @@ public static class HostBuilderExtensions
{ {
get get
{ {
if (builder is TelegramBotHostBuilder botHostBuilder) return (IHandlersCollection)((IHostApplicationBuilder)builder).Properties[HandlersCollectionPropertyKey];
return botHostBuilder.Handlers;
return (IHandlersCollection)builder.Properties[HandlersCollectionPropertyKey];
} }
} }
} }
/// <summary> /// <summary>
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers. /// Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
/// </summary> /// </summary>
public static IHostApplicationBuilder AddTelegrator(this IHostApplicationBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null) public static ITelegramBotHostBuilder AddTelegrator(this ITelegramBotHostBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null, Action<ITelegramBotHostBuilder>? action = null)
{
builder.AddTelegratorInternal(options, handlers);
action?.Invoke(builder);
return builder;
}
/// <summary>
/// Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
/// </summary>
public static IHostApplicationBuilder AddTelegrator(this HostApplicationBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null, Action<ITelegramBotHostBuilder>? action = null)
{
builder.AddTelegratorInternal(options, handlers);
action?.Invoke(new TelegramBotHostBuilder(builder));
return builder;
}
/// <summary>
/// Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
/// </summary>
public static IHostApplicationBuilder AddTelegratorInternal(this IHostApplicationBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null)
{ {
IServiceCollection services = builder.Services; IServiceCollection services = builder.Services;
IConfigurationManager configuration = builder.Configuration; IConfigurationManager configuration = builder.Configuration;
@@ -112,6 +131,18 @@ public static class HostBuilderExtensions
/// </summary> /// </summary>
public static class ServicesCollectionExtensions public static class ServicesCollectionExtensions
{ {
/// <summary>
/// Registers <see cref="IStateStorage"/> service
/// </summary>
/// <typeparam name="TStorage"></typeparam>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddStateStorage<TStorage>(this IServiceCollection services) where TStorage : IStateStorage
{
services.Replace(new ServiceDescriptor(typeof(IStateStorage), typeof(TStorage), ServiceLifetime.Singleton));
return services;
}
/// <summary> /// <summary>
/// Registers <see cref="TelegramBotHost"/> default services /// Registers <see cref="TelegramBotHost"/> default services
/// </summary> /// </summary>
@@ -119,11 +150,11 @@ public static class ServicesCollectionExtensions
/// <returns></returns> /// <returns></returns>
public static IServiceCollection AddTelegramBotHostDefaults(this IServiceCollection services) public static IServiceCollection AddTelegramBotHostDefaults(this IServiceCollection services)
{ {
services.AddLogging(builder => builder.AddConsole().AddDebug());
services.AddSingleton<IAwaitingProvider, HostAwaitingProvider>(); services.AddSingleton<IAwaitingProvider, HostAwaitingProvider>();
services.AddSingleton<IHandlersProvider, HostHandlersProvider>(); services.AddSingleton<IHandlersProvider, HostHandlersProvider>();
services.AddSingleton<IUpdateRouter, HostUpdateRouter>(); services.AddSingleton<IUpdateRouter, HostUpdateRouter>();
services.AddSingleton<ITelegramBotInfo, HostedTelegramBotInfo>(); services.AddSingleton<ITelegramBotInfo, HostedTelegramBotInfo>();
services.AddSingleton<IStateStorage, DefaultStateStorage>();
return services; return services;
} }
@@ -4,8 +4,8 @@ using System.Threading.Tasks;
using Telegram.Bot.Types; using Telegram.Bot.Types;
using Telegrator.Handlers; using Telegrator.Handlers;
namespace Telegrator.Localized namespace Telegrator.Localized;
{
public static class LocalizedMessageHandlerExtensions public static class LocalizedMessageHandlerExtensions
{ {
public static async Task<Message> ResponseLocalized(this ILocalizedHandler<Message> localizedHandler, string localizedReplyIdentifier, params IEnumerable<string> formatArgs) public static async Task<Message> ResponseLocalized(this ILocalizedHandler<Message> localizedHandler, string localizedReplyIdentifier, params IEnumerable<string> formatArgs)
@@ -14,4 +14,3 @@ namespace Telegrator.Localized
return await localizedHandler.Container.Responce(localizedString.Value); return await localizedHandler.Container.Responce(localizedString.Value);
} }
} }
}
@@ -4,8 +4,8 @@ using Telegrator.Attributes;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
using Telegrator.Filters; using Telegrator.Filters;
namespace Telegrator.Annotations namespace Telegrator.Annotations;
{
/// <summary> /// <summary>
/// Abstract base attribute for filtering callback-based updates. /// Abstract base attribute for filtering callback-based updates.
/// Supports various message types including regular messages, edited messages, channel posts, and business messages. /// Supports various message types including regular messages, edited messages, channel posts, and business messages.
@@ -41,4 +41,3 @@ namespace Telegrator.Annotations
public class CallbackInlineIdAttribute(string inlineMessageId) public class CallbackInlineIdAttribute(string inlineMessageId)
: CallbackQueryAttribute(new CallbackInlineIdFilter(inlineMessageId)) : CallbackQueryAttribute(new CallbackInlineIdFilter(inlineMessageId))
{ } { }
}
@@ -3,8 +3,8 @@ using Telegram.Bot.Types.Enums;
using Telegrator.Filters; using Telegrator.Filters;
using Telegrator.Attributes; using Telegrator.Attributes;
namespace Telegrator.Annotations namespace Telegrator.Annotations;
{
/// <summary> /// <summary>
/// Attribute for filtering messages based on command aliases. /// Attribute for filtering messages based on command aliases.
/// Allows handlers to respond to multiple command variations using a single attribute. /// Allows handlers to respond to multiple command variations using a single attribute.
@@ -57,4 +57,3 @@ namespace Telegrator.Annotations
/// <returns>The message from the update, or null if not present.</returns> /// <returns>The message from the update, or null if not present.</returns>
public override Message? GetFilterringTarget(Update update) => update.Message; public override Message? GetFilterringTarget(Update update) => update.Message;
} }
}
@@ -1,8 +1,8 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Telegrator.Filters; using Telegrator.Filters;
namespace Telegrator.Annotations namespace Telegrator.Annotations;
{
/// <summary> /// <summary>
/// Attribute for filtering messages where a command has arguments count >= <paramref name="count"/>. /// Attribute for filtering messages where a command has arguments count >= <paramref name="count"/>.
/// </summary> /// </summary>
@@ -60,4 +60,3 @@ namespace Telegrator.Annotations
public class ArgumentRegexAttribute(string pattern, RegexOptions options = RegexOptions.None, int index = 0) public class ArgumentRegexAttribute(string pattern, RegexOptions options = RegexOptions.None, int index = 0)
: MessageFilterAttribute(new ArgumentRegexFilter(pattern, options, index: index)) : MessageFilterAttribute(new ArgumentRegexFilter(pattern, options, index: index))
{ } { }
}
@@ -1,5 +1,5 @@
namespace Telegrator.Annotations namespace Telegrator.Annotations;
{
/// <summary> /// <summary>
/// Attribute that prevents a class from being automatically collected by the handler collection system. /// Attribute that prevents a class from being automatically collected by the handler collection system.
/// When applied to a class, it will be excluded from domain-wide handler collection operations. /// When applied to a class, it will be excluded from domain-wide handler collection operations.
@@ -9,4 +9,3 @@
{ {
} }
}
@@ -4,8 +4,8 @@ using Telegrator.Filters;
using Telegrator.Attributes; using Telegrator.Attributes;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
namespace Telegrator.Annotations namespace Telegrator.Annotations;
{
/// <summary> /// <summary>
/// Abstract base attribute for filtering updates based on environment conditions. /// Abstract base attribute for filtering updates based on environment conditions.
/// Can process all types of updates and provides environment-specific filtering logic. /// Can process all types of updates and provides environment-specific filtering logic.
@@ -82,4 +82,3 @@ namespace Telegrator.Annotations
public EnvironmentVariableAttribute(string variable, StringComparison comparison) public EnvironmentVariableAttribute(string variable, StringComparison comparison)
: base(new EnvironmentVariableFilter(variable, comparison)) { } : base(new EnvironmentVariableFilter(variable, comparison)) { }
} }
}
@@ -1,8 +1,8 @@
using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.Enums;
using Telegrator.Filters; using Telegrator.Filters;
namespace Telegrator.Annotations namespace Telegrator.Annotations;
{
/// <summary> /// <summary>
/// Attribute for filtering messages that contain mentions. /// Attribute for filtering messages that contain mentions.
/// Allows handlers to respond only to messages that mention the bot or specific users. /// Allows handlers to respond only to messages that mention the bot or specific users.
@@ -37,4 +37,3 @@ namespace Telegrator.Annotations
public MentionedAttribute(string mention, int offset) public MentionedAttribute(string mention, int offset)
: base(new MessageHasEntityFilter(MessageEntityType.Mention, offset, null), new MentionedFilter(mention)) { } : base(new MessageHasEntityFilter(MessageEntityType.Mention, offset, null), new MentionedFilter(mention)) { }
} }
}
@@ -1,8 +1,8 @@
using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.Enums;
using Telegrator.Filters; using Telegrator.Filters;
namespace Telegrator.Annotations namespace Telegrator.Annotations;
{
/// <summary> /// <summary>
/// Attribute for filtering messages sent in forum chats. /// Attribute for filtering messages sent in forum chats.
/// </summary> /// </summary>
@@ -102,4 +102,3 @@ namespace Telegrator.Annotations
public ChatNameAttribute(string? firstName, string? lastName) public ChatNameAttribute(string? firstName, string? lastName)
: base(new MessageChatNameFilter(firstName, lastName)) { } : base(new MessageChatNameFilter(firstName, lastName)) { }
} }
}
@@ -5,8 +5,8 @@ using Telegrator.Filters;
using Telegrator.Attributes; using Telegrator.Attributes;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
namespace Telegrator.Annotations namespace Telegrator.Annotations;
{
/// <summary> /// <summary>
/// Abstract base attribute for filtering message-based updates. /// Abstract base attribute for filtering message-based updates.
/// Supports various message types including regular messages, edited messages, channel posts, and business messages. /// Supports various message types including regular messages, edited messages, channel posts, and business messages.
@@ -158,4 +158,3 @@ namespace Telegrator.Annotations
public MessageHasEntityAttribute(MessageEntityType type, int offset, int? length, string content, StringComparison stringComparison = StringComparison.CurrentCulture) public MessageHasEntityAttribute(MessageEntityType type, int offset, int? length, string content, StringComparison stringComparison = StringComparison.CurrentCulture)
: base(new MessageHasEntityFilter(type, offset, length, content, stringComparison)) { } : base(new MessageHasEntityFilter(type, offset, length, content, stringComparison)) { }
} }
}
@@ -1,7 +1,7 @@
using Telegrator.Filters; using Telegrator.Filters;
namespace Telegrator.Annotations namespace Telegrator.Annotations;
{
/// <summary> /// <summary>
/// Attribute for filtering messages with reply to messages of this bot. /// Attribute for filtering messages with reply to messages of this bot.
/// </summary> /// </summary>
@@ -24,4 +24,3 @@ namespace Telegrator.Annotations
public class FromReplyChainAttribute(int replyDepth = 1) public class FromReplyChainAttribute(int replyDepth = 1)
: MessageFilterAttribute(new FromReplyChainFilter(replyDepth)) : MessageFilterAttribute(new FromReplyChainFilter(replyDepth))
{ } { }
}
@@ -1,7 +1,7 @@
using Telegrator.Filters; using Telegrator.Filters;
namespace Telegrator.Annotations namespace Telegrator.Annotations;
{
/// <summary> /// <summary>
/// Attribute for filtering messages based on the sender's username. /// Attribute for filtering messages based on the sender's username.
/// </summary> /// </summary>
@@ -89,4 +89,3 @@ namespace Telegrator.Annotations
public class FromPremiumUserAttribute() public class FromPremiumUserAttribute()
: MessageFilterAttribute(new FromPremiumUserFilter()) : MessageFilterAttribute(new FromPremiumUserFilter())
{ } { }
}
@@ -1,7 +1,7 @@
using Telegrator.Filters; using Telegrator.Filters;
namespace Telegrator.Annotations namespace Telegrator.Annotations;
{
/// <summary> /// <summary>
/// Attribute for filtering messages where the text starts with the specified content. /// Attribute for filtering messages where the text starts with the specified content.
/// </summary> /// </summary>
@@ -55,4 +55,3 @@ namespace Telegrator.Annotations
public class TextContainsWordAttribute(string word, StringComparison comparison = StringComparison.InvariantCulture, int startIndex = 0) public class TextContainsWordAttribute(string word, StringComparison comparison = StringComparison.InvariantCulture, int startIndex = 0)
: MessageFilterAttribute(new TextContainsWordFilter(word, comparison, startIndex)) : MessageFilterAttribute(new TextContainsWordFilter(word, comparison, startIndex))
{ } { }
}
@@ -1,7 +1,7 @@
using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.Enums;
namespace Telegrator.Annotations namespace Telegrator.Annotations;
{
/// <summary> /// <summary>
/// Attribute that says if this handler can await some of await types, that is not listed by its handler base. /// Attribute that says if this handler can await some of await types, that is not listed by its handler base.
/// Used for automatic collecting allowed to receiving <see cref="UpdateType"/>'s. /// Used for automatic collecting allowed to receiving <see cref="UpdateType"/>'s.
@@ -24,4 +24,3 @@ namespace Telegrator.Annotations
public MightAwaitAttribute(params UpdateType[] updateTypes) public MightAwaitAttribute(params UpdateType[] updateTypes)
=> _updateTypes = updateTypes; => _updateTypes = updateTypes;
} }
}
@@ -2,8 +2,8 @@
using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.Enums;
using Telegrator.Filters; using Telegrator.Filters;
namespace Telegrator.Annotations namespace Telegrator.Annotations;
{
/// <summary> /// <summary>
/// Attribute for filtering message with command "start" in bot's private chats. /// Attribute for filtering message with command "start" in bot's private chats.
/// Allows handlers to respond to "welcome" bot commands. /// Allows handlers to respond to "welcome" bot commands.
@@ -20,4 +20,3 @@ namespace Telegrator.Annotations
Filter<Message>.If(ctx => !onlyFirst || ctx.Input.Id == 0)) Filter<Message>.If(ctx => !onlyFirst || ctx.Input.Id == 0))
{ } { }
} }
}
@@ -1,5 +1,5 @@
namespace Telegrator.Aspects namespace Telegrator.Aspects;
{
/// <summary> /// <summary>
/// Attribute that specifies a post-execution processor to be executed after the handler. /// Attribute that specifies a post-execution processor to be executed after the handler.
/// The processor type must implement <see cref="IPostProcessor"/> interface. /// The processor type must implement <see cref="IPostProcessor"/> interface.
@@ -13,4 +13,3 @@
/// </summary> /// </summary>
public Type ProcessorType => typeof(T); public Type ProcessorType => typeof(T);
} }
}
@@ -1,5 +1,5 @@
namespace Telegrator.Aspects namespace Telegrator.Aspects;
{
/// <summary> /// <summary>
/// Attribute that specifies a pre-execution processor to be executed before the handler. /// Attribute that specifies a pre-execution processor to be executed before the handler.
/// The processor type must implement <see cref="IPreProcessor"/> interface. /// The processor type must implement <see cref="IPreProcessor"/> interface.
@@ -13,4 +13,3 @@
/// </summary> /// </summary>
public Type ProcessorType => typeof(T); public Type ProcessorType => typeof(T);
} }
}
+2 -3
View File
@@ -1,7 +1,7 @@
using Telegrator.Core.Handlers; using Telegrator.Core.Handlers;
namespace Telegrator.Aspects namespace Telegrator.Aspects;
{
/// <summary> /// <summary>
/// Interface for post-execution processors that are executed after handler execution. /// Interface for post-execution processors that are executed after handler execution.
/// Implement this interface to add cross-cutting concerns like logging, cleanup, or metrics collection. /// Implement this interface to add cross-cutting concerns like logging, cleanup, or metrics collection.
@@ -16,4 +16,3 @@ namespace Telegrator.Aspects
/// <returns>A <see cref="Result"/> indicating the final execution result.</returns> /// <returns>A <see cref="Result"/> indicating the final execution result.</returns>
public Task<Result> AfterExecution(IHandlerContainer container, CancellationToken cancellationToken); public Task<Result> AfterExecution(IHandlerContainer container, CancellationToken cancellationToken);
} }
}
+2 -3
View File
@@ -1,7 +1,7 @@
using Telegrator.Core.Handlers; using Telegrator.Core.Handlers;
namespace Telegrator.Aspects namespace Telegrator.Aspects;
{
/// <summary> /// <summary>
/// Interface for pre-execution processors that are executed before handler execution. /// Interface for pre-execution processors that are executed before handler execution.
/// Implement this interface to add cross-cutting concerns like validation, logging, or authorization. /// Implement this interface to add cross-cutting concerns like validation, logging, or authorization.
@@ -16,4 +16,3 @@ namespace Telegrator.Aspects
/// <returns>A <see cref="Result"/> indicating whether execution should continue or be stopped.</returns> /// <returns>A <see cref="Result"/> indicating whether execution should continue or be stopped.</returns>
public Task<Result> BeforeExecution(IHandlerContainer container, CancellationToken cancellationToken = default); public Task<Result> BeforeExecution(IHandlerContainer container, CancellationToken cancellationToken = default);
} }
}
@@ -3,8 +3,8 @@ using Telegram.Bot.Types.Enums;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
using Telegrator.Filters; using Telegrator.Filters;
namespace Telegrator.Attributes namespace Telegrator.Attributes;
{
/// <summary> /// <summary>
/// Reactive way to implement a new <see cref="UpdateFilterAttribute{T}"/> of type <typeparamref name="T"/> /// Reactive way to implement a new <see cref="UpdateFilterAttribute{T}"/> of type <typeparamref name="T"/>
/// </summary> /// </summary>
@@ -36,4 +36,3 @@ namespace Telegrator.Attributes
/// <inheritdoc/> /// <inheritdoc/>
public abstract bool CanPass(FilterExecutionContext<T> context); public abstract bool CanPass(FilterExecutionContext<T> context);
} }
}
+2 -3
View File
@@ -1,5 +1,5 @@
namespace Telegrator.Attributes namespace Telegrator.Attributes;
{
/// <summary> /// <summary>
/// Enumeration of filter modifiers that can be applied to update filters. /// Enumeration of filter modifiers that can be applied to update filters.
/// Defines how filters should be combined and applied in filter chains. /// Defines how filters should be combined and applied in filter chains.
@@ -22,4 +22,3 @@
/// </summary> /// </summary>
Not = 4, Not = 4,
} }
}
@@ -3,8 +3,8 @@ using Telegrator.Core.Attributes;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
using Telegrator.Filters; using Telegrator.Filters;
namespace Telegrator.Attributes namespace Telegrator.Attributes;
{
/// <summary> /// <summary>
/// Abstract base attribute for defining update filters for a specific type of update target. /// Abstract base attribute for defining update filters for a specific type of update target.
/// Provides logic for filter composition, modifier processing, and target extraction. /// Provides logic for filter composition, modifier processing, and target extraction.
@@ -82,4 +82,3 @@ namespace Telegrator.Attributes
/// <returns>The target object to filter, or null if not applicable</returns> /// <returns>The target object to filter, or null if not applicable</returns>
public abstract T? GetFilterringTarget(Update update); public abstract T? GetFilterringTarget(Update update);
} }
}
@@ -2,8 +2,8 @@
using Telegrator.Core.Attributes; using Telegrator.Core.Attributes;
using Telegrator.Core.Handlers; using Telegrator.Core.Handlers;
namespace Telegrator.Attributes namespace Telegrator.Attributes;
{
/// <summary> /// <summary>
/// Abstract base attribute for marking update handler classes. /// Abstract base attribute for marking update handler classes.
/// Provides a type-safe way to associate handler types with specific update types and importance settings. /// Provides a type-safe way to associate handler types with specific update types and importance settings.
@@ -43,4 +43,3 @@ namespace Telegrator.Attributes
protected UpdateHandlerAttribute(Type[] types, UpdateType updateType, int importance) protected UpdateHandlerAttribute(Type[] types, UpdateType updateType, int importance)
: base([.. types, typeof(T)], updateType, importance) { } : base([.. types, typeof(T)], updateType, importance) { }
} }
}
@@ -5,8 +5,8 @@ using Telegrator.Core.Filters;
using Telegrator.Core.Handlers; using Telegrator.Core.Handlers;
using Telegrator.Filters; using Telegrator.Filters;
namespace Telegrator.Core.Attributes namespace Telegrator.Core.Attributes;
{
/// <summary> /// <summary>
/// Defines the <see cref="IFilter{T}"/> to <see cref="Update"/> validation for entry into execution of the <see cref="UpdateHandlerBase"/> /// Defines the <see cref="IFilter{T}"/> to <see cref="Update"/> validation for entry into execution of the <see cref="UpdateHandlerBase"/>
/// </summary> /// </summary>
@@ -44,4 +44,3 @@ namespace Telegrator.Core.Attributes
/// <returns></returns> /// <returns></returns>
public abstract bool ProcessModifiers(UpdateFilterAttributeBase? previous); public abstract bool ProcessModifiers(UpdateFilterAttributeBase? previous);
} }
}
@@ -4,8 +4,8 @@ using Telegrator.Core.Descriptors;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
using Telegrator.Core.Handlers; using Telegrator.Core.Handlers;
namespace Telegrator.Core.Attributes namespace Telegrator.Core.Attributes;
{
/// <summary> /// <summary>
/// Defines the <see cref="UpdateType"/>'s and validator (<see cref="IFilter{T}"/>) of the <see cref="Update"/> that <see cref="UpdateHandlerBase"/> will process /// Defines the <see cref="UpdateType"/>'s and validator (<see cref="IFilter{T}"/>) of the <see cref="Update"/> that <see cref="UpdateHandlerBase"/> will process
/// </summary> /// </summary>
@@ -79,4 +79,3 @@ namespace Telegrator.Core.Attributes
/// <returns>True if the update passes validation; otherwise, false.</returns> /// <returns>True if the update passes validation; otherwise, false.</returns>
public abstract bool CanPass(FilterExecutionContext<Update> context); public abstract bool CanPass(FilterExecutionContext<Update> context);
} }
}
@@ -7,8 +7,8 @@ using Telegrator.Core.Handlers;
using Telegrator.Handlers; using Telegrator.Handlers;
using Telegrator.Handlers.Building; using Telegrator.Handlers.Building;
namespace Telegrator.Core.Descriptors namespace Telegrator.Core.Descriptors;
{
/// <summary> /// <summary>
/// Descriptor for creating handlers from methods /// Descriptor for creating handlers from methods
/// </summary> /// </summary>
@@ -67,4 +67,3 @@ namespace Telegrator.Core.Descriptors
} }
} }
} }
}
@@ -4,8 +4,8 @@ using Telegrator.Core.Filters;
using Telegrator.Core.Handlers; using Telegrator.Core.Handlers;
using Telegrator.Core.States; using Telegrator.Core.States;
namespace Telegrator.Core.Descriptors namespace Telegrator.Core.Descriptors;
{
/// <summary> /// <summary>
/// Contains information about a described handler, including its context, client, and execution logic. /// Contains information about a described handler, including its context, client, and execution logic.
/// </summary> /// </summary>
@@ -134,4 +134,3 @@ namespace Telegrator.Core.Descriptors
public override string ToString() public override string ToString()
=> DisplayString ?? From.HandlerType.Name; => DisplayString ?? From.HandlerType.Name;
} }
}
@@ -1,8 +1,8 @@
using Telegrator.Aspects; using Telegrator.Aspects;
using Telegrator.Core.Handlers; using Telegrator.Core.Handlers;
namespace Telegrator.Core.Descriptors namespace Telegrator.Core.Descriptors;
{
/// <summary> /// <summary>
/// Manages the execution of pre and post-execution aspects for a handler. /// Manages the execution of pre and post-execution aspects for a handler.
/// This class coordinates between self-processing (handler implements interfaces) /// This class coordinates between self-processing (handler implements interfaces)
@@ -77,4 +77,3 @@ namespace Telegrator.Core.Descriptors
return Result.Ok(); return Result.Ok();
} }
} }
}
@@ -3,8 +3,8 @@ using Telegrator.Core.Filters;
using Telegrator.Handlers.Diagnostics; using Telegrator.Handlers.Diagnostics;
using Telegrator.Logging; using Telegrator.Logging;
namespace Telegrator.Core.Descriptors namespace Telegrator.Core.Descriptors;
{
/// <summary> /// <summary>
/// Represents a set of filters for a handler descriptor, including update and state keeper validators. /// Represents a set of filters for a handler descriptor, including update and state keeper validators.
/// </summary> /// </summary>
@@ -142,4 +142,3 @@ namespace Telegrator.Core.Descriptors
} }
} }
} }
}
@@ -1,7 +1,7 @@
using Telegrator.Core.Attributes; using Telegrator.Core.Attributes;
namespace Telegrator.Core.Descriptors namespace Telegrator.Core.Descriptors;
{
/// <summary> /// <summary>
/// Represents an indexer for handler descriptors, containing importance and priority information. /// Represents an indexer for handler descriptors, containing importance and priority information.
/// </summary> /// </summary>
@@ -85,4 +85,3 @@ namespace Telegrator.Core.Descriptors
return string.Format("(Ix: {0,2}, Im: {1,2}, Pr: {2,2})", RouterIndex, Importance, Priority); return string.Format("(Ix: {0,2}, Im: {1,2}, Pr: {2,2})", RouterIndex, Importance, Priority);
} }
} }
}
@@ -4,8 +4,8 @@ using Telegrator.Core.Attributes;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
using Telegrator.Core.Handlers; using Telegrator.Core.Handlers;
namespace Telegrator.Core.Descriptors namespace Telegrator.Core.Descriptors;
{
/// <summary> /// <summary>
/// Specifies the type of handler descriptor. /// Specifies the type of handler descriptor.
/// </summary> /// </summary>
@@ -472,4 +472,3 @@ namespace Telegrator.Core.Descriptors
public override string ToString() public override string ToString()
=> DisplayString ?? HandlerType.Name; => DisplayString ?? HandlerType.Name;
} }
}
@@ -2,8 +2,8 @@
using Telegram.Bot.Types; using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.Enums;
namespace Telegrator.Core.Descriptors namespace Telegrator.Core.Descriptors;
{
/// <summary> /// <summary>
/// The collection containing the <see cref="HandlerDescriptor"/>'s. Used to route <see cref="Update"/>'s in <see cref="IHandlersProvider"/> /// The collection containing the <see cref="HandlerDescriptor"/>'s. Used to route <see cref="Update"/>'s in <see cref="IHandlersProvider"/>
/// </summary> /// </summary>
@@ -156,4 +156,3 @@ namespace Telegrator.Core.Descriptors
return _innerCollection.Values.GetEnumerator(); return _innerCollection.Values.GetEnumerator();
} }
} }
}
@@ -7,8 +7,8 @@ using Telegrator.Aspects;
using Telegrator.Core.Attributes; using Telegrator.Core.Attributes;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
namespace Telegrator.Core.Descriptors namespace Telegrator.Core.Descriptors;
{
/// <summary> /// <summary>
/// Provides methods for inspecting handler types and retrieving their attributes and filters. /// Provides methods for inspecting handler types and retrieving their attributes and filters.
/// </summary> /// </summary>
@@ -96,4 +96,3 @@ namespace Telegrator.Core.Descriptors
return new DescriptorAspectsSet(typedPre, typedPost); return new DescriptorAspectsSet(typedPre, typedPost);
} }
} }
}
@@ -2,8 +2,8 @@
using Telegrator.Filters; using Telegrator.Filters;
using Telegrator.Logging; using Telegrator.Logging;
namespace Telegrator.Core.Filters namespace Telegrator.Core.Filters;
{
/// <summary> /// <summary>
/// Represents a compiled filter that applies a set of filters to an anonymous target type. /// Represents a compiled filter that applies a set of filters to an anonymous target type.
/// </summary> /// </summary>
@@ -106,4 +106,3 @@ namespace Telegrator.Core.Filters
} }
} }
} }
}
@@ -2,8 +2,8 @@
using Telegrator.Filters; using Telegrator.Filters;
using Telegrator.Logging; using Telegrator.Logging;
namespace Telegrator.Core.Filters namespace Telegrator.Core.Filters;
{
/// <summary> /// <summary>
/// Represents a filter that applies a filter action to an anonymous target type extracted from an update. /// Represents a filter that applies a filter action to an anonymous target type extracted from an update.
/// </summary> /// </summary>
@@ -107,4 +107,3 @@ namespace Telegrator.Core.Filters
} }
} }
} }
}
@@ -1,8 +1,8 @@
using Telegrator.Filters; using Telegrator.Filters;
using Telegrator.Logging; using Telegrator.Logging;
namespace Telegrator.Core.Filters namespace Telegrator.Core.Filters;
{
/// <summary> /// <summary>
/// Represents a filter that composes multiple filters and passes only if all of them pass. /// Represents a filter that composes multiple filters and passes only if all of them pass.
/// </summary> /// </summary>
@@ -61,4 +61,3 @@ namespace Telegrator.Core.Filters
return true; return true;
} }
} }
}
@@ -1,7 +1,7 @@
using System.Collections; using System.Collections;
namespace Telegrator.Core.Filters namespace Telegrator.Core.Filters;
{
/// <summary> /// <summary>
/// The list containing filters worked out during Polling to further obtain additional filtering information /// The list containing filters worked out during Polling to further obtain additional filtering information
/// </summary> /// </summary>
@@ -83,4 +83,3 @@ namespace Telegrator.Core.Filters
/// <inheritdoc/> /// <inheritdoc/>
IEnumerator IEnumerable.GetEnumerator() => CompletedFilters.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => CompletedFilters.GetEnumerator();
} }
}
@@ -1,8 +1,8 @@
using Telegram.Bot.Types; using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.Enums;
namespace Telegrator.Core.Filters namespace Telegrator.Core.Filters;
{
/// <summary> /// <summary>
/// Represents the context for filter execution, including update, input, and additional data. /// Represents the context for filter execution, including update, input, and additional data.
/// </summary> /// </summary>
@@ -83,4 +83,3 @@ namespace Telegrator.Core.Filters
public FilterExecutionContext<C> CreateChild<C>(C input) where C : class public FilterExecutionContext<C> CreateChild<C>(C input) where C : class
=> new FilterExecutionContext<C>(UpdateRouter, BotInfo, Update, input, Data, CompletedFilters); => new FilterExecutionContext<C>(UpdateRouter, BotInfo, Update, input, Data, CompletedFilters);
} }
}
+13 -2
View File
@@ -1,5 +1,5 @@
namespace Telegrator.Core.Filters namespace Telegrator.Core.Filters;
{
/// <summary> /// <summary>
/// Interface for filters that have a name for identification and debugging purposes. /// Interface for filters that have a name for identification and debugging purposes.
/// </summary> /// </summary>
@@ -36,4 +36,15 @@
/// <returns>True if the filter passes; otherwise, false.</returns> /// <returns>True if the filter passes; otherwise, false.</returns>
public bool CanPass(FilterExecutionContext<T> info); public bool CanPass(FilterExecutionContext<T> info);
} }
/// <summary>
/// Represents a filter that joins multiple filters together.
/// </summary>
/// <typeparam name="T">The type of the input for the filter.</typeparam>
public interface IJoinedFilter<T> : IFilter<T> where T : class
{
/// <summary>
/// Gets the array of joined filters.
/// </summary>
public IFilter<T>[] Filters { get; }
} }
@@ -1,14 +0,0 @@
namespace Telegrator.Core.Filters
{
/// <summary>
/// Represents a filter that joins multiple filters together.
/// </summary>
/// <typeparam name="T">The type of the input for the filter.</typeparam>
public interface IJoinedFilter<T> : IFilter<T> where T : class
{
/// <summary>
/// Gets the array of joined filters.
/// </summary>
public IFilter<T>[] Filters { get; }
}
}
@@ -6,8 +6,8 @@ using Telegrator.Core.Filters;
using Telegrator.Core.States; using Telegrator.Core.States;
using Telegrator.Handlers; using Telegrator.Handlers;
namespace Telegrator.Core.Handlers namespace Telegrator.Core.Handlers;
{
/// <summary> /// <summary>
/// Abstract handler for Telegram updates of type <typeparamref name="TUpdate"/>. /// Abstract handler for Telegram updates of type <typeparamref name="TUpdate"/>.
/// </summary> /// </summary>
@@ -93,4 +93,3 @@ namespace Telegrator.Core.Handlers
/// <returns>A task representing the asynchronous operation.</returns> /// <returns>A task representing the asynchronous operation.</returns>
public abstract Task<Result> Execute(IHandlerContainer<TUpdate> container, CancellationToken cancellation); public abstract Task<Result> Execute(IHandlerContainer<TUpdate> container, CancellationToken cancellation);
} }
}
@@ -6,8 +6,8 @@ using Telegrator.Core.Descriptors;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
using Telegrator.Handlers; using Telegrator.Handlers;
namespace Telegrator.Core.Handlers namespace Telegrator.Core.Handlers;
{
/// <summary> /// <summary>
/// Abstract base class for handlers that support branching execution based on different methods. /// Abstract base class for handlers that support branching execution based on different methods.
/// Allows multiple handler methods to be defined in a single class, each with its own filters. /// Allows multiple handler methods to be defined in a single class, each with its own filters.
@@ -162,4 +162,3 @@ namespace Telegrator.Core.Handlers
} }
} }
} }
}
@@ -5,8 +5,8 @@ using Telegrator.Core.Filters;
using Telegrator.Core.States; using Telegrator.Core.States;
using Telegrator.Filters; using Telegrator.Filters;
namespace Telegrator.Core.Handlers.Building namespace Telegrator.Core.Handlers.Building;
{
/// <summary> /// <summary>
/// Base class for building handler descriptors and managing handler filters. /// Base class for building handler descriptors and managing handler filters.
/// </summary> /// </summary>
@@ -177,4 +177,3 @@ namespace Telegrator.Core.Handlers.Building
Filters.Add(compiledPollingFilter); Filters.Add(compiledPollingFilter);
} }
} }
}
@@ -1,7 +1,7 @@
using Telegrator.Core.States; using Telegrator.Core.States;
namespace Telegrator.Core.Handlers.Building namespace Telegrator.Core.Handlers.Building;
{
/// <summary> /// <summary>
/// Defines a builder for awaiting handler logic for a specific update type. /// Defines a builder for awaiting handler logic for a specific update type.
/// </summary> /// </summary>
@@ -16,4 +16,3 @@ namespace Telegrator.Core.Handlers.Building
/// <returns>A <see cref="Task{TUpdate}"/> representing the awaited update.</returns> /// <returns>A <see cref="Task{TUpdate}"/> representing the awaited update.</returns>
public Task<TUpdate> Await(IStateKeyResolver keyResolver, CancellationToken cancellationToken = default); public Task<TUpdate> Await(IStateKeyResolver keyResolver, CancellationToken cancellationToken = default);
} }
}
@@ -2,8 +2,8 @@
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
using Telegrator.Core.States; using Telegrator.Core.States;
namespace Telegrator.Core.Handlers.Building namespace Telegrator.Core.Handlers.Building;
{
/// <summary> /// <summary>
/// Defines builder actions for configuring handler builders. /// Defines builder actions for configuring handler builders.
/// </summary> /// </summary>
@@ -83,4 +83,3 @@ namespace Telegrator.Core.Handlers.Building
public void AddTargetedFilters<TFilterTarget>(Func<Update, TFilterTarget?> getFilterringTarget, params IFilter<TFilterTarget>[] filters) public void AddTargetedFilters<TFilterTarget>(Func<Update, TFilterTarget?> getFilterringTarget, params IFilter<TFilterTarget>[] filters)
where TFilterTarget : class; where TFilterTarget : class;
} }
}
@@ -1,7 +1,7 @@
using Telegrator.Handlers.Building; using Telegrator.Handlers.Building;
namespace Telegrator.Core.Handlers.Building namespace Telegrator.Core.Handlers.Building;
{
/// <summary> /// <summary>
/// Defines a builder for regular handler logic for a specific update type. /// Defines a builder for regular handler logic for a specific update type.
/// </summary> /// </summary>
@@ -14,4 +14,3 @@ namespace Telegrator.Core.Handlers.Building
/// <param name="executeHandler">The delegate to execute the handler logic.</param> /// <param name="executeHandler">The delegate to execute the handler logic.</param>
public IHandlersCollection Build(AbstractHandlerAction<TUpdate> executeHandler); public IHandlersCollection Build(AbstractHandlerAction<TUpdate> executeHandler);
} }
}
@@ -1,8 +1,8 @@
using Telegram.Bot.Types; using Telegram.Bot.Types;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
namespace Telegrator.Core.Handlers.Building namespace Telegrator.Core.Handlers.Building;
{
/// <summary> /// <summary>
/// Delegate for validating an update in a filter context. /// Delegate for validating an update in a filter context.
/// </summary> /// </summary>
@@ -38,4 +38,3 @@ namespace Telegrator.Core.Handlers.Building
public bool CanPass(FilterExecutionContext<Update> info) public bool CanPass(FilterExecutionContext<Update> info)
=> UpdateValidateAction.Invoke(info); => UpdateValidateAction.Invoke(info);
} }
}
@@ -3,8 +3,8 @@ using Telegram.Bot.Types;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
using Telegrator.Core.States; using Telegrator.Core.States;
namespace Telegrator.Core.Handlers namespace Telegrator.Core.Handlers;
{
/// <summary> /// <summary>
/// Represents an empty handler container that throws <see cref="NotImplementedException"/> for all members. /// Represents an empty handler container that throws <see cref="NotImplementedException"/> for all members.
/// </summary> /// </summary>
@@ -28,4 +28,3 @@ namespace Telegrator.Core.Handlers
/// <inheritdoc/> /// <inheritdoc/>
public IStateStorage StateStorage => throw new NotImplementedException(); public IStateStorage StateStorage => throw new NotImplementedException();
} }
}
@@ -1,5 +1,5 @@
namespace Telegrator.Core.Handlers namespace Telegrator.Core.Handlers;
{
/// <summary> /// <summary>
/// Represents a token that tracks the lifetime of a handler instance. /// Represents a token that tracks the lifetime of a handler instance.
/// </summary> /// </summary>
@@ -24,4 +24,3 @@
OnLifetimeEnded?.Invoke(this); OnLifetimeEnded?.Invoke(this);
} }
} }
}
@@ -3,8 +3,8 @@ using Telegram.Bot.Types;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
using Telegrator.Core.States; using Telegrator.Core.States;
namespace Telegrator.Core.Handlers namespace Telegrator.Core.Handlers;
{
/// <summary> /// <summary>
/// Interface for handler containers that provide context and resources for update handlers. /// Interface for handler containers that provide context and resources for update handlers.
/// Contains all necessary information and services that handlers need during execution. /// Contains all necessary information and services that handlers need during execution.
@@ -41,4 +41,3 @@ namespace Telegrator.Core.Handlers
/// </summary> /// </summary>
public IStateStorage StateStorage { get; } public IStateStorage StateStorage { get; }
} }
}
@@ -1,7 +1,7 @@
using Telegrator.Core.Descriptors; using Telegrator.Core.Descriptors;
namespace Telegrator.Core.Handlers namespace Telegrator.Core.Handlers;
{
/// <summary> /// <summary>
/// Factory interface for creating handler containers. /// Factory interface for creating handler containers.
/// Provides a way to create handler containers with specific providers and handler information. /// Provides a way to create handler containers with specific providers and handler information.
@@ -15,4 +15,3 @@ namespace Telegrator.Core.Handlers
/// <returns>A new <see cref="IHandlerContainer"/> instance.</returns> /// <returns>A new <see cref="IHandlerContainer"/> instance.</returns>
public IHandlerContainer CreateContainer(DescribedHandlerDescriptor handlerInfo); public IHandlerContainer CreateContainer(DescribedHandlerDescriptor handlerInfo);
} }
}
@@ -4,8 +4,8 @@ using Telegram.Bot.Types.Enums;
using Telegrator.Core.Descriptors; using Telegrator.Core.Descriptors;
using Telegrator.Handlers.Diagnostics; using Telegrator.Handlers.Diagnostics;
namespace Telegrator.Core.Handlers namespace Telegrator.Core.Handlers;
{
/// <summary> /// <summary>
/// Base class for update handlers, providing execution and lifetime management for Telegram updates. /// Base class for update handlers, providing execution and lifetime management for Telegram updates.
/// </summary> /// </summary>
@@ -179,4 +179,3 @@ namespace Telegrator.Core.Handlers
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
} }
}
+2 -3
View File
@@ -1,7 +1,7 @@
using Telegrator.Core.Descriptors; using Telegrator.Core.Descriptors;
namespace Telegrator.Core namespace Telegrator.Core;
{
/// <summary> /// <summary>
/// Provider for managing awaiting handlers that can wait for specific update types. /// Provider for managing awaiting handlers that can wait for specific update types.
/// </summary> /// </summary>
@@ -14,4 +14,3 @@ namespace Telegrator.Core
/// <returns>An <see cref="IDisposable"/> that manages the handler's usage lifetime.</returns> /// <returns>An <see cref="IDisposable"/> that manages the handler's usage lifetime.</returns>
public IDisposable UseHandler(HandlerDescriptor handlerDescriptor); public IDisposable UseHandler(HandlerDescriptor handlerDescriptor);
} }
}
+2 -3
View File
@@ -1,5 +1,5 @@
namespace Telegrator.Core namespace Telegrator.Core;
{
/// <summary> /// <summary>
/// Interface for providers that collect and manage handler collections. /// Interface for providers that collect and manage handler collections.
/// Provides access to a collection of handlers for various processing operations. /// Provides access to a collection of handlers for various processing operations.
@@ -11,4 +11,3 @@
/// </summary> /// </summary>
public IHandlersCollection Handlers { get; } public IHandlersCollection Handlers { get; }
} }
}
@@ -1,7 +1,7 @@
using Telegrator.Core.Descriptors; using Telegrator.Core.Descriptors;
namespace Telegrator.Core namespace Telegrator.Core;
{
/// <summary> /// <summary>
/// Interface for classes that can provide custom handler descriptors. /// Interface for classes that can provide custom handler descriptors.
/// Allows classes to define their own handler description logic beyond the standard reflection-based approach. /// Allows classes to define their own handler description logic beyond the standard reflection-based approach.
@@ -14,4 +14,3 @@ namespace Telegrator.Core
/// <returns>A collection of handler descriptors.</returns> /// <returns>A collection of handler descriptors.</returns>
public IEnumerable<HandlerDescriptor> DescribeHandlers(); public IEnumerable<HandlerDescriptor> DescribeHandlers();
} }
}
+2 -3
View File
@@ -1,8 +1,8 @@
using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.Enums;
using Telegrator.Core.Descriptors; using Telegrator.Core.Descriptors;
namespace Telegrator.Core namespace Telegrator.Core;
{
/// <summary> /// <summary>
/// Collection class for managing handler descriptors organized by update type. /// Collection class for managing handler descriptors organized by update type.
/// Provides functionality for collecting, adding, and organizing handlers. /// Provides functionality for collecting, adding, and organizing handlers.
@@ -38,4 +38,3 @@ namespace Telegrator.Core
/// <returns>The updated <see cref="IHandlersCollection"/>.</returns> /// <returns>The updated <see cref="IHandlersCollection"/>.</returns>
public IHandlersCollection AddDescriptor(HandlerDescriptor descriptor); public IHandlersCollection AddDescriptor(HandlerDescriptor descriptor);
} }
}
+2 -3
View File
@@ -1,5 +1,5 @@
namespace Telegrator.Core namespace Telegrator.Core;
{
/// <summary> /// <summary>
/// Combines <see cref="IHandlersCollection"/> and <see cref="IHandlersProvider"/>. /// Combines <see cref="IHandlersCollection"/> and <see cref="IHandlersProvider"/>.
/// Provides functionality of collecting, organizing and resolving handlers instances. /// Provides functionality of collecting, organizing and resolving handlers instances.
@@ -8,4 +8,3 @@
{ {
} }
}
+2 -3
View File
@@ -2,8 +2,8 @@
using Telegrator.Core.Descriptors; using Telegrator.Core.Descriptors;
using Telegrator.Core.Handlers; using Telegrator.Core.Handlers;
namespace Telegrator.Core namespace Telegrator.Core;
{
/// <summary> /// <summary>
/// Provides methods to retrieve and describe handler information for updates. /// Provides methods to retrieve and describe handler information for updates.
/// </summary> /// </summary>
@@ -37,4 +37,3 @@ namespace Telegrator.Core
/// <returns>True if the provider is empty; otherwise, false.</returns> /// <returns>True if the provider is empty; otherwise, false.</returns>
public bool IsEmpty(); public bool IsEmpty();
} }
}
@@ -1,8 +1,8 @@
using Telegram.Bot; using Telegram.Bot;
using Telegram.Bot.Polling; using Telegram.Bot.Polling;
namespace Telegrator.Core namespace Telegrator.Core;
{
/// <summary> /// <summary>
/// Interface for handling exceptions that occur during update routing operations. /// Interface for handling exceptions that occur during update routing operations.
/// Provides a centralized way to handle and log errors that occur during bot operation. /// Provides a centralized way to handle and log errors that occur during bot operation.
@@ -18,4 +18,3 @@ namespace Telegrator.Core
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
public void HandleException(ITelegramBotClient botClient, Exception exception, HandleErrorSource source, CancellationToken cancellationToken); public void HandleException(ITelegramBotClient botClient, Exception exception, HandleErrorSource source, CancellationToken cancellationToken);
} }
}
+2 -3
View File
@@ -1,7 +1,7 @@
using Telegram.Bot.Types; using Telegram.Bot.Types;
namespace Telegrator.Core namespace Telegrator.Core;
{
/// <summary> /// <summary>
/// Interface for providing bot information and metadata. /// Interface for providing bot information and metadata.
/// Contains information about the bot user and provides initialization capabilities. /// Contains information about the bot user and provides initialization capabilities.
@@ -13,4 +13,3 @@ namespace Telegrator.Core
/// </summary> /// </summary>
public User User { get; } public User User { get; }
} }
}
+2 -3
View File
@@ -1,7 +1,7 @@
using Telegrator.Core.Descriptors; using Telegrator.Core.Descriptors;
namespace Telegrator.Core namespace Telegrator.Core;
{
/// <summary> /// <summary>
/// Represents a delegate for when a handler is enqueued. /// Represents a delegate for when a handler is enqueued.
/// </summary> /// </summary>
@@ -35,4 +35,3 @@ namespace Telegrator.Core
/// <param name="handlers">The handlers to enqueue.</param> /// <param name="handlers">The handlers to enqueue.</param>
public Task Enqueue(params IEnumerable<DescribedHandlerDescriptor> handlers); public Task Enqueue(params IEnumerable<DescribedHandlerDescriptor> handlers);
} }
}
+2 -3
View File
@@ -2,8 +2,8 @@
using Telegrator.Core.Handlers; using Telegrator.Core.Handlers;
using Telegrator.Core.States; using Telegrator.Core.States;
namespace Telegrator.Core namespace Telegrator.Core;
{
/// <summary> /// <summary>
/// Interface for update routers that handle incoming updates and manage handler execution. /// Interface for update routers that handle incoming updates and manage handler execution.
/// Combines update handling capabilities with polling provider functionality and exception handling. /// Combines update handling capabilities with polling provider functionality and exception handling.
@@ -45,4 +45,3 @@ namespace Telegrator.Core
/// </summary> /// </summary>
public IHandlerContainerFactory? DefaultContainerFactory { get; set; } public IHandlerContainerFactory? DefaultContainerFactory { get; set; }
} }
}
+2 -3
View File
@@ -1,5 +1,5 @@
namespace Telegrator namespace Telegrator;
{
/// <summary> /// <summary>
/// Enumeration of dice types supported by Telegram. /// Enumeration of dice types supported by Telegram.
/// Used for filtering dice messages and determining dice emoji representations. /// Used for filtering dice messages and determining dice emoji representations.
@@ -131,4 +131,3 @@
HandlersPool = 0x8 HandlersPool = 0x8
} }
*/ */
}
+2 -3
View File
@@ -1,7 +1,7 @@
using Telegrator.Core.Descriptors; using Telegrator.Core.Descriptors;
namespace Telegrator namespace Telegrator;
{
/// <summary> /// <summary>
/// Exception thrown when attempting to modify a frozen collection. /// Exception thrown when attempting to modify a frozen collection.
/// </summary> /// </summary>
@@ -49,4 +49,3 @@ namespace Telegrator
HandlerInfo = handlerInfo; HandlerInfo = handlerInfo;
} }
} }
}
@@ -2,8 +2,8 @@
using Telegram.Bot.Types; using Telegram.Bot.Types;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
namespace Telegrator.Filters namespace Telegrator.Filters;
{
/// <summary> /// <summary>
/// Filter thet checks <see cref="CallbackQuery"/>'s data /// Filter thet checks <see cref="CallbackQuery"/>'s data
/// </summary> /// </summary>
@@ -70,4 +70,3 @@ namespace Telegrator.Filters
public CallbackRegexFilter(Regex regex) public CallbackRegexFilter(Regex regex)
: base(clb => clb.Data, regex) { } : base(clb => clb.Data, regex) { }
} }
}
+2 -3
View File
@@ -2,8 +2,8 @@
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
using Telegrator.Handlers; using Telegrator.Handlers;
namespace Telegrator.Filters namespace Telegrator.Filters;
{
/// <summary> /// <summary>
/// Filter that checks if a command matches any of the specified aliases. /// Filter that checks if a command matches any of the specified aliases.
/// Requires a <see cref="CommandHandlerAttribute"/> to be applied first to extract the command. /// Requires a <see cref="CommandHandlerAttribute"/> to be applied first to extract the command.
@@ -29,4 +29,3 @@ namespace Telegrator.Filters
return alliases.Contains(ReceivedCommand, StringComparer.InvariantCultureIgnoreCase); return alliases.Contains(ReceivedCommand, StringComparer.InvariantCultureIgnoreCase);
} }
} }
}
@@ -3,8 +3,8 @@ using Telegram.Bot.Types;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
using Telegrator.Handlers; using Telegrator.Handlers;
namespace Telegrator.Filters namespace Telegrator.Filters;
{
/// <summary> /// <summary>
/// Abstract base class for filters that operate on command arguments. /// Abstract base class for filters that operate on command arguments.
/// Provides functionality to extract and validate command arguments from message text. /// Provides functionality to extract and validate command arguments from message text.
@@ -202,4 +202,3 @@ namespace Telegrator.Filters
return Match.Success; return Match.Success;
} }
} }
}
+2 -3
View File
@@ -2,8 +2,8 @@
using Telegram.Bot.Types; using Telegram.Bot.Types;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
namespace Telegrator.Filters namespace Telegrator.Filters;
{
/// <summary> /// <summary>
/// Abstract base class for filters that operate based on the current environment. /// Abstract base class for filters that operate based on the current environment.
/// Provides functionality to detect debug vs release environments. /// Provides functionality to detect debug vs release environments.
@@ -122,4 +122,3 @@ namespace Telegrator.Filters
return envValue.Equals(_value, _comparison); return envValue.Equals(_value, _comparison);
} }
} }
}
+2 -3
View File
@@ -1,7 +1,7 @@
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
namespace Telegrator.Filters namespace Telegrator.Filters;
{
/// <summary> /// <summary>
/// Base class for filters, providing logical operations and collectability. /// Base class for filters, providing logical operations and collectability.
/// </summary> /// </summary>
@@ -132,4 +132,3 @@ namespace Telegrator.Filters
public override bool CanPass(FilterExecutionContext<T> context) public override bool CanPass(FilterExecutionContext<T> context)
=> context.Input != null && FilterFunc != null && FilterFunc(context); => context.Input != null && FilterFunc != null && FilterFunc(context);
} }
}
+2 -3
View File
@@ -1,7 +1,7 @@
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
namespace Telegrator.Filters namespace Telegrator.Filters;
{
/// <summary> /// <summary>
/// Base class for filters that join multiple filters together. /// Base class for filters that join multiple filters together.
/// </summary> /// </summary>
@@ -51,4 +51,3 @@ namespace Telegrator.Filters
public override bool CanPass(FilterExecutionContext<T> context) public override bool CanPass(FilterExecutionContext<T> context)
=> Filters[0].CanPass(context) || Filters[1].CanPass(context); => Filters[0].CanPass(context) || Filters[1].CanPass(context);
} }
}
+2 -3
View File
@@ -2,8 +2,8 @@
using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.Enums;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
namespace Telegrator.Filters namespace Telegrator.Filters;
{
/// <summary> /// <summary>
/// Filter that checks if a message contains a mention of the bot or a specific user. /// Filter that checks if a message contains a mention of the bot or a specific user.
/// Requires a <see cref="MessageHasEntityFilter"/> to be applied first to identify mention entities. /// Requires a <see cref="MessageHasEntityFilter"/> to be applied first to identify mention entities.
@@ -61,4 +61,3 @@ namespace Telegrator.Filters
return false; return false;
} }
} }
}
+2 -3
View File
@@ -3,8 +3,8 @@ using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.ReplyMarkups; using Telegram.Bot.Types.ReplyMarkups;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
namespace Telegrator.Filters namespace Telegrator.Filters;
{
/// <summary> /// <summary>
/// Base class for filters that operate on the chat of the message being processed. /// Base class for filters that operate on the chat of the message being processed.
/// </summary> /// </summary>
@@ -217,4 +217,3 @@ namespace Telegrator.Filters
return true; return true;
} }
} }
}
+2 -3
View File
@@ -3,8 +3,8 @@ using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.Enums;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
namespace Telegrator.Filters namespace Telegrator.Filters;
{
/// <summary> /// <summary>
/// Base abstract class for all filter of <see cref="Message"/> updates /// Base abstract class for all filter of <see cref="Message"/> updates
/// </summary> /// </summary>
@@ -272,4 +272,3 @@ namespace Telegrator.Filters
return true; return true;
} }
} }
}
@@ -1,8 +1,8 @@
using Telegram.Bot.Types; using Telegram.Bot.Types;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
namespace Telegrator.Filters namespace Telegrator.Filters;
{
/// <summary> /// <summary>
/// Filter that checks if message has appropriate reply chain. /// Filter that checks if message has appropriate reply chain.
/// DOES NOT SHiFT MESSAGE FILTERS TARGET /// DOES NOT SHiFT MESSAGE FILTERS TARGET
@@ -99,4 +99,3 @@ namespace Telegrator.Filters
return context.BotInfo.User == repliedFilter.Reply.From; return context.BotInfo.User == repliedFilter.Reply.From;
} }
} }
}
@@ -1,8 +1,8 @@
using Telegram.Bot.Types; using Telegram.Bot.Types;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
namespace Telegrator.Filters namespace Telegrator.Filters;
{
/// <summary> /// <summary>
/// Abstract base class for filters that operate on message senders. /// Abstract base class for filters that operate on message senders.
/// Provides functionality to access and validate the user who sent the message. /// Provides functionality to access and validate the user who sent the message.
@@ -179,4 +179,3 @@ namespace Telegrator.Filters
protected override bool CanPassNext(FilterExecutionContext<Message> _) protected override bool CanPassNext(FilterExecutionContext<Message> _)
=> User.IsPremium; => User.IsPremium;
} }
}
+2 -4
View File
@@ -1,9 +1,8 @@
using Telegram.Bot.Types; using Telegram.Bot.Types;
using Telegrator.Core.Filters; using Telegrator.Core.Filters;
using static System.Net.Mime.MediaTypeNames;
namespace Telegrator.Filters namespace Telegrator.Filters;
{
/// <summary> /// <summary>
/// Abstract base class for filters that operate on message text content. /// Abstract base class for filters that operate on message text content.
/// Provides common functionality for extracting and validating message text. /// Provides common functionality for extracting and validating message text.
@@ -182,4 +181,3 @@ namespace Telegrator.Filters
protected override bool CanPassNext(FilterExecutionContext<Message> context) protected override bool CanPassNext(FilterExecutionContext<Message> context)
=> Text.ContainsWord(Word, Comparison, StartIndex); => Text.ContainsWord(Word, Comparison, StartIndex);
} }
}

Some files were not shown because too many files have changed in this diff Show More