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 { /// /// Regex to match command "/subscribe_any @username keywords".
/// For instance, "/subscribe_any @baraholka обувь ботинки сапоги" will create match for a current user with type "Any" and pattern "обувь ботинки сапоги". ///
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 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); } }