* Added missing summaries

This commit is contained in:
2026-03-09 04:38:03 +04:00
parent 0e445dd586
commit 5f9c640930
12 changed files with 967 additions and 7 deletions
@@ -100,7 +100,13 @@ public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
continue;
usings.UnionAdd(classDeclaration.FindAncestor<CompilationUnitSyntax>().Usings, UsingEqualityComparer);
MethodDeclarationSyntax targeter = FindTargetterMethod(targetters, classDeclaration);
MethodDeclarationSyntax? targeter = FindTargetterMethod(targetters, classDeclaration);
if (targeter == null)
{
debugExport.AppendLine("Targetter not found");
continue;
}
if (classDeclaration.ParameterList != null && classDeclaration.BaseList != null)
{
@@ -227,7 +233,7 @@ public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
private static IEnumerable<ConstructorDeclarationSyntax> GetConstructors(ClassDeclarationSyntax classDeclaration)
=> classDeclaration.Members.OfType<ConstructorDeclarationSyntax>().Where(ctor => ctor.Modifiers.HasModifiers("public"));
private static MethodDeclarationSyntax FindTargetterMethod(Dictionary<string, MethodDeclarationSyntax> targeters, ClassDeclarationSyntax classDeclaration)
private static MethodDeclarationSyntax? FindTargetterMethod(Dictionary<string, MethodDeclarationSyntax> targeters, ClassDeclarationSyntax classDeclaration)
{
if (targeters.TryGetValue(classDeclaration.Identifier.ValueText, out MethodDeclarationSyntax targeter))
return targeter;
@@ -235,7 +241,7 @@ public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
if (classDeclaration.BaseList != null && targeters.TryGetValue(classDeclaration.BaseList.Types.ElementAt(0).Type.ToString(), out targeter))
return targeter;
throw new TargteterNotFoundException();
return null;
}
private static SyntaxTriviaList BuildExtensionXmlDocTrivia(ClassDeclarationSyntax classDeclaration, ParameterListSyntax methodParameters)
+29
View File
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<doc>
<assembly>
<name>Telegartor.RedisStateStorage</name>
</assembly>
<members>
<member name="T:Telegrator.States.RedisStateStorage">
<summary>
Provides a Redis-based implementation of the <see cref="T:Telegrator.Core.States.IStateStorage"/> interface.
Serializes state objects to JSON format before storing them in the Redis database.
</summary>
</member>
<member name="M:Telegrator.States.RedisStateStorage.#ctor(StackExchange.Redis.IConnectionMultiplexer)">
<summary>
Provides a Redis-based implementation of the <see cref="T:Telegrator.Core.States.IStateStorage"/> interface.
Serializes state objects to JSON format before storing them in the Redis database.
</summary>
</member>
<member name="M:Telegrator.States.RedisStateStorage.SetAsync``1(System.String,``0,System.Threading.CancellationToken)">
<inheritdoc/>
</member>
<member name="M:Telegrator.States.RedisStateStorage.GetAsync``1(System.String,System.Threading.CancellationToken)">
<inheritdoc/>
</member>
<member name="M:Telegrator.States.RedisStateStorage.DeleteAsync(System.String,System.Threading.CancellationToken)">
<inheritdoc/>
</member>
</members>
</doc>
+783
View File
@@ -769,6 +769,33 @@
</summary>
<param name="updateTypes"></param>
</member>
<member name="T:Telegrator.Annotations.StateAttribute`2">
<summary>
Attribute for filtering updates where resolved state matches target value.
</summary>
<typeparam name="TKey"></typeparam>
<typeparam name="TValue"></typeparam>
<param name="value"></param>
</member>
<member name="M:Telegrator.Annotations.StateAttribute`2.#ctor(`1)">
<summary>
Attribute for filtering updates where resolved state matches target value.
</summary>
<typeparam name="TKey"></typeparam>
<typeparam name="TValue"></typeparam>
<param name="value"></param>
</member>
<member name="P:Telegrator.Annotations.StateAttribute`2.Value">
<summary>
The targetting state value.
</summary>
</member>
<member name="P:Telegrator.Annotations.StateAttribute`2.AllowedTypes">
<inheritdoc/>
</member>
<member name="M:Telegrator.Annotations.StateAttribute`2.GetFilterringTarget(Telegram.Bot.Types.Update)">
<inheritdoc/>
</member>
<member name="T:Telegrator.Annotations.WelcomeAttribute">
<summary>
Attribute for filtering message with command "start" in bot's private chats.
@@ -2896,6 +2923,80 @@
<param name="keySource">The update to resolve the key from.</param>
<returns>The resolved key.</returns>
</member>
<member name="T:Telegrator.Core.States.IStateMachine`1">
<summary>
Defines a contract for a state machine that manages transitions and retrieves states for specific updates.
</summary>
<typeparam name="TState">The type of the state. Must implement <see cref="T:System.IEquatable`1"/>.</typeparam>
</member>
<member name="M:Telegrator.Core.States.IStateMachine`1.Current(Telegrator.Core.States.IStateStorage,System.String,System.Threading.CancellationToken)">
<summary>
Gets the current state associated with the specified update key.
</summary>
<param name="storage">The storage mechanism used to persist the state.</param>
<param name="updateKey">The unique key identifying the current update context (e.g., chat and user ID).</param>
<param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
<returns>A task that represents the asynchronous operation. The task result contains the current state, or the default value if no state is found.</returns>
</member>
<member name="M:Telegrator.Core.States.IStateMachine`1.Advance(Telegrator.Core.States.IStateStorage,System.String,System.Threading.CancellationToken)">
<summary>
Advances the state machine to the next state in the sequence.
</summary>
<param name="storage">The storage mechanism used to persist the state.</param>
<param name="updateKey">The unique key identifying the current update context.</param>
<param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
<returns>A task that represents the asynchronous transition operation.</returns>
</member>
<member name="M:Telegrator.Core.States.IStateMachine`1.Retreat(Telegrator.Core.States.IStateStorage,System.String,System.Threading.CancellationToken)">
<summary>
Moves the state machine backward to the previous state in the sequence.
</summary>
<param name="storage">The storage mechanism used to persist the state.</param>
<param name="updateKey">The unique key identifying the current update context.</param>
<param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
<returns>A task that represents the asynchronous transition operation.</returns>
</member>
<member name="M:Telegrator.Core.States.IStateMachine`1.Reset(Telegrator.Core.States.IStateStorage,System.String,System.Threading.CancellationToken)">
<summary>
Resets the state machine to its initial or default state.
</summary>
<param name="storage">The storage mechanism used to persist the state.</param>
<param name="updateKey">The unique key identifying the current update context.</param>
<param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
<returns>A task that represents the asynchronous reset operation.</returns>
</member>
<member name="T:Telegrator.Core.States.IStateStorage">
<summary>
Defines a contract for an asynchronous state storage mechanism.
</summary>
</member>
<member name="M:Telegrator.Core.States.IStateStorage.SetAsync``1(System.String,``0,System.Threading.CancellationToken)">
<summary>
Saves or updates a state value associated with the specified key.
</summary>
<typeparam name="T">The type of the state object.</typeparam>
<param name="key">The unique identifier for the state.</param>
<param name="state">The state object to store.</param>
<param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
<returns>A task that represents the asynchronous save operation.</returns>
</member>
<member name="M:Telegrator.Core.States.IStateStorage.GetAsync``1(System.String,System.Threading.CancellationToken)">
<summary>
Retrieves a state value associated with the specified key.
</summary>
<typeparam name="T">The type of the state object to retrieve.</typeparam>
<param name="key">The unique identifier for the state.</param>
<param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
<returns>A task that represents the asynchronous retrieve operation. The task result contains the state object if found; otherwise, the default value of <typeparamref name="T"/>.</returns>
</member>
<member name="M:Telegrator.Core.States.IStateStorage.DeleteAsync(System.String,System.Threading.CancellationToken)">
<summary>
Deletes the state value associated with the specified key.
</summary>
<param name="key">The unique identifier for the state to remove.</param>
<param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
<returns>A task that represents the asynchronous delete operation.</returns>
</member>
<member name="T:Telegrator.DiceType">
<summary>
Enumeration of dice types supported by Telegram.
@@ -4996,6 +5097,7 @@
<param name="extraData"></param>
<param name="filters"></param>
<param name="awaitingProvider"></param>
<param name="stateStorage"></param>
</member>
<member name="M:Telegrator.Handlers.HandlerContainer`1.CreateChild``1">
<summary>
@@ -6548,6 +6650,20 @@
<returns>The chat ID as a long value.</returns>
<exception cref="T:System.ArgumentException">Thrown when the update does not contain a valid chat ID.</exception>
</member>
<member name="T:Telegrator.States.DefaultStateStorage">
<summary>
Defines default in-memory state storage
</summary>
</member>
<member name="M:Telegrator.States.DefaultStateStorage.DeleteAsync(System.String,System.Threading.CancellationToken)">
<inheritdoc/>
</member>
<member name="M:Telegrator.States.DefaultStateStorage.GetAsync``1(System.String,System.Threading.CancellationToken)">
<inheritdoc/>
</member>
<member name="M:Telegrator.States.DefaultStateStorage.SetAsync``1(System.String,``0,System.Threading.CancellationToken)">
<inheritdoc/>
</member>
<member name="T:Telegrator.States.EnumStateMachine`1">
<summary>
State machine implementation for enum-based states.
@@ -6581,6 +6697,29 @@
<returns>The sender ID as a long value.</returns>
<exception cref="T:System.ArgumentException">Thrown when the update does not contain a valid sender ID.</exception>
</member>
<member name="T:Telegrator.States.StateMachine`2">
<inheritdoc cref="T:Telegrator.Core.States.IStateMachine`1"/>
</member>
<member name="M:Telegrator.States.StateMachine`2.#ctor(Telegrator.Core.States.IStateStorage,Telegram.Bot.Types.Update)">
<inheritdoc cref="T:Telegrator.Core.States.IStateMachine`1"/>
</member>
<member name="F:Telegrator.States.StateMachine`2.KeyResolver">
<summary>
Chosen key resolver
</summary>
</member>
<member name="M:Telegrator.States.StateMachine`2.Advance(System.Threading.CancellationToken)">
<inheritdoc cref="M:Telegrator.Core.States.IStateMachine`1.Advance(Telegrator.Core.States.IStateStorage,System.String,System.Threading.CancellationToken)"/>
</member>
<member name="M:Telegrator.States.StateMachine`2.Current(System.Threading.CancellationToken)">
<inheritdoc cref="M:Telegrator.Core.States.IStateMachine`1.Current(Telegrator.Core.States.IStateStorage,System.String,System.Threading.CancellationToken)"/>
</member>
<member name="M:Telegrator.States.StateMachine`2.Reset(System.Threading.CancellationToken)">
<inheritdoc cref="M:Telegrator.Core.States.IStateMachine`1.Reset(Telegrator.Core.States.IStateStorage,System.String,System.Threading.CancellationToken)"/>
</member>
<member name="M:Telegrator.States.StateMachine`2.Retreat(System.Threading.CancellationToken)">
<inheritdoc cref="M:Telegrator.Core.States.IStateMachine`1.Retreat(Telegrator.Core.States.IStateStorage,System.String,System.Threading.CancellationToken)"/>
</member>
<member name="T:Telegrator.TelegramBotInfo">
<summary>
Implementation of <see cref="T:Telegrator.Core.ITelegramBotInfo"/> that provides bot information.
@@ -6872,6 +7011,73 @@
</summary>
<returns>An enumerable of bot commands.</returns>
</member>
<member name="T:Telegrator.StateStorageExtensions">
<summary>
Provides extension methods for <see cref="T:Telegrator.Core.States.IStateStorage"/> to easily initialize state machines.
</summary>
</member>
<member name="M:Telegrator.StateStorageExtensions.GetStateMachine``1(Telegrator.Core.States.IStateStorage,Telegram.Bot.Types.Update)">
<summary>
Initializes a state machine using the default <see cref="T:Telegrator.States.EnumStateMachine`1"/> for the specified update.
</summary>
<typeparam name="TState">The enum type representing the state.</typeparam>
<param name="stateStorage">The storage mechanism used to persist the state.</param>
<param name="handlingUpdate">The update context to resolve the state key from.</param>
<returns>A new instance of <see cref="T:Telegrator.States.StateMachine`2"/>.</returns>
</member>
<member name="M:Telegrator.StateStorageExtensions.GetStateMachine``2(Telegrator.Core.States.IStateStorage,Telegram.Bot.Types.Update)">
<summary>
Initializes a specific custom state machine for the specified update.
</summary>
<typeparam name="TMachine">The type of the state machine logic implementation.</typeparam>
<typeparam name="TState">The type of the state.</typeparam>
<param name="stateStorage">The storage mechanism used to persist the state.</param>
<param name="handlingUpdate">The update context to resolve the state key from.</param>
<returns>A new instance of <see cref="T:Telegrator.States.StateMachine`2"/>.</returns>
</member>
<member name="M:Telegrator.StateStorageExtensions.ByChatId``2(Telegrator.Core.States.IStateStorage,Telegram.Bot.Types.Update)">
<summary>
Initializes a state machine and explicitly configures it to resolve keys by the chat ID.
</summary>
<typeparam name="TMachine">The type of the state machine logic implementation.</typeparam>
<typeparam name="TState">The type of the state.</typeparam>
<param name="stateStorage">The storage mechanism used to persist the state.</param>
<param name="handlingUpdate">The update context to resolve the state key from.</param>
<returns>A configured instance of <see cref="T:Telegrator.States.StateMachine`2"/>.</returns>
</member>
<member name="M:Telegrator.StateStorageExtensions.BySenderId``2(Telegrator.Core.States.IStateStorage,Telegram.Bot.Types.Update)">
<summary>
Initializes a state machine and explicitly configures it to resolve keys by the sender (user) ID.
</summary>
<typeparam name="TMachine">The type of the state machine logic implementation.</typeparam>
<typeparam name="TState">The type of the state.</typeparam>
<param name="stateStorage">The storage mechanism used to persist the state.</param>
<param name="handlingUpdate">The update context to resolve the state key from.</param>
<returns>A configured instance of <see cref="T:Telegrator.States.StateMachine`2"/>.</returns>
</member>
<member name="T:Telegrator.StateMachineExtensions">
<summary>
Provides fluent extension methods for configuring <see cref="T:Telegrator.States.StateMachine`2"/> instances.
</summary>
</member>
<member name="M:Telegrator.StateMachineExtensions.ByChatId``2(Telegrator.States.StateMachine{``0,``1})">
<summary>
Configures the state machine to use a <see cref="T:Telegrator.States.ChatIdResolver"/> for state key resolution.
</summary>
<typeparam name="TMachine">The type of the state machine logic implementation.</typeparam>
<typeparam name="TState">The type of the state.</typeparam>
<param name="stateMachine">The state machine instance to configure.</param>
<returns>The same state machine instance for method chaining.</returns>
</member>
<member name="M:Telegrator.StateMachineExtensions.BySenderId``2(Telegrator.States.StateMachine{``0,``1})">
<summary>
Configures the state machine to use a <see cref="T:Telegrator.States.SenderIdResolver"/> for state key resolution.
</summary>
<typeparam name="TMachine">The type of the state machine logic implementation.</typeparam>
<typeparam name="TState">The type of the state.</typeparam>
<param name="stateMachine">The state machine instance to configure.</param>
<returns>The same state machine instance for method chaining.</returns>
</member>
<member name="T:Telegrator.HandlersCollectionExtensions">
<summary>
Extension methods for handlers collections.
@@ -7034,5 +7240,582 @@
<param name="updateType"></param>
<returns></returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.CallbackData``1(``0,System.String)">
<summary>
Adds a CallbackDataAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "data">The data.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.CallbackInlineId``1(``0,System.String)">
<summary>
Adds a CallbackInlineIdAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "inlineMessageId">The inlineMessageId.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.CommandAllias``1(``0,System.String[])">
<summary>
Adds a CommandAlliasAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "alliases">The alliases.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.ArgumentCount``1(``0,System.Int32)">
<summary>
Adds a ArgumentCountAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "count">The count.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.ArgumentStartsWith``1(``0,System.String,System.StringComparison,System.Int32)">
<summary>
Adds a ArgumentStartsWithAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "content">The content.</param>
<param name = "comparison">The comparison.</param>
<param name = "index">The index.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.ArgumentEndsWith``1(``0,System.String,System.StringComparison,System.Int32)">
<summary>
Adds a ArgumentEndsWithAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "content">The content.</param>
<param name = "comparison">The comparison.</param>
<param name = "index">The index.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.ArgumentContains``1(``0,System.String,System.StringComparison,System.Int32)">
<summary>
Adds a ArgumentContainsAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "content">The content.</param>
<param name = "comparison">The comparison.</param>
<param name = "index">The index.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.ArgumentEquals``1(``0,System.String,System.StringComparison,System.Int32)">
<summary>
Adds a ArgumentEqualsAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "content">The content.</param>
<param name = "comparison">The comparison.</param>
<param name = "index">The index.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.ArgumentRegex``1(``0,System.String,System.Text.RegularExpressions.RegexOptions,System.Int32)">
<summary>
Adds a ArgumentRegexAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "pattern">The pattern.</param>
<param name = "options">The options.</param>
<param name = "index">The index.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.IsDebugEnvironment``1(``0)">
<summary>
Adds a IsDebugEnvironmentAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.IsReleaseEnvironment``1(``0)">
<summary>
Adds a IsReleaseEnvironmentAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.EnvironmentVariable``1(``0,System.String,System.String,System.StringComparison)">
<summary>
Adds a EnvironmentVariableAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "variable">The variable.</param>
<param name = "value">The value.</param>
<param name = "comparison">The comparison.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.EnvironmentVariable``1(``0,System.String,System.String)">
<summary>
Adds a EnvironmentVariableAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "variable">The variable.</param>
<param name = "value">The value.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.EnvironmentVariable``1(``0,System.String)">
<summary>
Adds a EnvironmentVariableAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "variable">The variable.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.EnvironmentVariable``1(``0,System.String,System.StringComparison)">
<summary>
Adds a EnvironmentVariableAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "variable">The variable.</param>
<param name = "comparison">The comparison.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.Mentioned``1(``0)">
<summary>
Adds a MentionedAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.Mentioned``1(``0,System.Int32)">
<summary>
Adds a MentionedAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "offset">The offset.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.Mentioned``1(``0,System.String)">
<summary>
Adds a MentionedAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "mention">The mention.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.Mentioned``1(``0,System.String,System.Int32)">
<summary>
Adds a MentionedAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "mention">The mention.</param>
<param name = "offset">The offset.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.ChatIsForum``1(``0)">
<summary>
Adds a ChatIsForumAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.ChatId``1(``0,System.Int64)">
<summary>
Adds a ChatIdAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "id">The id.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.InChatType``1(``0,Telegram.Bot.Types.Enums.ChatType)">
<summary>
Adds a ChatTypeAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "type">The type.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.InChatType``1(``0,Telegrator.ChatTypeFlags)">
<summary>
Adds a ChatTypeAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "flags">The flags.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.ChatTitle``1(``0,System.String,System.StringComparison)">
<summary>
Adds a ChatTitleAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "title">The title.</param>
<param name = "comparison">The comparison.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.ChatTitle``1(``0,System.String)">
<summary>
Adds a ChatTitleAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "title">The title.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.ChatUsername``1(``0,System.String,System.StringComparison)">
<summary>
Adds a ChatUsernameAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "userName">The userName.</param>
<param name = "comparison">The comparison.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.ChatUsername``1(``0,System.String)">
<summary>
Adds a ChatUsernameAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "userName">The userName.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.ChatName``1(``0,System.String,System.String,System.StringComparison)">
<summary>
Adds a ChatNameAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "firstName">The firstName.</param>
<param name = "lastName">The lastName.</param>
<param name = "comparison">The comparison.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.ChatName``1(``0,System.String,System.String)">
<summary>
Adds a ChatNameAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "firstName">The firstName.</param>
<param name = "lastName">The lastName.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.MessageRegex``1(``0,System.String,System.Text.RegularExpressions.RegexOptions)">
<summary>
Adds a MessageRegexAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "pattern">The pattern.</param>
<param name = "regexOptions">The regexOptions.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.MessageRegex``1(``0,System.Text.RegularExpressions.Regex)">
<summary>
Adds a MessageRegexAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "regex">The regex.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.DiceThrowed``1(``0,System.Int32)">
<summary>
Adds a DiceThrowedAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "value">The value.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.DiceThrowed``1(``0,Telegrator.DiceType,System.Int32)">
<summary>
Adds a DiceThrowedAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "diceType">The diceType.</param>
<param name = "value">The value.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.IsAutomaticFormwardMessage``1(``0)">
<summary>
Adds a IsAutomaticFormwardMessageAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.IsFromOfflineMessage``1(``0)">
<summary>
Adds a IsFromOfflineMessageAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.IsServiceMessageMessage``1(``0)">
<summary>
Adds a IsServiceMessageMessageAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.IsTopicMessageMessage``1(``0)">
<summary>
Adds a IsTopicMessageMessageAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.MessageHasEntity``1(``0,Telegram.Bot.Types.Enums.MessageEntityType)">
<summary>
Adds a MessageHasEntityAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "type">The type.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.MessageHasEntity``1(``0,Telegram.Bot.Types.Enums.MessageEntityType,System.Int32,System.Nullable{System.Int32})">
<summary>
Adds a MessageHasEntityAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "type">The type.</param>
<param name = "offset">The offset.</param>
<param name = "length">The length.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.MessageHasEntity``1(``0,Telegram.Bot.Types.Enums.MessageEntityType,System.String,System.StringComparison)">
<summary>
Adds a MessageHasEntityAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "type">The type.</param>
<param name = "content">The content.</param>
<param name = "stringComparison">The stringComparison.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.MessageHasEntity``1(``0,Telegram.Bot.Types.Enums.MessageEntityType,System.Int32,System.Nullable{System.Int32},System.String,System.StringComparison)">
<summary>
Adds a MessageHasEntityAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "type">The type.</param>
<param name = "offset">The offset.</param>
<param name = "length">The length.</param>
<param name = "content">The content.</param>
<param name = "stringComparison">The stringComparison.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.MeReplied``1(``0)">
<summary>
Adds a MeRepliedAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.HasReply``1(``0,System.Int32)">
<summary>
Adds a HasReplyAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "replyDepth">The replyDepth.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.FromReplyChain``1(``0,System.Int32)">
<summary>
Adds a FromReplyChainAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "replyDepth">The replyDepth.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.FromUsername``1(``0,System.String)">
<summary>
Adds a FromUsernameAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "username">The username.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.FromUsername``1(``0,System.String,System.StringComparison)">
<summary>
Adds a FromUsernameAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "username">The username.</param>
<param name = "comparison">The comparison.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.FromUser``1(``0,System.String,System.String,System.StringComparison)">
<summary>
Adds a FromUserAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "firstName">The firstName.</param>
<param name = "lastName">The lastName.</param>
<param name = "comparison">The comparison.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.FromUser``1(``0,System.String,System.String)">
<summary>
Adds a FromUserAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "firstName">The firstName.</param>
<param name = "lastName">The lastName.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.FromUser``1(``0,System.String)">
<summary>
Adds a FromUserAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "firstName">The firstName.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.FromUser``1(``0,System.String,System.StringComparison)">
<summary>
Adds a FromUserAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "firstName">The firstName.</param>
<param name = "comparison">The comparison.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.FromUserId``1(``0,System.Int64)">
<summary>
Adds a FromUserIdAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "userId">The userId.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.NotFromBot``1(``0)">
<summary>
Adds a NotFromBotAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.FromBot``1(``0)">
<summary>
Adds a FromBotAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.FromPremiumUser``1(``0)">
<summary>
Adds a FromPremiumUserAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.TextStartsWith``1(``0,System.String,System.StringComparison)">
<summary>
Adds a TextStartsWithAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "content">The content.</param>
<param name = "comparison">The comparison.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.TextEndsWith``1(``0,System.String,System.StringComparison)">
<summary>
Adds a TextEndsWithAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "content">The content.</param>
<param name = "comparison">The comparison.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.TextContains``1(``0,System.String,System.StringComparison)">
<summary>
Adds a TextContainsAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "content">The content.</param>
<param name = "comparison">The comparison.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.TextEquals``1(``0,System.String,System.StringComparison)">
<summary>
Adds a TextEqualsAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "content">The content.</param>
<param name = "comparison">The comparison.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.HasText``1(``0)">
<summary>
Adds a HasTextAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.TextContainsWord``1(``0,System.String,System.StringComparison,System.Int32)">
<summary>
Adds a TextContainsWordAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "word">The word.</param>
<param name = "comparison">The comparison.</param>
<param name = "startIndex">The startIndex.</param>
<returns>The same builder instance.</returns>
</member>
<member name="M:Telegrator.HandlerBuilderExtensions.Welcome``1(``0,System.Boolean)">
<summary>
Adds a WelcomeAttribute target filter to the handler builder.
</summary>
<typeparam name = "TBuilder">The builder type.</typeparam>
<param name = "builder">The handler builder.</param>
<param name = "onlyFirst">The onlyFirst.</param>
<returns>The same builder instance.</returns>
</member>
</members>
</doc>
@@ -4,6 +4,10 @@ using Telegrator.Core.States;
namespace Telegrator.States;
/// <summary>
/// Provides a Redis-based implementation of the <see cref="IStateStorage"/> interface.
/// Serializes state objects to JSON format before storing them in the Redis database.
/// </summary>
public class RedisStateStorage(IConnectionMultiplexer redis) : IStateStorage
{
private readonly IDatabase _db = redis.GetDatabase();
@@ -30,6 +34,6 @@ public class RedisStateStorage(IConnectionMultiplexer redis) : IStateStorage
/// <inheritdoc/>
public async Task DeleteAsync(string key, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
await _db.KeyDeleteAsync(key);
}
}
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>
@@ -6,14 +6,25 @@ using Telegrator.Filters;
namespace Telegrator.Annotations;
/// <summary>
/// Attribute for filtering updates where resolved state matches target value.
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
/// <param name="value"></param>
public class StateAttribute<TKey, TValue>(TValue? value) : UpdateFilterAttribute<Update>(new StateKeyFilter<TKey, TValue>(value))
where TKey : IStateKeyResolver, new()
where TValue : IEquatable<TValue>
{
/// <summary>
/// The targetting state value.
/// </summary>
public TValue? Value => value;
/// <inheritdoc/>
public override UpdateType[] AllowedTypes => Update.AllTypes;
/// <inheritdoc/>
public override Update? GetFilterringTarget(Update update)
{
return update;
@@ -1,9 +1,44 @@
namespace Telegrator.Core.States;
/// <summary>
/// Defines a contract for a state machine that manages transitions and retrieves states for specific updates.
/// </summary>
/// <typeparam name="TState">The type of the state. Must implement <see cref="IEquatable{T}"/>.</typeparam>
public interface IStateMachine<TState> where TState : IEquatable<TState>
{
/// <summary>
/// Gets the current state associated with the specified update key.
/// </summary>
/// <param name="storage">The storage mechanism used to persist the state.</param>
/// <param name="updateKey">The unique key identifying the current update context (e.g., chat and user ID).</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the current state, or the default value if no state is found.</returns>
Task<TState?> Current(IStateStorage storage, string updateKey, CancellationToken cancellationToken = default);
/// <summary>
/// Advances the state machine to the next state in the sequence.
/// </summary>
/// <param name="storage">The storage mechanism used to persist the state.</param>
/// <param name="updateKey">The unique key identifying the current update context.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>A task that represents the asynchronous transition operation.</returns>
Task Advance(IStateStorage storage, string updateKey, CancellationToken cancellationToken = default);
/// <summary>
/// Moves the state machine backward to the previous state in the sequence.
/// </summary>
/// <param name="storage">The storage mechanism used to persist the state.</param>
/// <param name="updateKey">The unique key identifying the current update context.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>A task that represents the asynchronous transition operation.</returns>
Task Retreat(IStateStorage storage, string updateKey, CancellationToken cancellationToken = default);
/// <summary>
/// Resets the state machine to its initial or default state.
/// </summary>
/// <param name="storage">The storage mechanism used to persist the state.</param>
/// <param name="updateKey">The unique key identifying the current update context.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>A task that represents the asynchronous reset operation.</returns>
Task Reset(IStateStorage storage, string updateKey, CancellationToken cancellationToken = default);
}
@@ -1,8 +1,34 @@
namespace Telegrator.Core.States;
/// <summary>
/// Defines a contract for an asynchronous state storage mechanism.
/// </summary>
public interface IStateStorage
{
/// <summary>
/// Saves or updates a state value associated with the specified key.
/// </summary>
/// <typeparam name="T">The type of the state object.</typeparam>
/// <param name="key">The unique identifier for the state.</param>
/// <param name="state">The state object to store.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>A task that represents the asynchronous save operation.</returns>
Task SetAsync<T>(string key, T state, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves a state value associated with the specified key.
/// </summary>
/// <typeparam name="T">The type of the state object to retrieve.</typeparam>
/// <param name="key">The unique identifier for the state.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>A task that represents the asynchronous retrieve operation. The task result contains the state object if found; otherwise, the default value of <typeparamref name="T"/>.</returns>
Task<T?> GetAsync<T>(string key, CancellationToken cancellationToken = default);
/// <summary>
/// Deletes the state value associated with the specified key.
/// </summary>
/// <param name="key">The unique identifier for the state to remove.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>A task that represents the asynchronous delete operation.</returns>
Task DeleteAsync(string key, CancellationToken cancellationToken = default);
}
@@ -61,6 +61,7 @@ namespace Telegrator.Handlers
/// <param name="extraData"></param>
/// <param name="filters"></param>
/// <param name="awaitingProvider"></param>
/// <param name="stateStorage"></param>
public HandlerContainer(TUpdate actualUpdate, Update handlingUpdate, ITelegramBotClient client, Dictionary<string, object> extraData, CompletedFiltersList filters, IAwaitingProvider awaitingProvider, IStateStorage stateStorage)
{
ActualUpdate = actualUpdate;
@@ -3,10 +3,14 @@ using Telegrator.Core.States;
namespace Telegrator.States;
/// <summary>
/// Defines default in-memory state storage
/// </summary>
public class DefaultStateStorage : IStateStorage
{
private readonly ConcurrentDictionary<string, object> storage = [];
/// <inheritdoc/>
public Task DeleteAsync(string key, CancellationToken cancellationToken = default)
{
if (key is null)
@@ -18,6 +22,7 @@ public class DefaultStateStorage : IStateStorage
return Task.CompletedTask;
}
/// <inheritdoc/>
public Task<T?> GetAsync<T>(string key, CancellationToken ccancellationTokent = default)
{
if (key is null)
@@ -29,6 +34,7 @@ public class DefaultStateStorage : IStateStorage
return Task.FromResult(default(T));
}
/// <inheritdoc/>
public Task SetAsync<T>(string key, T state, CancellationToken cancellationToken = default)
{
if (key is null)
+8
View File
@@ -3,6 +3,7 @@ using Telegrator.Core.States;
namespace Telegrator.States;
/// <inheritdoc cref="IStateMachine{TState}"/>
public class StateMachine<TMachine, TState>(IStateStorage stateStorage, Update handlingUpdate)
where TMachine : IStateMachine<TState>, new()
where TState : IEquatable<TState>
@@ -11,8 +12,12 @@ public class StateMachine<TMachine, TState>(IStateStorage stateStorage, Update h
private readonly Update _handlingUpdate = handlingUpdate;
private readonly IStateMachine<TState> _stateMachine = new TMachine();
/// <summary>
/// Chosen key resolver
/// </summary>
public IStateKeyResolver? KeyResolver;
/// <inheritdoc cref="IStateMachine{TState}.Advance(IStateStorage, string, CancellationToken)"/>
public async Task Advance(CancellationToken cancellationToken = default)
{
if (KeyResolver is null)
@@ -25,6 +30,7 @@ public class StateMachine<TMachine, TState>(IStateStorage stateStorage, Update h
await _stateMachine.Advance(_stateStorage, key, cancellationToken);
}
/// <inheritdoc cref="IStateMachine{TState}.Current(IStateStorage, string, CancellationToken)"/>
public async Task<TState?> Current(CancellationToken cancellationToken = default)
{
if (KeyResolver is null)
@@ -37,6 +43,7 @@ public class StateMachine<TMachine, TState>(IStateStorage stateStorage, Update h
return await _stateMachine.Current(_stateStorage, key, cancellationToken);
}
/// <inheritdoc cref="IStateMachine{TState}.Reset(IStateStorage, string, CancellationToken)"/>
public async Task Reset(CancellationToken cancellationToken = default)
{
if (KeyResolver is null)
@@ -49,6 +56,7 @@ public class StateMachine<TMachine, TState>(IStateStorage stateStorage, Update h
await _stateMachine.Reset(_stateStorage, key, cancellationToken);
}
/// <inheritdoc cref="IStateMachine{TState}.Retreat(IStateStorage, string, CancellationToken)"/>
public async Task Retreat(CancellationToken cancellationToken = default)
{
if (KeyResolver is null)
+51
View File
@@ -284,30 +284,74 @@ namespace Telegrator
}
}
/// <summary>
/// Provides extension methods for <see cref="IStateStorage"/> to easily initialize state machines.
/// </summary>
public static class StateStorageExtensions
{
/// <summary>
/// Initializes a state machine using the default <see cref="EnumStateMachine{TState}"/> for the specified update.
/// </summary>
/// <typeparam name="TState">The enum type representing the state.</typeparam>
/// <param name="stateStorage">The storage mechanism used to persist the state.</param>
/// <param name="handlingUpdate">The update context to resolve the state key from.</param>
/// <returns>A new instance of <see cref="StateMachine{TMachine, TState}"/>.</returns>
public static StateMachine<EnumStateMachine<TState>, TState> GetStateMachine<TState>(this IStateStorage stateStorage, Update handlingUpdate)
where TState : struct, Enum, IEquatable<TState>
=> new StateMachine<EnumStateMachine<TState>, TState>(stateStorage, handlingUpdate);
/// <summary>
/// Initializes a specific custom state machine for the specified update.
/// </summary>
/// <typeparam name="TMachine">The type of the state machine logic implementation.</typeparam>
/// <typeparam name="TState">The type of the state.</typeparam>
/// <param name="stateStorage">The storage mechanism used to persist the state.</param>
/// <param name="handlingUpdate">The update context to resolve the state key from.</param>
/// <returns>A new instance of <see cref="StateMachine{TMachine, TState}"/>.</returns>
public static StateMachine<TMachine, TState> GetStateMachine<TMachine, TState>(this IStateStorage stateStorage, Update handlingUpdate)
where TMachine : IStateMachine<TState>, new()
where TState : IEquatable<TState>
=> new StateMachine<TMachine, TState>(stateStorage, handlingUpdate);
/// <summary>
/// Initializes a state machine and explicitly configures it to resolve keys by the chat ID.
/// </summary>
/// <typeparam name="TMachine">The type of the state machine logic implementation.</typeparam>
/// <typeparam name="TState">The type of the state.</typeparam>
/// <param name="stateStorage">The storage mechanism used to persist the state.</param>
/// <param name="handlingUpdate">The update context to resolve the state key from.</param>
/// <returns>A configured instance of <see cref="StateMachine{TMachine, TState}"/>.</returns>
public static StateMachine<TMachine, TState> ByChatId<TMachine, TState>(this IStateStorage stateStorage, Update handlingUpdate)
where TMachine : IStateMachine<TState>, new()
where TState : IEquatable<TState>
=> new StateMachine<TMachine, TState>(stateStorage, handlingUpdate).ByChatId();
/// <summary>
/// Initializes a state machine and explicitly configures it to resolve keys by the sender (user) ID.
/// </summary>
/// <typeparam name="TMachine">The type of the state machine logic implementation.</typeparam>
/// <typeparam name="TState">The type of the state.</typeparam>
/// <param name="stateStorage">The storage mechanism used to persist the state.</param>
/// <param name="handlingUpdate">The update context to resolve the state key from.</param>
/// <returns>A configured instance of <see cref="StateMachine{TMachine, TState}"/>.</returns>
public static StateMachine<TMachine, TState> BySenderId<TMachine, TState>(this IStateStorage stateStorage, Update handlingUpdate)
where TMachine : IStateMachine<TState>, new()
where TState : IEquatable<TState>
=> new StateMachine<TMachine, TState>(stateStorage, handlingUpdate).BySenderId();
}
/// <summary>
/// Provides fluent extension methods for configuring <see cref="StateMachine{TMachine, TState}"/> instances.
/// </summary>
public static class StateMachineExtensions
{
/// <summary>
/// Configures the state machine to use a <see cref="ChatIdResolver"/> for state key resolution.
/// </summary>
/// <typeparam name="TMachine">The type of the state machine logic implementation.</typeparam>
/// <typeparam name="TState">The type of the state.</typeparam>
/// <param name="stateMachine">The state machine instance to configure.</param>
/// <returns>The same state machine instance for method chaining.</returns>
public static StateMachine<TMachine, TState> ByChatId<TMachine, TState>(this StateMachine<TMachine, TState> stateMachine)
where TMachine : IStateMachine<TState>, new()
where TState : IEquatable<TState>
@@ -316,6 +360,13 @@ namespace Telegrator
return stateMachine;
}
/// <summary>
/// Configures the state machine to use a <see cref="SenderIdResolver"/> for state key resolution.
/// </summary>
/// <typeparam name="TMachine">The type of the state machine logic implementation.</typeparam>
/// <typeparam name="TState">The type of the state.</typeparam>
/// <param name="stateMachine">The state machine instance to configure.</param>
/// <returns>The same state machine instance for method chaining.</returns>
public static StateMachine<TMachine, TState> BySenderId<TMachine, TState>(this StateMachine<TMachine, TState> stateMachine)
where TMachine : IStateMachine<TState>, new()
where TState : IEquatable<TState>