Added localization addon
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
using Microsoft.Extensions.Localization;
|
||||||
|
using Telegram.Bot.Types;
|
||||||
|
using Telegrator.Handlers.Components;
|
||||||
|
|
||||||
|
namespace Telegrator.Localized
|
||||||
|
{
|
||||||
|
public interface ILocalizedHandler<T> : IAbstractUpdateHandler<Message> where T : class
|
||||||
|
{
|
||||||
|
public IStringLocalizer LocalizationProvider { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using Telegram.Bot.Types;
|
||||||
|
using Telegrator.Handlers.Components;
|
||||||
|
|
||||||
|
namespace Telegrator.Localized
|
||||||
|
{
|
||||||
|
public interface ILocalizedMessageHandler : ILocalizedHandler<Message>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.Extensions.Localization;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Telegram.Bot.Types;
|
||||||
|
using Telegrator.Handlers;
|
||||||
|
|
||||||
|
namespace Telegrator.Localized
|
||||||
|
{
|
||||||
|
public static class LocalizedMessageHandlerExtensions
|
||||||
|
{
|
||||||
|
public static async Task<Message> ResponseLocalized(this ILocalizedHandler<Message> localizedHandler, string localizedReplyIdentifier, params IEnumerable<string> formatArgs)
|
||||||
|
{
|
||||||
|
LocalizedString localizedString = localizedHandler.LocalizationProvider[localizedReplyIdentifier];
|
||||||
|
localizedHandler.Container.Response();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<LangVersion>latest</LangVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="10.0.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Telegrator\Telegrator.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -70,7 +70,7 @@ namespace Telegrator.Tests.Handlers
|
|||||||
public async Task UpdateHandlerBase_ShouldHandleCancellation()
|
public async Task UpdateHandlerBase_ShouldHandleCancellation()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var mockContainer = new Mock<IAbstractHandlerContainer<Message>>();
|
var mockContainer = new Mock<IHandlerContainer<Message>>();
|
||||||
var testHandler = new TestUpdateHandler();
|
var testHandler = new TestUpdateHandler();
|
||||||
var cancellationTokenSource = new CancellationTokenSource();
|
var cancellationTokenSource = new CancellationTokenSource();
|
||||||
cancellationTokenSource.Cancel(); // Отменяем сразу
|
cancellationTokenSource.Cancel(); // Отменяем сразу
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace Telegrator.Tests
|
|||||||
{
|
{
|
||||||
public bool WasExecuted { get; private set; }
|
public bool WasExecuted { get; private set; }
|
||||||
|
|
||||||
public override Task<Result> Execute(IAbstractHandlerContainer<Message> container, CancellationToken cancellationToken)
|
public override Task<Result> Execute(IHandlerContainer<Message> container, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
WasExecuted = true;
|
WasExecuted = true;
|
||||||
|
|||||||
+10
-2
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 18
|
||||||
VisualStudioVersion = 17.14.36119.2
|
VisualStudioVersion = 18.2.11408.102 d18.0
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Telegrator", "Telegrator\Telegrator.csproj", "{12D1D209-6473-4F58-BD66-846F0D85F6FD}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Telegrator", "Telegrator\Telegrator.csproj", "{12D1D209-6473-4F58-BD66-846F0D85F6FD}"
|
||||||
EndProject
|
EndProject
|
||||||
@@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Telegrator.Hosting.Web", "T
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Telegrator.RoslynGenerators", "dev\Telegrator.RoslynGenerators\Telegrator.RoslynGenerators.csproj", "{93658B7F-C651-4C78-2CB1-2C0AE00C45B5}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Telegrator.RoslynGenerators", "dev\Telegrator.RoslynGenerators\Telegrator.RoslynGenerators.csproj", "{93658B7F-C651-4C78-2CB1-2C0AE00C45B5}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Telegrator.Localized", "Telegrator.Localized\Telegrator.Localized.csproj", "{0B5D9465-B5E4-4B37-92D2-6AF1D682DAD9}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
AnalyzersDebug|Any CPU = AnalyzersDebug|Any CPU
|
AnalyzersDebug|Any CPU = AnalyzersDebug|Any CPU
|
||||||
@@ -63,6 +65,12 @@ Global
|
|||||||
{93658B7F-C651-4C78-2CB1-2C0AE00C45B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{93658B7F-C651-4C78-2CB1-2C0AE00C45B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{93658B7F-C651-4C78-2CB1-2C0AE00C45B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{93658B7F-C651-4C78-2CB1-2C0AE00C45B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{93658B7F-C651-4C78-2CB1-2C0AE00C45B5}.Release|Any CPU.Build.0 = Release|Any CPU
|
{93658B7F-C651-4C78-2CB1-2C0AE00C45B5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{0B5D9465-B5E4-4B37-92D2-6AF1D682DAD9}.AnalyzersDebug|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0B5D9465-B5E4-4B37-92D2-6AF1D682DAD9}.AnalyzersDebug|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{0B5D9465-B5E4-4B37-92D2-6AF1D682DAD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0B5D9465-B5E4-4B37-92D2-6AF1D682DAD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0B5D9465-B5E4-4B37-92D2-6AF1D682DAD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0B5D9465-B5E4-4B37-92D2-6AF1D682DAD9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace Telegrator.Handlers.Building
|
|||||||
/// <param name="container">The handler container with execution context.</param>
|
/// <param name="container">The handler container with execution context.</param>
|
||||||
/// <param name="cancellation">The cancellation token.</param>
|
/// <param name="cancellation">The cancellation token.</param>
|
||||||
/// <returns>A task representing the asynchronous execution.</returns>
|
/// <returns>A task representing the asynchronous execution.</returns>
|
||||||
public override Task<Result> Execute(IAbstractHandlerContainer<TUpdate> container, CancellationToken cancellation)
|
public override Task<Result> Execute(IHandlerContainer<TUpdate> container, CancellationToken cancellation)
|
||||||
=> HandlerAction.Invoke(container, cancellation);
|
=> HandlerAction.Invoke(container, cancellation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Telegrator.Handlers.Building
|
|||||||
/// <param name="container">The handler container with execution context.</param>
|
/// <param name="container">The handler container with execution context.</param>
|
||||||
/// <param name="cancellation">The cancellation token.</param>
|
/// <param name="cancellation">The cancellation token.</param>
|
||||||
/// <returns>A task representing the asynchronous execution.</returns>
|
/// <returns>A task representing the asynchronous execution.</returns>
|
||||||
public delegate Task<Result> AbstractHandlerAction<TUpdate>(IAbstractHandlerContainer<TUpdate> container, CancellationToken cancellation) where TUpdate : class;
|
public delegate Task<Result> AbstractHandlerAction<TUpdate>(IHandlerContainer<TUpdate> container, CancellationToken cancellation) where TUpdate : class;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Builder class for creating regular handlers that can process updates.
|
/// Builder class for creating regular handlers that can process updates.
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ namespace Telegrator.Handlers
|
|||||||
int? directMessageTopicId = null,
|
int? directMessageTopicId = null,
|
||||||
SuggestedPostParameters? suggestedPostParameters = null,
|
SuggestedPostParameters? suggestedPostParameters = null,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
=> await Container.Responce(
|
=> await Container.Response(
|
||||||
text, parseMode, replyParameters,
|
text, parseMode, replyParameters,
|
||||||
replyMarkup, linkPreviewOptions,
|
replyMarkup, linkPreviewOptions,
|
||||||
messageThreadId, entities,
|
messageThreadId, entities,
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ namespace Telegrator.Handlers.Components
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Abstract handler for Telegram updates of type <typeparamref name="TUpdate"/>.
|
/// Abstract handler for Telegram updates of type <typeparamref name="TUpdate"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class AbstractUpdateHandler<TUpdate> : UpdateHandlerBase, IHandlerContainerFactory where TUpdate : class
|
public abstract class AbstractUpdateHandler<TUpdate> : UpdateHandlerBase, IHandlerContainerFactory, IAbstractUpdateHandler<TUpdate> where TUpdate : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handler container for the current update.
|
/// Handler container for the current update.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected IAbstractHandlerContainer<TUpdate> Container { get; private set; } = default!;
|
public IHandlerContainer<TUpdate> Container { get; private set; } = default!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Telegram Bot client associated with the current container.
|
/// Telegram Bot client associated with the current container.
|
||||||
@@ -64,7 +64,7 @@ namespace Telegrator.Handlers.Components
|
|||||||
/// <returns>The created handler container.</returns>
|
/// <returns>The created handler container.</returns>
|
||||||
public virtual IHandlerContainer CreateContainer(DescribedHandlerInfo handlerInfo)
|
public virtual IHandlerContainer CreateContainer(DescribedHandlerInfo handlerInfo)
|
||||||
{
|
{
|
||||||
return new AbstractHandlerContainer<TUpdate>(handlerInfo);
|
return new HandlerContainer<TUpdate>(handlerInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -75,7 +75,7 @@ namespace Telegrator.Handlers.Components
|
|||||||
/// <returns>A task representing the asynchronous operation.</returns>
|
/// <returns>A task representing the asynchronous operation.</returns>
|
||||||
protected override sealed async Task<Result> ExecuteInternal(IHandlerContainer container, CancellationToken cancellationToken)
|
protected override sealed async Task<Result> ExecuteInternal(IHandlerContainer container, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
Container = (IAbstractHandlerContainer<TUpdate>)container;
|
Container = (IHandlerContainer<TUpdate>)container;
|
||||||
return await Execute(Container, cancellationToken);
|
return await Execute(Container, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +85,6 @@ namespace Telegrator.Handlers.Components
|
|||||||
/// <param name="container">The handler container.</param>
|
/// <param name="container">The handler container.</param>
|
||||||
/// <param name="cancellation">Cancellation token.</param>
|
/// <param name="cancellation">Cancellation token.</param>
|
||||||
/// <returns>A task representing the asynchronous operation.</returns>
|
/// <returns>A task representing the asynchronous operation.</returns>
|
||||||
public abstract Task<Result> Execute(IAbstractHandlerContainer<TUpdate> container, CancellationToken cancellation);
|
public abstract Task<Result> Execute(IHandlerContainer<TUpdate> container, CancellationToken cancellation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ namespace Telegrator.Handlers.Components
|
|||||||
/// <exception cref="Exception">Thrown when the awaiting provider is not of the expected type.</exception>
|
/// <exception cref="Exception">Thrown when the awaiting provider is not of the expected type.</exception>
|
||||||
public override IHandlerContainer CreateContainer(DescribedHandlerInfo handlerInfo)
|
public override IHandlerContainer CreateContainer(DescribedHandlerInfo handlerInfo)
|
||||||
{
|
{
|
||||||
return new AbstractHandlerContainer<TUpdate>(handlerInfo);
|
return new HandlerContainer<TUpdate>(handlerInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -117,7 +117,7 @@ namespace Telegrator.Handlers.Components
|
|||||||
/// <param name="container">The handler container.</param>
|
/// <param name="container">The handler container.</param>
|
||||||
/// <param name="cancellation">The cancellation token.</param>
|
/// <param name="cancellation">The cancellation token.</param>
|
||||||
/// <exception cref="Exception">Thrown when no branch method is set.</exception>
|
/// <exception cref="Exception">Thrown when no branch method is set.</exception>
|
||||||
public override async Task<Result> Execute(IAbstractHandlerContainer<TUpdate> container, CancellationToken cancellation)
|
public override async Task<Result> Execute(IHandlerContainer<TUpdate> container, CancellationToken cancellation)
|
||||||
{
|
{
|
||||||
if (branchMethodInfo is null)
|
if (branchMethodInfo is null)
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
@@ -131,7 +131,7 @@ namespace Telegrator.Handlers.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="container">The handler container.</param>
|
/// <param name="container">The handler container.</param>
|
||||||
/// <param name="methodInfo">The method to execute.</param>
|
/// <param name="methodInfo">The method to execute.</param>
|
||||||
protected virtual async Task<Result> BranchExecuteWrapper(IAbstractHandlerContainer<TUpdate> container, MethodInfo methodInfo)
|
protected virtual async Task<Result> BranchExecuteWrapper(IHandlerContainer<TUpdate> container, MethodInfo methodInfo)
|
||||||
{
|
{
|
||||||
if (methodInfo.ReturnType == typeof(void))
|
if (methodInfo.ReturnType == typeof(void))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
namespace Telegrator.Handlers.Components;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Abstract handler for Telegram updates of type <typeparamref name="TUpdate"/>.
|
||||||
|
/// </summary>
|
||||||
|
public interface IAbstractUpdateHandler<TUpdate> where TUpdate : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Handler container for the current update.
|
||||||
|
/// </summary>
|
||||||
|
public IHandlerContainer<TUpdate> Container { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Abstract method to execute the update handling logic.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="container">The handler container.</param>
|
||||||
|
/// <param name="cancellation">Cancellation token.</param>
|
||||||
|
/// <returns>A task representing the asynchronous operation.</returns>
|
||||||
|
public Task<Result> Execute(IHandlerContainer<TUpdate> container, CancellationToken cancellation);
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using Telegram.Bot;
|
||||||
|
using Telegram.Bot.Types.Enums;
|
||||||
|
using Telegrator.Handlers.Diagnostics;
|
||||||
|
using Telegrator.MadiatorCore.Descriptors;
|
||||||
|
|
||||||
|
namespace Telegrator.Handlers.Components;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Abstraction for update handlers, providing execution and lifetime management for Telegram updates.
|
||||||
|
/// </summary>
|
||||||
|
public interface IUpdateHandlerBase : IDisposable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the <see cref="UpdateType"/> that this handler processes.
|
||||||
|
/// </summary>
|
||||||
|
UpdateType HandlingUpdateType { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the <see cref="HandlerLifetimeToken"/> associated with this handler instance.
|
||||||
|
/// </summary>
|
||||||
|
HandlerLifetimeToken LifetimeToken { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes the handler logic and marks the lifetime as ended after execution.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="described"></param>
|
||||||
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
|
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
||||||
|
Task<Result> Execute(DescribedHandlerInfo described, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles failed filters during handler describing.
|
||||||
|
/// Use <see cref="Result"/> to control how router should treat this fail.
|
||||||
|
/// <see cref="Result.Next"/> to silently continue decribing.
|
||||||
|
/// <see cref="Result.Fault"/> to stop\break desribing sequence.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="report"></param>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<Result> FiltersFallback(FiltersFallbackReport report, ITelegramBotClient client, CancellationToken cancellationToken = default);
|
||||||
|
}
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
using System.ComponentModel;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot;
|
|
||||||
using Telegram.Bot.Polling;
|
using Telegram.Bot.Polling;
|
||||||
using Telegram.Bot.Types;
|
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegrator.Filters.Components;
|
|
||||||
using Telegrator.Handlers.Diagnostics;
|
using Telegrator.Handlers.Diagnostics;
|
||||||
using Telegrator.MadiatorCore.Descriptors;
|
using Telegrator.MadiatorCore.Descriptors;
|
||||||
|
|
||||||
@@ -12,7 +9,7 @@ namespace Telegrator.Handlers.Components
|
|||||||
/// <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>
|
||||||
public abstract class UpdateHandlerBase(UpdateType handlingUpdateType) : IDisposable
|
public abstract class UpdateHandlerBase(UpdateType handlingUpdateType) : IUpdateHandlerBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="UpdateType"/> that this handler processes.
|
/// Gets the <see cref="UpdateType"/> that this handler processes.
|
||||||
|
|||||||
+9
-9
@@ -11,7 +11,7 @@ namespace Telegrator.Handlers
|
|||||||
/// Provides access to the update, client, filters, and other execution context.
|
/// Provides access to the update, client, filters, and other execution context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TUpdate">The type of update being handled.</typeparam>
|
/// <typeparam name="TUpdate">The type of update being handled.</typeparam>
|
||||||
public class AbstractHandlerContainer<TUpdate> : IAbstractHandlerContainer<TUpdate> where TUpdate : class
|
public class HandlerContainer<TUpdate> : IHandlerContainer<TUpdate> where TUpdate : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the actual update object of type TUpdate.
|
/// Gets the actual update object of type TUpdate.
|
||||||
@@ -34,10 +34,10 @@ namespace Telegrator.Handlers
|
|||||||
public IAwaitingProvider AwaitingProvider { get; }
|
public IAwaitingProvider AwaitingProvider { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes new instance of <see cref="AbstractHandlerContainer{TUpdate}"/>
|
/// Initializes new instance of <see cref="HandlerContainer{TUpdate}"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="handlerInfo"></param>
|
/// <param name="handlerInfo"></param>
|
||||||
public AbstractHandlerContainer(DescribedHandlerInfo handlerInfo)
|
public HandlerContainer(DescribedHandlerInfo handlerInfo)
|
||||||
{
|
{
|
||||||
ActualUpdate = handlerInfo.HandlingUpdate.GetActualUpdateObject<TUpdate>();
|
ActualUpdate = handlerInfo.HandlingUpdate.GetActualUpdateObject<TUpdate>();
|
||||||
HandlingUpdate = handlerInfo.HandlingUpdate;
|
HandlingUpdate = handlerInfo.HandlingUpdate;
|
||||||
@@ -48,7 +48,7 @@ namespace Telegrator.Handlers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes new instance of <see cref="AbstractHandlerContainer{TUpdate}"/>
|
/// Initializes new instance of <see cref="HandlerContainer{TUpdate}"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="actualUpdate"></param>
|
/// <param name="actualUpdate"></param>
|
||||||
/// <param name="handlingUpdate"></param>
|
/// <param name="handlingUpdate"></param>
|
||||||
@@ -56,7 +56,7 @@ namespace Telegrator.Handlers
|
|||||||
/// <param name="extraData"></param>
|
/// <param name="extraData"></param>
|
||||||
/// <param name="filters"></param>
|
/// <param name="filters"></param>
|
||||||
/// <param name="awaitingProvider"></param>
|
/// <param name="awaitingProvider"></param>
|
||||||
public AbstractHandlerContainer(TUpdate actualUpdate, Update handlingUpdate, ITelegramBotClient client, Dictionary<string, object> extraData, CompletedFiltersList filters, IAwaitingProvider awaitingProvider)
|
public HandlerContainer(TUpdate actualUpdate, Update handlingUpdate, ITelegramBotClient client, Dictionary<string, object> extraData, CompletedFiltersList filters, IAwaitingProvider awaitingProvider)
|
||||||
{
|
{
|
||||||
ActualUpdate = actualUpdate;
|
ActualUpdate = actualUpdate;
|
||||||
HandlingUpdate = handlingUpdate;
|
HandlingUpdate = handlingUpdate;
|
||||||
@@ -71,9 +71,9 @@ namespace Telegrator.Handlers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="QUpdate"></typeparam>
|
/// <typeparam name="QUpdate"></typeparam>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public AbstractHandlerContainer<QUpdate> CreateChild<QUpdate>() where QUpdate : class
|
public HandlerContainer<QUpdate> CreateChild<QUpdate>() where QUpdate : class
|
||||||
{
|
{
|
||||||
return new AbstractHandlerContainer<QUpdate>(
|
return new HandlerContainer<QUpdate>(
|
||||||
HandlingUpdate.GetActualUpdateObject<QUpdate>(),
|
HandlingUpdate.GetActualUpdateObject<QUpdate>(),
|
||||||
HandlingUpdate, Client, ExtraData,
|
HandlingUpdate, Client, ExtraData,
|
||||||
CompletedFilters, AwaitingProvider);
|
CompletedFilters, AwaitingProvider);
|
||||||
@@ -85,9 +85,9 @@ namespace Telegrator.Handlers
|
|||||||
/// <typeparam name="QUpdate"></typeparam>
|
/// <typeparam name="QUpdate"></typeparam>
|
||||||
/// <param name="other"></param>
|
/// <param name="other"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static AbstractHandlerContainer<TUpdate> From<QUpdate>(IAbstractHandlerContainer<QUpdate> other) where QUpdate : class
|
public static HandlerContainer<TUpdate> From<QUpdate>(IHandlerContainer<QUpdate> other) where QUpdate : class
|
||||||
{
|
{
|
||||||
return new AbstractHandlerContainer<TUpdate>(
|
return new HandlerContainer<TUpdate>(
|
||||||
other.HandlingUpdate.GetActualUpdateObject<TUpdate>(),
|
other.HandlingUpdate.GetActualUpdateObject<TUpdate>(),
|
||||||
other.HandlingUpdate, other.Client, other.ExtraData,
|
other.HandlingUpdate, other.Client, other.ExtraData,
|
||||||
other.CompletedFilters, other.AwaitingProvider);
|
other.CompletedFilters, other.AwaitingProvider);
|
||||||
+1
-1
@@ -6,7 +6,7 @@ namespace Telegrator.Handlers
|
|||||||
/// Represents a handler container for a specific update type.
|
/// Represents a handler container for a specific update type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TUpdate">The type of update handled by the container.</typeparam>
|
/// <typeparam name="TUpdate">The type of update handled by the container.</typeparam>
|
||||||
public interface IAbstractHandlerContainer<TUpdate> : IHandlerContainer where TUpdate : class
|
public interface IHandlerContainer<TUpdate> : IHandlerContainer where TUpdate : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the actual update object of type <typeparamref name="TUpdate"/>.
|
/// Gets the actual update object of type <typeparamref name="TUpdate"/>.
|
||||||
@@ -26,12 +26,12 @@ namespace Telegrator.Handlers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handler container for the current <see cref="InlineQuery"/> update.
|
/// Handler container for the current <see cref="InlineQuery"/> update.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected IAbstractHandlerContainer<InlineQuery> QueryContainer { get; private set; } = null!;
|
protected IHandlerContainer<InlineQuery> QueryContainer { get; private set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handler container for the current <see cref="ChosenInlineResult"/> update.
|
/// Handler container for the current <see cref="ChosenInlineResult"/> update.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected IAbstractHandlerContainer<ChosenInlineResult> ChosenContainer { get; private set; } = null!;
|
protected IHandlerContainer<ChosenInlineResult> ChosenContainer { get; private set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Incoming update of type <see cref="InlineQuery"/>.
|
/// Incoming update of type <see cref="InlineQuery"/>.
|
||||||
@@ -44,20 +44,20 @@ namespace Telegrator.Handlers
|
|||||||
protected ChosenInlineResult InputChosen { get; private set; } = null!;
|
protected ChosenInlineResult InputChosen { get; private set; } = null!;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override async Task<Result> Execute(IAbstractHandlerContainer<Update> container, CancellationToken cancellation)
|
public override async Task<Result> Execute(IHandlerContainer<Update> container, CancellationToken cancellation)
|
||||||
{
|
{
|
||||||
switch (container.HandlingUpdate.Type)
|
switch (container.HandlingUpdate.Type)
|
||||||
{
|
{
|
||||||
case UpdateType.InlineQuery:
|
case UpdateType.InlineQuery:
|
||||||
{
|
{
|
||||||
QueryContainer = AbstractHandlerContainer<InlineQuery>.From(container);
|
QueryContainer = HandlerContainer<InlineQuery>.From(container);
|
||||||
InputQuery = QueryContainer.ActualUpdate;
|
InputQuery = QueryContainer.ActualUpdate;
|
||||||
return await Requested(QueryContainer, cancellation).ConfigureAwait(false);
|
return await Requested(QueryContainer, cancellation).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
case UpdateType.ChosenInlineResult:
|
case UpdateType.ChosenInlineResult:
|
||||||
{
|
{
|
||||||
ChosenContainer = AbstractHandlerContainer<ChosenInlineResult>.From(container);
|
ChosenContainer = HandlerContainer<ChosenInlineResult>.From(container);
|
||||||
InputChosen = ChosenContainer.ActualUpdate;
|
InputChosen = ChosenContainer.ActualUpdate;
|
||||||
return await Chosen(ChosenContainer, cancellation).ConfigureAwait(false);
|
return await Chosen(ChosenContainer, cancellation).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ namespace Telegrator.Handlers
|
|||||||
/// <param name="container"></param>
|
/// <param name="container"></param>
|
||||||
/// <param name="cancellation"></param>
|
/// <param name="cancellation"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public abstract Task<Result> Requested(IAbstractHandlerContainer<InlineQuery> container, CancellationToken cancellation);
|
public abstract Task<Result> Requested(IHandlerContainer<InlineQuery> container, CancellationToken cancellation);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes handler logic if received update is <see cref="UpdateType.ChosenInlineResult"/>
|
/// Executes handler logic if received update is <see cref="UpdateType.ChosenInlineResult"/>
|
||||||
@@ -81,7 +81,7 @@ namespace Telegrator.Handlers
|
|||||||
/// <param name="container"></param>
|
/// <param name="container"></param>
|
||||||
/// <param name="cancellation"></param>
|
/// <param name="cancellation"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public abstract Task<Result> Chosen(IAbstractHandlerContainer<ChosenInlineResult> container, CancellationToken cancellation);
|
public abstract Task<Result> Chosen(IHandlerContainer<ChosenInlineResult> container, CancellationToken cancellation);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Answers inline query
|
/// Answers inline query
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ namespace Telegrator.Handlers
|
|||||||
/// <param name="suggestedPostParameters"></param>
|
/// <param name="suggestedPostParameters"></param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>The sent message.</returns>
|
/// <returns>The sent message.</returns>
|
||||||
protected async Task<Message> Responce(
|
protected async Task<Message> Response(
|
||||||
string text,
|
string text,
|
||||||
ParseMode parseMode = ParseMode.None,
|
ParseMode parseMode = ParseMode.None,
|
||||||
ReplyParameters? replyParameters = null,
|
ReplyParameters? replyParameters = null,
|
||||||
@@ -104,7 +104,7 @@ namespace Telegrator.Handlers
|
|||||||
int? directMessageTopicId = null,
|
int? directMessageTopicId = null,
|
||||||
SuggestedPostParameters? suggestedPostParameters = null,
|
SuggestedPostParameters? suggestedPostParameters = null,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
=> await Container.Responce(
|
=> await Container.Response(
|
||||||
text, parseMode, replyParameters,
|
text, parseMode, replyParameters,
|
||||||
replyMarkup, linkPreviewOptions,
|
replyMarkup, linkPreviewOptions,
|
||||||
messageThreadId, entities,
|
messageThreadId, entities,
|
||||||
@@ -197,7 +197,7 @@ namespace Telegrator.Handlers
|
|||||||
int? directMessageTopicId = null,
|
int? directMessageTopicId = null,
|
||||||
SuggestedPostParameters? suggestedPostParameters = null,
|
SuggestedPostParameters? suggestedPostParameters = null,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
=> await Container.Responce(
|
=> await Container.Response(
|
||||||
text, parseMode, replyParameters,
|
text, parseMode, replyParameters,
|
||||||
replyMarkup, linkPreviewOptions,
|
replyMarkup, linkPreviewOptions,
|
||||||
messageThreadId, entities,
|
messageThreadId, entities,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace Telegrator.Handlers
|
|||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task React(
|
public static async Task React(
|
||||||
this IAbstractHandlerContainer<Message> container,
|
this IHandlerContainer<Message> container,
|
||||||
ReactionType reaction,
|
ReactionType reaction,
|
||||||
bool isBig = false,
|
bool isBig = false,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
@@ -38,7 +38,7 @@ namespace Telegrator.Handlers
|
|||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task React(
|
public static async Task React(
|
||||||
this IAbstractHandlerContainer<Message> container,
|
this IHandlerContainer<Message> container,
|
||||||
IEnumerable<ReactionType> reactions,
|
IEnumerable<ReactionType> reactions,
|
||||||
bool isBig = false,
|
bool isBig = false,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
@@ -67,7 +67,7 @@ namespace Telegrator.Handlers
|
|||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>The sent message.</returns>
|
/// <returns>The sent message.</returns>
|
||||||
public static async Task<Message> Reply(
|
public static async Task<Message> Reply(
|
||||||
this IAbstractHandlerContainer<Message> container,
|
this IHandlerContainer<Message> container,
|
||||||
string text,
|
string text,
|
||||||
ParseMode parseMode = ParseMode.None,
|
ParseMode parseMode = ParseMode.None,
|
||||||
ReplyMarkup? replyMarkup = null,
|
ReplyMarkup? replyMarkup = null,
|
||||||
@@ -111,8 +111,8 @@ namespace Telegrator.Handlers
|
|||||||
/// <param name="suggestedPostParameters"></param>
|
/// <param name="suggestedPostParameters"></param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>The sent message.</returns>
|
/// <returns>The sent message.</returns>
|
||||||
public static async Task<Message> Responce(
|
public static async Task<Message> Response(
|
||||||
this IAbstractHandlerContainer<Message> container,
|
this IHandlerContainer<Message> container,
|
||||||
string text,
|
string text,
|
||||||
ParseMode parseMode = ParseMode.None,
|
ParseMode parseMode = ParseMode.None,
|
||||||
ReplyParameters? replyParameters = null,
|
ReplyParameters? replyParameters = null,
|
||||||
@@ -158,8 +158,8 @@ namespace Telegrator.Handlers
|
|||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="Exception"></exception>
|
/// <exception cref="Exception"></exception>
|
||||||
public static async Task<Message> Responce(
|
public static async Task<Message> Response(
|
||||||
this IAbstractHandlerContainer<CallbackQuery> container,
|
this IHandlerContainer<CallbackQuery> container,
|
||||||
string text,
|
string text,
|
||||||
ParseMode parseMode = ParseMode.None,
|
ParseMode parseMode = ParseMode.None,
|
||||||
ReplyParameters? replyParameters = null,
|
ReplyParameters? replyParameters = null,
|
||||||
@@ -203,7 +203,7 @@ namespace Telegrator.Handlers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="Exception"></exception>
|
/// <exception cref="Exception"></exception>
|
||||||
public static async Task<Message> EditMessage(
|
public static async Task<Message> EditMessage(
|
||||||
this IAbstractHandlerContainer<CallbackQuery> container,
|
this IHandlerContainer<CallbackQuery> container,
|
||||||
string text,
|
string text,
|
||||||
ParseMode parseMode = ParseMode.None,
|
ParseMode parseMode = ParseMode.None,
|
||||||
InlineKeyboardMarkup? replyMarkup = null,
|
InlineKeyboardMarkup? replyMarkup = null,
|
||||||
@@ -243,7 +243,7 @@ namespace Telegrator.Handlers
|
|||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task AnswerCallbackQuery(
|
public static async Task AnswerCallbackQuery(
|
||||||
this IAbstractHandlerContainer<CallbackQuery> container,
|
this IHandlerContainer<CallbackQuery> container,
|
||||||
string? text = null,
|
string? text = null,
|
||||||
bool showAlert = false,
|
bool showAlert = false,
|
||||||
string? url = null,
|
string? url = null,
|
||||||
@@ -269,7 +269,7 @@ namespace Telegrator.Handlers
|
|||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task AnswerInlineQuery(
|
public static async Task AnswerInlineQuery(
|
||||||
this IAbstractHandlerContainer<InlineQuery> container,
|
this IHandlerContainer<InlineQuery> container,
|
||||||
IEnumerable<InlineQueryResult> results,
|
IEnumerable<InlineQueryResult> results,
|
||||||
int? cacheTime = null,
|
int? cacheTime = null,
|
||||||
bool isPersonal = false,
|
bool isPersonal = false,
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace Telegrator.MadiatorCore.Descriptors
|
|||||||
{
|
{
|
||||||
internal MethodInfo Method = null!;
|
internal MethodInfo Method = null!;
|
||||||
|
|
||||||
public override async Task<Result> Execute(IAbstractHandlerContainer<TUpdate> container, CancellationToken cancellation)
|
public override async Task<Result> Execute(IHandlerContainer<TUpdate> container, CancellationToken cancellation)
|
||||||
{
|
{
|
||||||
if (Method is null)
|
if (Method is null)
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
|
|||||||
@@ -129,16 +129,6 @@ namespace Telegrator
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns an enumerable that repeats the item multiple times.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T"></typeparam>
|
|
||||||
/// <param name="item"></param>
|
|
||||||
/// <param name="times"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static IEnumerable<T> Repeat<T>(this T item, int times)
|
|
||||||
=> Enumerable.Range(0, times).Select(_ => item);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the only element of a sequence, or a default value if the sequence is empty.
|
/// Returns the only element of a sequence, or a default value if the sequence is empty.
|
||||||
/// This method returns default if there is more than one element in the sequence.
|
/// This method returns default if there is more than one element in the sequence.
|
||||||
|
|||||||
Reference in New Issue
Block a user