Reviewed-on: #12 Co-authored-by: Sergey Nazarov <insight.appdev@gmail.com> Co-committed-by: Sergey Nazarov <insight.appdev@gmail.com>
40 lines
1.8 KiB
C#
40 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.SubscribeAllMessage;
|
||
|
||
public sealed class SubscribeAllMessageHandler : SubscribeHandlerBase, IMatchingUpdateHandler<SubscribeAllMessageMatcher>
|
||
{
|
||
/// <summary>
|
||
/// Regex to match command "/subscribe_all @username keywords". <br/>
|
||
/// For instance, "/subscribe_all @baraholka обувь ботинки сапоги" will create match for a current user with type "All" and pattern "обувь ботинки сапоги".
|
||
/// </summary>
|
||
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<SubscribeAllMessageHandler> 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);
|
||
}
|
||
} |