* warnings fixes
This commit is contained in:
@@ -9,3 +9,4 @@ using System.Diagnostics.CodeAnalysis;
|
||||
[assembly: SuppressMessage("Style", "IDE0090")]
|
||||
[assembly: SuppressMessage("Usage", "CA2254")]
|
||||
[assembly: SuppressMessage("Maintainability", "CA1510")]
|
||||
[assembly: SuppressMessage("Style", "IDE0270")]
|
||||
|
||||
@@ -9,3 +9,4 @@ using System.Diagnostics.CodeAnalysis;
|
||||
[assembly: SuppressMessage("Style", "IDE0090")]
|
||||
[assembly: SuppressMessage("Usage", "CA2254")]
|
||||
[assembly: SuppressMessage("Maintainability", "CA1510")]
|
||||
[assembly: SuppressMessage("Style", "IDE0270")]
|
||||
|
||||
@@ -8,3 +8,4 @@ using System.Diagnostics.CodeAnalysis;
|
||||
[assembly: SuppressMessage("Style", "IDE0290")]
|
||||
[assembly: SuppressMessage("Style", "IDE0090")]
|
||||
[assembly: SuppressMessage("Style", "IDE0057")]
|
||||
[assembly: SuppressMessage("Style", "IDE0270")]
|
||||
|
||||
@@ -58,7 +58,8 @@ public static partial class HandlerBuilderExtensions
|
||||
handlerBuilder.AddFilters(filters);
|
||||
return handlerBuilder;
|
||||
}
|
||||
|
||||
|
||||
#pragma warning disable CS1574
|
||||
/// <inheritdoc cref="HandlerBuilderBase.SetState{TKey, TValue}(TValue?)"/>
|
||||
public static TBuilder SetState<TBuilder, TKey, TValue>(this TBuilder handlerBuilder, TValue? myState)
|
||||
where TBuilder : HandlerBuilderBase
|
||||
@@ -68,6 +69,7 @@ public static partial class HandlerBuilderExtensions
|
||||
handlerBuilder.SetState<TKey, TValue>(myState);
|
||||
return handlerBuilder;
|
||||
}
|
||||
#pragma warning restore CS1574
|
||||
|
||||
/// <summary>
|
||||
/// Adds a targeted filter for a specific filter target type.
|
||||
|
||||
@@ -16,7 +16,7 @@ public class DefaultStateStorage : IStateStorage
|
||||
if (key is null)
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
|
||||
if (!storage.TryRemove(key, out object value))
|
||||
if (!storage.TryRemove(key, out _))
|
||||
throw new Exception("Failed to remove key '" + key + "' from storage.");
|
||||
|
||||
return Task.CompletedTask;
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Telegrator.States;
|
||||
public class EnumStateMachine<TEnum> : IStateMachine<TEnum> where TEnum : struct, Enum, IEquatable<TEnum>
|
||||
{
|
||||
private readonly TEnum[] _states = Enum.GetValues(typeof(TEnum)).Cast<TEnum>().ToArray();
|
||||
private TEnum _defaultState => _states.FirstOrDefault();
|
||||
private TEnum DefaultState => _states.FirstOrDefault();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<TEnum> Current(IStateStorage storage, string updateKey, CancellationToken cancellationToken = default)
|
||||
@@ -19,7 +19,7 @@ public class EnumStateMachine<TEnum> : IStateMachine<TEnum> where TEnum : struct
|
||||
TEnum state = await storage.GetAsync<TEnum>(key, cancellationToken);
|
||||
|
||||
return EqualityComparer<TEnum>.Default.Equals(state, default)
|
||||
? _defaultState : state;
|
||||
? DefaultState : state;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -54,7 +54,7 @@ public class EnumStateMachine<TEnum> : IStateMachine<TEnum> where TEnum : struct
|
||||
public async Task Reset(IStateStorage storage, string updateKey, CancellationToken cancellationToken = default)
|
||||
{
|
||||
string key = FormatKey(updateKey);
|
||||
await storage.SetAsync(key, _defaultState, cancellationToken);
|
||||
await storage.SetAsync(key, DefaultState, cancellationToken);
|
||||
}
|
||||
|
||||
private static string FormatKey(string updateKey)
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="10.0.3" />
|
||||
<PackageReference Include="System.Threading.Channels" Version="10.0.3" />
|
||||
<PackageReference Include="Telegram.Bot" Version="22.9.5.3" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -515,6 +515,21 @@ public static partial class HandlersCollectionExtensions
|
||||
/// </summary>
|
||||
public static partial class UpdateExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extracts the IETF language tag of the user's client from the update.
|
||||
/// </summary>
|
||||
public static string? GetUserLanguageCode(this Update update) => update switch
|
||||
{
|
||||
{ Message.From: { } from } => from.LanguageCode,
|
||||
{ EditedMessage.From: { } from } => from.LanguageCode,
|
||||
{ CallbackQuery.From: { } from } => from.LanguageCode,
|
||||
{ InlineQuery.From: { } from } => from.LanguageCode,
|
||||
{ ChatJoinRequest.From: { } from } => from.LanguageCode,
|
||||
{ PreCheckoutQuery.From: { } from } => from.LanguageCode,
|
||||
{ ShippingQuery.From: { } from } => from.LanguageCode,
|
||||
_ => null
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Selects from Update an object from which you can get the sender's ID
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user