Reviewed-on: #12 Co-authored-by: Sergey Nazarov <insight.appdev@gmail.com> Co-committed-by: Sergey Nazarov <insight.appdev@gmail.com>
42 lines
1.8 KiB
C#
42 lines
1.8 KiB
C#
using System.Text.RegularExpressions;
|
||
using Insight.Localizer;
|
||
using Insight.TelegramBot;
|
||
using Insight.TelegramBot.Handling.Handlers;
|
||
using Microsoft.Extensions.Logging;
|
||
using Nocr.TelegramClient.AppServices.Bots.MessageDispatcher;
|
||
using Nocr.TelegramClient.AppServices.Handlers.Messages.SubscribeExactMessage;
|
||
using Nocr.TelegramClient.AppServices.Users;
|
||
using Nocr.TextMatcher.Api.Contracts.TextMatches;
|
||
using Nocr.TextMatcher.Contracts;
|
||
using Telegram.Bot.Types;
|
||
|
||
namespace Nocr.TelegramClient.AppServices.Handlers.Messages.SubscribeAnyMessage;
|
||
|
||
public sealed class SubscribeAnyMessageHandler : SubscribeHandlerBase,
|
||
IMatchingUpdateHandler<SubscribeAnyMessageMatcher>
|
||
{
|
||
/// <summary>
|
||
/// Regex to match command "/subscribe_any @username keywords". <br/>
|
||
/// For instance, "/subscribe_any @baraholka обувь ботинки сапоги" will create match for a current user with type "Any" and pattern "обувь ботинки сапоги".
|
||
/// </summary>
|
||
private static Regex _commandRegex =
|
||
new Regex(
|
||
@"^/subscribe_any (.*\B@(?=\w{5,32}\b)[a-zA-Z0-9]+(?:_[а-яА-Яa-zA-Z0-9]+)*) (\s*[а-яА-ЯA-Za-z0-9]+(?:\s+[а-яА-ЯA-Za-z0-9]+)*\s*)$",
|
||
RegexOptions.Compiled);
|
||
|
||
public SubscribeAnyMessageHandler(
|
||
ILogger<SubscribeAnyMessageHandler> logger,
|
||
ILocalizer localizer,
|
||
IMessageDispatcherQueue messageQueue,
|
||
IUsersService usersService,
|
||
IBot bot,
|
||
ITextSubscriptionsController subscriptionsController)
|
||
: base(logger, localizer, messageQueue, bot, usersService, subscriptionsController)
|
||
{
|
||
}
|
||
|
||
public Task Handle(Update update, CancellationToken cancellationToken = default)
|
||
{
|
||
return base.Handle(update, _commandRegex, TextSubscriptionRule.AnyWord, cancellationToken);
|
||
}
|
||
} |