* Fixed "MentionedAttribute"
* Improved "MentionedFilter"
This commit is contained in:
@@ -13,7 +13,7 @@ namespace Telegrator.Annotations
|
|||||||
/// Initializes a new instance of the MentionedAttribute that matches any mention.
|
/// Initializes a new instance of the MentionedAttribute that matches any mention.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MentionedAttribute()
|
public MentionedAttribute()
|
||||||
: base(new MessageHasEntityFilter(MessageEntityType.Mention, 0, null), new MentionedFilter()) { }
|
: base(new MessageHasEntityFilter(MessageEntityType.Mention, null, null), new MentionedFilter()) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the MentionedAttribute that matches mentions at a specific offset.
|
/// Initializes a new instance of the MentionedAttribute that matches mentions at a specific offset.
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegrator.Filters.Components;
|
using Telegrator.Filters.Components;
|
||||||
|
|
||||||
namespace Telegrator.Filters
|
namespace Telegrator.Filters
|
||||||
@@ -45,8 +46,19 @@ namespace Telegrator.Filters
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
string userName = Mention ?? context.BotInfo.User.Username ?? throw new ArgumentNullException(nameof(context), "MentionedFilter requires BotInfo to be initialized");
|
string userName = Mention ?? context.BotInfo.User.Username ?? throw new ArgumentNullException(nameof(context), "MentionedFilter requires BotInfo to be initialized");
|
||||||
IEnumerable<MessageHasEntityFilter> entityFilter = context.CompletedFilters.Get<MessageHasEntityFilter>();
|
IEnumerable<MessageEntity> entities = context.CompletedFilters
|
||||||
return entityFilter.Any(fltr => fltr.FoundEntities.Any(ent => Target.Text.Substring(ent.Offset + 1, ent.Length - 1) == userName));
|
.Get<MessageHasEntityFilter>()
|
||||||
|
.SelectMany(ent => ent.FoundEntities)
|
||||||
|
.Where(ent => ent.Type == MessageEntityType.Mention);
|
||||||
|
|
||||||
|
foreach (MessageEntity ent in entities)
|
||||||
|
{
|
||||||
|
string mention = Target.Text.Substring(ent.Offset + 1, ent.Length - 1);
|
||||||
|
if (mention == userName)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ namespace Telegrator.Filters
|
|||||||
/// <param name="type">The entity type to filter by.</param>
|
/// <param name="type">The entity type to filter by.</param>
|
||||||
/// <param name="offset">The offset to filter by.</param>
|
/// <param name="offset">The offset to filter by.</param>
|
||||||
/// <param name="length">The length to filter by.</param>
|
/// <param name="length">The length to filter by.</param>
|
||||||
public MessageHasEntityFilter(MessageEntityType type, int offset, int? length)
|
public MessageHasEntityFilter(MessageEntityType type, int? offset, int? length)
|
||||||
{
|
{
|
||||||
EntityType = type;
|
EntityType = type;
|
||||||
Offset = offset;
|
Offset = offset;
|
||||||
@@ -215,7 +215,7 @@ namespace Telegrator.Filters
|
|||||||
/// <param name="type">The entity type to filter by.</param>
|
/// <param name="type">The entity type to filter by.</param>
|
||||||
/// <param name="content">The content to filter by.</param>
|
/// <param name="content">The content to filter by.</param>
|
||||||
/// <param name="stringComparison">The string comparison to use.</param>
|
/// <param name="stringComparison">The string comparison to use.</param>
|
||||||
public MessageHasEntityFilter(MessageEntityType type, string content, StringComparison stringComparison = StringComparison.CurrentCulture)
|
public MessageHasEntityFilter(MessageEntityType type, string? content, StringComparison stringComparison = StringComparison.CurrentCulture)
|
||||||
{
|
{
|
||||||
EntityType = type;
|
EntityType = type;
|
||||||
Content = content;
|
Content = content;
|
||||||
@@ -230,7 +230,7 @@ namespace Telegrator.Filters
|
|||||||
/// <param name="length">The length to filter by.</param>
|
/// <param name="length">The length to filter by.</param>
|
||||||
/// <param name="content">The content to filter by.</param>
|
/// <param name="content">The content to filter by.</param>
|
||||||
/// <param name="stringComparison">The string comparison to use.</param>
|
/// <param name="stringComparison">The string comparison to use.</param>
|
||||||
public MessageHasEntityFilter(MessageEntityType type, int offset, int? length, string content, StringComparison stringComparison = StringComparison.CurrentCulture)
|
public MessageHasEntityFilter(MessageEntityType type, int? offset, int? length, string? content, StringComparison stringComparison = StringComparison.CurrentCulture)
|
||||||
{
|
{
|
||||||
EntityType = type;
|
EntityType = type;
|
||||||
Offset = offset;
|
Offset = offset;
|
||||||
|
|||||||
@@ -88,6 +88,15 @@ namespace Telegrator.Handlers.Components
|
|||||||
if (!AllowedBranchReturnTypes.Any(branch.ReturnType.Equals))
|
if (!AllowedBranchReturnTypes.Any(branch.ReturnType.Equals))
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
handlerAttribute = HandlerInspector.GetHandlerAttribute(branch);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_ = 0xBAD + 0xC0DE;
|
||||||
|
}
|
||||||
|
|
||||||
List<IFilter<Update>> branchFiltersList = HandlerInspector.GetFilterAttributes(branch, HandlingUpdateType).ToList();
|
List<IFilter<Update>> branchFiltersList = HandlerInspector.GetFilterAttributes(branch, HandlingUpdateType).ToList();
|
||||||
branchFiltersList.AddRange(handlerFilters);
|
branchFiltersList.AddRange(handlerFilters);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user