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