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.SubscribeAllMessage; public sealed class SubscribeAllMessageHandler : SubscribeHandlerBase, IMatchingUpdateHandler { /// /// Regex to match command "/subscribe_all @username keywords".
/// For instance, "/subscribe_all @baraholka обувь ботинки сапоги" will create match for a current user with type "All" and pattern "обувь ботинки сапоги". ///
private static Regex _commandRegex = new Regex(@"^/subscribe_all (.*\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 SubscribeAllMessageHandler( 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.AllWords, cancellationToken); } }