Added missing XML-Summaries
This commit is contained in:
@@ -3,6 +3,10 @@ using Telegrator.Filters;
|
|||||||
|
|
||||||
namespace Telegrator.Annotations
|
namespace Telegrator.Annotations
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Attribute for filtering messages where a command has arguments count >= <paramref name="count"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="count"></param>
|
||||||
public class ArgumentCountAttribute(int count)
|
public class ArgumentCountAttribute(int count)
|
||||||
: MessageFilterAttribute(new ArgumentCountFilter(count))
|
: MessageFilterAttribute(new ArgumentCountFilter(count))
|
||||||
{ }
|
{ }
|
||||||
@@ -52,7 +56,6 @@ namespace Telegrator.Annotations
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pattern">The regular expression pattern to match against the command argument.</param>
|
/// <param name="pattern">The regular expression pattern to match against the command argument.</param>
|
||||||
/// <param name="options">The regex options to use for the pattern matching.</param>
|
/// <param name="options">The regex options to use for the pattern matching.</param>
|
||||||
/// <param name="matchTimeout">The timeout for the regex match operation.</param>
|
|
||||||
/// <param name="index">The index of the argument to check (0-based).</param>
|
/// <param name="index">The index of the argument to check (0-based).</param>
|
||||||
public class ArgumentRegexAttribute(string pattern, RegexOptions options = RegexOptions.None, int index = 0)
|
public class ArgumentRegexAttribute(string pattern, RegexOptions options = RegexOptions.None, int index = 0)
|
||||||
: MessageFilterAttribute(new ArgumentRegexFilter(pattern, options, index: index))
|
: MessageFilterAttribute(new ArgumentRegexFilter(pattern, options, index: index))
|
||||||
|
|||||||
@@ -42,10 +42,15 @@ namespace Telegrator.Filters
|
|||||||
protected abstract bool CanPassNext(FilterExecutionContext<Message> context);
|
protected abstract bool CanPassNext(FilterExecutionContext<Message> context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Filter that checks if a command has arguments count >= <paramref name="count"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="count"></param>
|
||||||
public class ArgumentCountFilter(int count) : Filter<Message>
|
public class ArgumentCountFilter(int count) : Filter<Message>
|
||||||
{
|
{
|
||||||
private readonly int Count = count;
|
private readonly int Count = count;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
public override bool CanPass(FilterExecutionContext<Message> context)
|
public override bool CanPass(FilterExecutionContext<Message> context)
|
||||||
{
|
{
|
||||||
CommandHandlerAttribute attr = context.CompletedFilters.Get<CommandHandlerAttribute>(0);
|
CommandHandlerAttribute attr = context.CompletedFilters.Get<CommandHandlerAttribute>(0);
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ namespace Telegrator.Handlers.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public List<FilterFallbackInfo> UpdateFilters { get; } = [];
|
public List<FilterFallbackInfo> UpdateFilters { get; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the failure is due to a specific filter.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public bool Only(string name, int index = 0)
|
public bool Only(string name, int index = 0)
|
||||||
{
|
{
|
||||||
FilterFallbackInfo? info = UpdateFilters.SingleSafe(info => info.Failed);
|
FilterFallbackInfo? info = UpdateFilters.SingleSafe(info => info.Failed);
|
||||||
@@ -48,6 +54,11 @@ namespace Telegrator.Handlers.Components
|
|||||||
return ReferenceEquals(target, info);
|
return ReferenceEquals(target, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the failure is due to a specific filter.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="names"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public bool Only(string[] names)
|
public bool Only(string[] names)
|
||||||
{
|
{
|
||||||
return UpdateFilters
|
return UpdateFilters
|
||||||
@@ -56,6 +67,12 @@ namespace Telegrator.Handlers.Components
|
|||||||
.SequenceEqual(names);
|
.SequenceEqual(names);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the failure is due to all filters except one.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public bool Except(string name, int index = 0)
|
public bool Except(string name, int index = 0)
|
||||||
{
|
{
|
||||||
FilterFallbackInfo? info = UpdateFilters.SingleSafe(info => !info.Failed);
|
FilterFallbackInfo? info = UpdateFilters.SingleSafe(info => !info.Failed);
|
||||||
@@ -66,6 +83,11 @@ namespace Telegrator.Handlers.Components
|
|||||||
return ReferenceEquals(target, info);
|
return ReferenceEquals(target, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the failure is due to all filters except one.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="names"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public bool Except(string[] names)
|
public bool Except(string[] names)
|
||||||
{
|
{
|
||||||
return UpdateFilters
|
return UpdateFilters
|
||||||
@@ -74,6 +96,12 @@ namespace Telegrator.Handlers.Components
|
|||||||
.SequenceEqual(names);
|
.SequenceEqual(names);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the failure is due to aall attribute type, excluding one.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The attribute type to check for.</typeparam>
|
||||||
|
/// <param name="index">The index of the filter to check (default: 0).</param>
|
||||||
|
/// <returns>True if the failure is exclusively due to the specified attribute type; otherwise, false.</returns>
|
||||||
public bool ExceptAttribute<T>(int index = 0) where T : UpdateFilterAttributeBase
|
public bool ExceptAttribute<T>(int index = 0) where T : UpdateFilterAttributeBase
|
||||||
=> Except(nameof(T), index);
|
=> Except(nameof(T), index);
|
||||||
|
|
||||||
|
|||||||
@@ -1009,6 +1009,13 @@ namespace Telegrator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return index of first element that satisfies the condition
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static int IndexOf<T>(this IEnumerable<T> source, Func<T, bool> predicate)
|
public static int IndexOf<T>(this IEnumerable<T> source, Func<T, bool> predicate)
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@@ -1023,12 +1030,34 @@ 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)
|
public static IEnumerable<T> Repeat<T>(this T item, int times)
|
||||||
=> Enumerable.Range(0, times).Select(_ => item);
|
=> Enumerable.Range(0, times).Select(_ => item);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static T? SingleSafe<T>(this IEnumerable<T> source)
|
public static T? SingleSafe<T>(this IEnumerable<T> source)
|
||||||
=> source.Count() == 1 ? source.ElementAt(0) : default;
|
=> source.Count() == 1 ? source.ElementAt(0) : default;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the only element of a sequence that satisfies a specified condition or a default value if no such element exists.
|
||||||
|
/// This method return default if more than one element satisfies the condition.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="predicate"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static T? SingleSafe<T>(this IEnumerable<T> source, Func<T, bool> predicate)
|
public static T? SingleSafe<T>(this IEnumerable<T> source, Func<T, bool> predicate)
|
||||||
{
|
{
|
||||||
source = source.Where(predicate);
|
source = source.Where(predicate);
|
||||||
@@ -1198,6 +1227,11 @@ namespace Telegrator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return new string with first found letter set to upper case
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="target"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static string FirstLetterToUpper(this string target)
|
public static string FirstLetterToUpper(this string target)
|
||||||
{
|
{
|
||||||
char[] chars = target.ToCharArray();
|
char[] chars = target.ToCharArray();
|
||||||
@@ -1206,6 +1240,11 @@ namespace Telegrator
|
|||||||
return new string(chars);
|
return new string(chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return new string with first found letter set to lower case
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="target"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static string FirstLetterToLower(this string target)
|
public static string FirstLetterToLower(this string target)
|
||||||
{
|
{
|
||||||
char[] chars = target.ToCharArray();
|
char[] chars = target.ToCharArray();
|
||||||
|
|||||||
Reference in New Issue
Block a user