telegram-client/src/Nocr.TelegramClient.AppServices/Handlers/Messages/SubscribeAnyMessage/SubscribeAnyMessageHandler.cs
Sergey Nazarov ea5cb89121 nazarovsa/subscription_type (#12)
Reviewed-on: #12
Co-authored-by: Sergey Nazarov <insight.appdev@gmail.com>
Co-committed-by: Sergey Nazarov <insight.appdev@gmail.com>
2024-05-18 12:49:00 +00:00

42 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}