From 5e99e802ec75fadda388d3504c4225f8b987a7fc Mon Sep 17 00:00:00 2001 From: Sergey Nazarov Date: Tue, 16 Apr 2024 13:03:31 +0000 Subject: [PATCH] nazarovsa/subscription_commands (#6) Reviewed-on: https://gitea.musk.fun/nocr/telegram-client/pulls/6 Co-authored-by: Sergey Nazarov Co-committed-by: Sergey Nazarov --- .../Bots/IBotExtensions.cs | 27 ++++ .../Bots/NocrCallbackData.cs | 30 ++++ .../Bots/NocrState.cs | 12 ++ .../ViewSubscriptionHandlerBase.cs | 132 ++++++++++++++++++ .../ActivateSubscriptionHandler.cs | 61 ++++++++ .../ActivateSubscriptionMatcher.cs | 12 ++ .../DeactivateSubscriptionHandler.cs | 62 ++++++++ .../DeactivateSubscriptionMatcher.cs | 12 ++ .../DeleteSubscriptionHandler.cs | 69 +++++++++ .../DeleteSubscriptionMatcher.cs | 12 ++ .../ViewSubscriptionHandler.cs | 49 +++++++ .../ViewSubscriptionMatcher.cs | 12 ++ .../StartMessage/StartMessageHandler.cs | 2 +- .../SubscribeMessageHandler.cs | 49 ++++--- .../SubscriptionsMessageHandler.cs | 38 ++--- ...dHandler.cs => TextSubscriptionMatched.cs} | 11 +- .../Matches/TextMatchExtensions.cs | 47 ------- .../Matches/TextSubscriptionRuleExtensions.cs | 22 +++ .../Nocr.TelegramClient.AppServices.csproj | 1 - .../ServiceCollectionExtensions.cs | 2 +- .../Nocr.TelegramClient.Host.csproj | 1 + .../TextSubscriptionData.ru-ru.json | 7 - .../ErrorMessages/errorMessages.en-us.json | 4 - .../ErrorMessages/errorMessages.ru-ru.json | 4 - .../TextSubscriptionMatchedHandler.ru-ru.json | 3 + .../ViewSubscriptionHandlerBase.ru-ru.json | 8 ++ .../ActivateSubscriptionHandler.ru-ru.json | 3 + .../DeactivateSubscriptionHandler.ru-ru.json | 3 + .../DeleteSubscriptionHandler.ru-ru.json | 4 + .../StartMessageHandler.ru-ru.json | 3 + .../SubscribeMessageHandler.ru-ru.json | 6 + .../Resources/Messages/messages.en-us.json | 2 - .../Resources/Messages/messages.ru-ru.json | 4 - 33 files changed, 592 insertions(+), 122 deletions(-) create mode 100644 src/Nocr.TelegramClient.AppServices/Bots/IBotExtensions.cs create mode 100644 src/Nocr.TelegramClient.AppServices/Bots/NocrCallbackData.cs create mode 100644 src/Nocr.TelegramClient.AppServices/Bots/NocrState.cs create mode 100644 src/Nocr.TelegramClient.AppServices/Handlers/BaseHandlers/ViewSubscriptionHandlerBase.cs create mode 100644 src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ActivateSubscription/ActivateSubscriptionHandler.cs create mode 100644 src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ActivateSubscription/ActivateSubscriptionMatcher.cs create mode 100644 src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeactivateSubscription/DeactivateSubscriptionHandler.cs create mode 100644 src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeactivateSubscription/DeactivateSubscriptionMatcher.cs create mode 100644 src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeleteSubscription/DeleteSubscriptionHandler.cs create mode 100644 src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeleteSubscription/DeleteSubscriptionMatcher.cs create mode 100644 src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ViewSubscription/ViewSubscriptionHandler.cs create mode 100644 src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ViewSubscription/ViewSubscriptionMatcher.cs rename src/Nocr.TelegramClient.AppServices/Matches/Handlers/{TextMatchMatchedHandler.cs => TextSubscriptionMatched.cs} (85%) delete mode 100644 src/Nocr.TelegramClient.AppServices/Matches/TextMatchExtensions.cs create mode 100644 src/Nocr.TelegramClient.AppServices/Matches/TextSubscriptionRuleExtensions.cs delete mode 100644 src/Nocr.TelegramClient.Host/Resources/Elements/TextSubscriptionData/TextSubscriptionData.ru-ru.json delete mode 100644 src/Nocr.TelegramClient.Host/Resources/ErrorMessages/errorMessages.en-us.json delete mode 100644 src/Nocr.TelegramClient.Host/Resources/ErrorMessages/errorMessages.ru-ru.json create mode 100644 src/Nocr.TelegramClient.Host/Resources/Handlers/EventHandlers/TextSubscriptionMatched/TextSubscriptionMatchedHandler.ru-ru.json create mode 100644 src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/Base/SubscriptionHandlerBase/ViewSubscriptionHandlerBase.ru-ru.json create mode 100644 src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/CallbackQueries/ActivateSubscription/ActivateSubscriptionHandler.ru-ru.json create mode 100644 src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/CallbackQueries/DeactivateSubscriptions/DeactivateSubscriptionHandler.ru-ru.json create mode 100644 src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/CallbackQueries/DeleteSubscription/DeleteSubscriptionHandler.ru-ru.json create mode 100644 src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/Messages/StartMessage/StartMessageHandler.ru-ru.json create mode 100644 src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/Messages/SubscribeMessage/SubscribeMessageHandler.ru-ru.json delete mode 100644 src/Nocr.TelegramClient.Host/Resources/Messages/messages.en-us.json delete mode 100644 src/Nocr.TelegramClient.Host/Resources/Messages/messages.ru-ru.json diff --git a/src/Nocr.TelegramClient.AppServices/Bots/IBotExtensions.cs b/src/Nocr.TelegramClient.AppServices/Bots/IBotExtensions.cs new file mode 100644 index 0000000..dd5b24e --- /dev/null +++ b/src/Nocr.TelegramClient.AppServices/Bots/IBotExtensions.cs @@ -0,0 +1,27 @@ +using Insight.TelegramBot; +using Insight.TelegramBot.Models; +using Microsoft.Extensions.Logging; + +namespace Nocr.TelegramClient.AppServices.Bots; + +public static class BotExtensions +{ + public static async Task EditOrSendTextMessage(this IBot bot, + int messageId, + TextMessage message, + ILogger? logger = null, + CancellationToken cancellationToken = default) + { + try + { + await bot.EditMessageTextAsync(messageId, message, cancellationToken); + return; + } + catch (Exception ex) + { + logger?.LogWarning(ex, "Не удалось отредактировать текстовое сообщение"); + } + + await bot.SendMessageAsync(message, CancellationToken.None); + } +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.AppServices/Bots/NocrCallbackData.cs b/src/Nocr.TelegramClient.AppServices/Bots/NocrCallbackData.cs new file mode 100644 index 0000000..d7bccad --- /dev/null +++ b/src/Nocr.TelegramClient.AppServices/Bots/NocrCallbackData.cs @@ -0,0 +1,30 @@ +using Insight.TelegramBot; + +namespace Nocr.TelegramClient.AppServices.Bots; + +public class NocrCallbackData : CallbackData +{ + public NocrCallbackData(NocrState nextState, params string[] args) : base(nextState, args) + { + } + + public static NocrCallbackData ActivateSubscription(long subscriptionId) + { + return new NocrCallbackData(NocrState.ActivateSubscription, subscriptionId.ToString()); + } + + public static NocrCallbackData DeactivateSubscription(long subscriptionId) + { + return new NocrCallbackData(NocrState.DeactivateSubscription, subscriptionId.ToString()); + } + + public static NocrCallbackData DeleteSubscription(long subscriptionId) + { + return new NocrCallbackData(NocrState.DeleteSubscription, subscriptionId.ToString()); + } + + public static NocrCallbackData ViewSubscription(long subscriptionId) + { + return new NocrCallbackData(NocrState.ViewSubscription, subscriptionId.ToString()); + } +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.AppServices/Bots/NocrState.cs b/src/Nocr.TelegramClient.AppServices/Bots/NocrState.cs new file mode 100644 index 0000000..01c1d8e --- /dev/null +++ b/src/Nocr.TelegramClient.AppServices/Bots/NocrState.cs @@ -0,0 +1,12 @@ +namespace Nocr.TelegramClient.AppServices.Bots; + +public enum NocrState +{ + // Commands + ActivateSubscription = 1, + DeactivateSubscription = 2, + DeleteSubscription = 3, + + // States + ViewSubscription = 4 +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.AppServices/Handlers/BaseHandlers/ViewSubscriptionHandlerBase.cs b/src/Nocr.TelegramClient.AppServices/Handlers/BaseHandlers/ViewSubscriptionHandlerBase.cs new file mode 100644 index 0000000..f3c8509 --- /dev/null +++ b/src/Nocr.TelegramClient.AppServices/Handlers/BaseHandlers/ViewSubscriptionHandlerBase.cs @@ -0,0 +1,132 @@ +using FormatWith; +using Insight.Localizer; +using Insight.TelegramBot; +using Insight.TelegramBot.Keyboards; +using Insight.TelegramBot.Models; +using Microsoft.Extensions.Logging; +using Nocr.TelegramClient.AppServices.Bots; +using Nocr.TelegramClient.AppServices.Bots.MessageDispatcher; +using Nocr.TelegramClient.AppServices.Matches; +using Nocr.TextMatcher.Api.Contracts.TextMatches; +using Nocr.TextMatcher.Api.Contracts.TextMatches.Dto; +using Telegram.Bot.Types.Enums; +using Telegram.Bot.Types.ReplyMarkups; + +namespace Nocr.TelegramClient.AppServices.Handlers.BaseHandlers; + +public abstract class ViewSubscriptionHandlerBase +{ + protected ILogger Logger { get; } + protected IBot Bot { get; } + protected ITextSubscriptionsController SubscriptionsController { get; } + protected ILocalizer Localizer { get; } + protected IMessageDispatcherQueue MessageQueue { get; } + + protected ViewSubscriptionHandlerBase(ILogger logger, ILocalizer localizer, IMessageDispatcherQueue messageQueue, + IBot bot, ITextSubscriptionsController subscriptionsController) + { + Logger = logger ?? throw new ArgumentNullException(nameof(logger)); + Bot = bot ?? throw new ArgumentNullException(nameof(bot)); + SubscriptionsController = + subscriptionsController ?? throw new ArgumentNullException(nameof(subscriptionsController)); + Localizer = localizer ?? throw new ArgumentNullException(nameof(localizer)); + MessageQueue = messageQueue ?? throw new ArgumentNullException(nameof(messageQueue)); + } + + public async Task SendSubscriptionMessage(long receiverId, TextSubscriptionData subscription, + CancellationToken cancellationToken = default) + { + var message = await GetMessage(receiverId, subscription, cancellationToken); + MessageQueue.Enqueue(message); + } + + public async Task EditSubscriptionMessage(long receiverId, int messageId, long subscriptionId, + CancellationToken cancellationToken = default) + { + var subscription = await SubscriptionsController.GetById(subscriptionId, cancellationToken); + var message = await GetMessage(receiverId, subscription, cancellationToken); + await Bot.EditOrSendTextMessage(messageId, message, Logger, cancellationToken); + } + + private async Task GetMessage(long receiverId, TextSubscriptionData subscription, + CancellationToken cancellationToken = default) + { + var subscriptions = await SubscriptionsController.GetByUserId(subscription.UserId, cancellationToken); + var ordered = subscriptions.OrderBy(x => x.Id).ToList(); + var indexOf = ordered.FindIndex(x => x.Id == subscription.Id); + long? prevId = indexOf > 0 ? ordered[indexOf - 1].Id : null; + long? nextId = indexOf < ordered.Count - 1 ? ordered[indexOf + 1].Id : null; + + var textMessage = new TextMessage(receiverId) + { + Text = GetText(subscription), + ParseMode = ParseMode.Html, + ReplyMarkup = BuildKeyBoard(subscription, prevId, nextId).InlineKeyboardMarkup + }; + + return textMessage; + } + + private string GetText(TextSubscriptionData subscription) + { + var activeText = subscription.Active + ? Localizer.Get(nameof(ViewSubscriptionHandlerBase), "Active") + : Localizer.Get(nameof(ViewSubscriptionHandlerBase), "Inactive"); + + var text = Localizer.Get(nameof(ViewSubscriptionHandlerBase), "Text") + .FormatWith(new + { + subscription.Id, + subscription.ChatUsername, + ActiveText = activeText, + Rule = subscription.Rule.TextView(Localizer), + subscription.Template + }); + + return text; + } + + private VerticalKeyboardMarkup BuildKeyBoard(TextSubscriptionData textSubscription, long? prevId, long? nextId) + { + var activeButtonText = textSubscription.Active + ? Localizer.Get(nameof(ViewSubscriptionHandlerBase), "DeactivateButton") + : Localizer.Get(nameof(ViewSubscriptionHandlerBase), "ActivateButton"); + + var deleteButtonText = Localizer.Get("Buttons", "Delete"); + + var markup = new VerticalKeyboardMarkup(); + + var row = new List(2); + if (prevId.HasValue) + { + row.Add(new InlineKeyboardButton(Localizer.Get("Buttons", "PreviousPage")) + { + CallbackData = NocrCallbackData.ViewSubscription(prevId.Value).ToString() + }); + } + + if (nextId.HasValue) + { + row.Add(new InlineKeyboardButton(Localizer.Get("Buttons", "NextPage")) + { + CallbackData = NocrCallbackData.ViewSubscription(nextId.Value).ToString() + }); + } + + if (row.Count != 0) + markup.AddRow(row); + + markup.Add(new InlineKeyboardButton(activeButtonText) + { + CallbackData = textSubscription.Active + ? NocrCallbackData.DeactivateSubscription(textSubscription.Id).ToString() + : NocrCallbackData.ActivateSubscription(textSubscription.Id).ToString() + }); + + markup.Add(new InlineKeyboardButton(deleteButtonText) + { CallbackData = NocrCallbackData.DeleteSubscription(textSubscription.Id).ToString() }); + + + return markup; + } +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ActivateSubscription/ActivateSubscriptionHandler.cs b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ActivateSubscription/ActivateSubscriptionHandler.cs new file mode 100644 index 0000000..610efec --- /dev/null +++ b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ActivateSubscription/ActivateSubscriptionHandler.cs @@ -0,0 +1,61 @@ +using Insight.Localizer; +using Insight.TelegramBot; +using Insight.TelegramBot.Handling.Handlers; +using Insight.TelegramBot.Models; +using Microsoft.Extensions.Logging; +using Nocr.TelegramClient.AppServices.Bots; +using Nocr.TelegramClient.AppServices.Bots.MessageDispatcher; +using Nocr.TelegramClient.AppServices.Handlers.BaseHandlers; +using Nocr.TextMatcher.Api.Contracts.TextMatches; +using Telegram.Bot.Types; + +namespace Nocr.TelegramClient.AppServices.Handlers.CallbackQueries.ActivateSubscription; + +public class ActivateSubscriptionHandler : ViewSubscriptionHandlerBase, IMatchingUpdateHandler +{ + public ActivateSubscriptionHandler(ILogger logger, + ILocalizer localizer, + IMessageDispatcherQueue messageQueue, + IBot bot, + ITextSubscriptionsController subscriptionsController) + : base(logger, localizer, messageQueue, bot, subscriptionsController) + { + } + + public async Task Handle(Update update, CancellationToken cancellationToken = default) + { + var callbackData = NocrCallbackData.Parse(update.CallbackQuery.Data); + var from = update.CallbackQuery.From.Id; + + if (callbackData.Args.Count != 1 || !long.TryParse(callbackData.Args.First(), out var subscriptionId)) + { + Logger.LogWarning( + "Не удалось извлечь идентификатор подписки. CallbackData: {@CallbackData}, ChatId: {ChatId}, MessageId {MessageId}", + callbackData, from, update.CallbackQuery.Message.Chat.Id); + SendErrorMessage(from); + return; + } + + try + { + await SubscriptionsController.Activate(subscriptionId, cancellationToken); + } + catch (Exception ex) + { + Logger.LogError(ex, "Не удалось деактивировать подписку"); + SendErrorMessage(from); + throw; + } + + await EditSubscriptionMessage(from, update.CallbackQuery.Message.MessageId, subscriptionId, + CancellationToken.None); + } + + private void SendErrorMessage(long from) + { + MessageQueue.Enqueue(new TextMessage(from) + { + Text = Localizer.Get(nameof(ActivateSubscriptionHandler), "FailedToActivateSubscription") + }); + } +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ActivateSubscription/ActivateSubscriptionMatcher.cs b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ActivateSubscription/ActivateSubscriptionMatcher.cs new file mode 100644 index 0000000..4490d04 --- /dev/null +++ b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ActivateSubscription/ActivateSubscriptionMatcher.cs @@ -0,0 +1,12 @@ +using Insight.TelegramBot.Handling.Matchers.CallbackQueryMatchers; +using Nocr.TelegramClient.AppServices.Bots; + +namespace Nocr.TelegramClient.AppServices.Handlers.CallbackQueries.ActivateSubscription; + +public sealed class ActivateSubscriptionMatcher : StateCallbackQueryMatcher +{ + public ActivateSubscriptionMatcher() + { + ExpectingState = NocrState.ActivateSubscription; + } +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeactivateSubscription/DeactivateSubscriptionHandler.cs b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeactivateSubscription/DeactivateSubscriptionHandler.cs new file mode 100644 index 0000000..b412cb0 --- /dev/null +++ b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeactivateSubscription/DeactivateSubscriptionHandler.cs @@ -0,0 +1,62 @@ +using Insight.Localizer; +using Insight.TelegramBot; +using Insight.TelegramBot.Handling.Handlers; +using Insight.TelegramBot.Models; +using Microsoft.Extensions.Logging; +using Nocr.TelegramClient.AppServices.Bots; +using Nocr.TelegramClient.AppServices.Bots.MessageDispatcher; +using Nocr.TelegramClient.AppServices.Handlers.BaseHandlers; +using Nocr.TextMatcher.Api.Contracts.TextMatches; +using Telegram.Bot.Types; + +namespace Nocr.TelegramClient.AppServices.Handlers.CallbackQueries.DeactivateSubscription; + +public class DeactivateSubscriptionHandler : ViewSubscriptionHandlerBase, + IMatchingUpdateHandler +{ + + public DeactivateSubscriptionHandler(ILogger logger, + ILocalizer localizer, + IMessageDispatcherQueue messageQueue, + IBot bot, + ITextSubscriptionsController subscriptionsController) + : base(logger, localizer, messageQueue, bot, subscriptionsController) + { + } + + public async Task Handle(Update update, CancellationToken cancellationToken = default) + { + var callbackData = NocrCallbackData.Parse(update.CallbackQuery.Data); + var from = update.CallbackQuery.From.Id; + + if (callbackData.Args.Count != 1 || !long.TryParse(callbackData.Args.First(), out var subscriptionId)) + { + Logger.LogWarning( + "Не удалось извлечь идентификатор подписки. CallbackData: {@CallbackData}, ChatId: {ChatId}, MessageId {MessageId}", + callbackData, from, update.CallbackQuery.Message.Chat.Id); + SendErrorMessage(from); + return; + } + + try + { + await SubscriptionsController.Disable(subscriptionId, cancellationToken); + } + catch (Exception ex) + { + Logger.LogError(ex, "Не удалось деактивировать подписку"); + SendErrorMessage(from); + throw; + } + + await EditSubscriptionMessage(from, update.CallbackQuery.Message.MessageId, subscriptionId, CancellationToken.None); + } + + private void SendErrorMessage(long from) + { + MessageQueue.Enqueue(new TextMessage(from) + { + Text = Localizer.Get(nameof(DeactivateSubscriptionHandler), "FailedToDeactivateSubscription") + }); + } +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeactivateSubscription/DeactivateSubscriptionMatcher.cs b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeactivateSubscription/DeactivateSubscriptionMatcher.cs new file mode 100644 index 0000000..80adaf0 --- /dev/null +++ b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeactivateSubscription/DeactivateSubscriptionMatcher.cs @@ -0,0 +1,12 @@ +using Insight.TelegramBot.Handling.Matchers.CallbackQueryMatchers; +using Nocr.TelegramClient.AppServices.Bots; + +namespace Nocr.TelegramClient.AppServices.Handlers.CallbackQueries.DeactivateSubscription; + +public sealed class DeactivateSubscriptionMatcher : StateCallbackQueryMatcher +{ + public DeactivateSubscriptionMatcher() + { + ExpectingState = NocrState.DeactivateSubscription; + } +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeleteSubscription/DeleteSubscriptionHandler.cs b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeleteSubscription/DeleteSubscriptionHandler.cs new file mode 100644 index 0000000..2cdf094 --- /dev/null +++ b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeleteSubscription/DeleteSubscriptionHandler.cs @@ -0,0 +1,69 @@ +using FormatWith; +using Insight.Localizer; +using Insight.TelegramBot; +using Insight.TelegramBot.Handling.Handlers; +using Insight.TelegramBot.Models; +using Microsoft.Extensions.Logging; +using Nocr.TelegramClient.AppServices.Bots; +using Nocr.TelegramClient.AppServices.Bots.MessageDispatcher; +using Nocr.TelegramClient.AppServices.Handlers.BaseHandlers; +using Nocr.TelegramClient.AppServices.Handlers.CallbackQueries.DeactivateSubscription; +using Nocr.TextMatcher.Api.Contracts.TextMatches; +using Telegram.Bot.Types; + +namespace Nocr.TelegramClient.AppServices.Handlers.CallbackQueries.DeleteSubscription; + +public class DeleteSubscriptionHandler : ViewSubscriptionHandlerBase, + IMatchingUpdateHandler +{ + public DeleteSubscriptionHandler(ILogger logger, + ILocalizer localizer, + IMessageDispatcherQueue messageQueue, + IBot bot, + ITextSubscriptionsController subscriptionsController) + : base(logger, localizer, messageQueue, bot, subscriptionsController) + { + } + + public async Task Handle(Update update, CancellationToken cancellationToken = default) + { + var callbackData = NocrCallbackData.Parse(update.CallbackQuery.Data); + var from = update.CallbackQuery.From.Id; + + if (callbackData.Args.Count != 1 || !long.TryParse(callbackData.Args.First(), out var subscriptionId)) + { + Logger.LogWarning( + "Не удалось извлечь идентификатор подписки. CallbackData: {@CallbackData}, ChatId: {ChatId}, MessageId {MessageId}", + callbackData, from, update.CallbackQuery.Message.Chat.Id); + SendErrorMessage(from); + return; + } + + try + { + await SubscriptionsController.Delete(subscriptionId, cancellationToken); + } + catch (Exception ex) + { + Logger.LogError(ex, "Не удалось удалить подписку"); + SendErrorMessage(from); + throw; + } + + var message = new TextMessage(from) + { + Text = Localizer.Get(nameof(DeleteSubscriptionHandler), "Text") + .FormatWith(new { Id = subscriptionId }) + }; + + await Bot.EditOrSendTextMessage(update.CallbackQuery.Message.MessageId, message, Logger, CancellationToken.None); + } + + private void SendErrorMessage(long from) + { + MessageQueue.Enqueue(new TextMessage(from) + { + Text = Localizer.Get(nameof(DeactivateSubscriptionHandler), "FailedToDeleteSubscription") + }); + } +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeleteSubscription/DeleteSubscriptionMatcher.cs b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeleteSubscription/DeleteSubscriptionMatcher.cs new file mode 100644 index 0000000..81ac410 --- /dev/null +++ b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/DeleteSubscription/DeleteSubscriptionMatcher.cs @@ -0,0 +1,12 @@ +using Insight.TelegramBot.Handling.Matchers.CallbackQueryMatchers; +using Nocr.TelegramClient.AppServices.Bots; + +namespace Nocr.TelegramClient.AppServices.Handlers.CallbackQueries.DeleteSubscription; + +public sealed class DeleteSubscriptionMatcher : StateCallbackQueryMatcher +{ + public DeleteSubscriptionMatcher() + { + ExpectingState = NocrState.DeleteSubscription; + } +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ViewSubscription/ViewSubscriptionHandler.cs b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ViewSubscription/ViewSubscriptionHandler.cs new file mode 100644 index 0000000..4437373 --- /dev/null +++ b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ViewSubscription/ViewSubscriptionHandler.cs @@ -0,0 +1,49 @@ +using Insight.Localizer; +using Insight.TelegramBot; +using Insight.TelegramBot.Handling.Handlers; +using Insight.TelegramBot.Models; +using Microsoft.Extensions.Logging; +using Nocr.TelegramClient.AppServices.Bots; +using Nocr.TelegramClient.AppServices.Bots.MessageDispatcher; +using Nocr.TelegramClient.AppServices.Handlers.BaseHandlers; +using Nocr.TextMatcher.Api.Contracts.TextMatches; +using Telegram.Bot.Types; + +namespace Nocr.TelegramClient.AppServices.Handlers.CallbackQueries.ViewSubscription; + +public class ViewSubscriptionHandler : ViewSubscriptionHandlerBase, IMatchingUpdateHandler +{ + public ViewSubscriptionHandler(ILogger logger, + ILocalizer localizer, + IMessageDispatcherQueue messageQueue, + IBot bot, + ITextSubscriptionsController subscriptionsController) : + base(logger, localizer, messageQueue, bot, subscriptionsController) + { + } + + public async Task Handle(Update update, CancellationToken cancellationToken = default) + { + var callbackData = NocrCallbackData.Parse(update.CallbackQuery.Data); + var from = update.CallbackQuery.From.Id; + + if (callbackData.Args.Count != 1 || !long.TryParse(callbackData.Args.First(), out var subscriptionId)) + { + Logger.LogWarning( + "Не удалось извлечь идентификатор подписки. CallbackData: {@CallbackData}, ChatId: {ChatId}, MessageId {MessageId}", + callbackData, from, update.CallbackQuery.Message.Chat.Id); + SendErrorMessage(from); + return; + } + + await EditSubscriptionMessage(from, update.CallbackQuery.Message.MessageId, subscriptionId, cancellationToken); + } + + private void SendErrorMessage(long from) + { + MessageQueue.Enqueue(new TextMessage(from) + { + Text = Localizer.Get(nameof(ViewSubscriptionHandler), "FailedToViewSubscription") + }); + } +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ViewSubscription/ViewSubscriptionMatcher.cs b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ViewSubscription/ViewSubscriptionMatcher.cs new file mode 100644 index 0000000..eaaa60c --- /dev/null +++ b/src/Nocr.TelegramClient.AppServices/Handlers/CallbackQueries/ViewSubscription/ViewSubscriptionMatcher.cs @@ -0,0 +1,12 @@ +using Insight.TelegramBot.Handling.Matchers.CallbackQueryMatchers; +using Nocr.TelegramClient.AppServices.Bots; + +namespace Nocr.TelegramClient.AppServices.Handlers.CallbackQueries.ViewSubscription; + +public sealed class ViewSubscriptionMatcher : StateCallbackQueryMatcher +{ + public ViewSubscriptionMatcher() + { + ExpectingState = NocrState.ViewSubscription; + } +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.AppServices/Handlers/Messages/StartMessage/StartMessageHandler.cs b/src/Nocr.TelegramClient.AppServices/Handlers/Messages/StartMessage/StartMessageHandler.cs index ae34807..cbc7d3a 100644 --- a/src/Nocr.TelegramClient.AppServices/Handlers/Messages/StartMessage/StartMessageHandler.cs +++ b/src/Nocr.TelegramClient.AppServices/Handlers/Messages/StartMessage/StartMessageHandler.cs @@ -23,7 +23,7 @@ public class StartMessageHandler : IMatchingUpdateHandler var telegramId = update.Message.From.Id; var message = new TextMessage(telegramId) { - Text = _localizer.Get("messages", "StartMessage"), + Text = _localizer.Get(nameof(StartMessageHandler), "Text"), ParseMode = ParseMode.Html }; diff --git a/src/Nocr.TelegramClient.AppServices/Handlers/Messages/SubscribeMessage/SubscribeMessageHandler.cs b/src/Nocr.TelegramClient.AppServices/Handlers/Messages/SubscribeMessage/SubscribeMessageHandler.cs index e2fd5c5..7f9ccff 100644 --- a/src/Nocr.TelegramClient.AppServices/Handlers/Messages/SubscribeMessage/SubscribeMessageHandler.cs +++ b/src/Nocr.TelegramClient.AppServices/Handlers/Messages/SubscribeMessage/SubscribeMessageHandler.cs @@ -1,7 +1,12 @@ using System.Text.RegularExpressions; +using FormatWith; +using Insight.Localizer; +using Insight.TelegramBot; using Insight.TelegramBot.Handling.Handlers; using Insight.TelegramBot.Models; +using Microsoft.Extensions.Logging; using Nocr.TelegramClient.AppServices.Bots.MessageDispatcher; +using Nocr.TelegramClient.AppServices.Handlers.BaseHandlers; using Nocr.TelegramClient.AppServices.Users; using Nocr.TextMatcher.Api.Contracts.TextMatches; using Nocr.TextMatcher.Api.Contracts.TextMatches.Requests; @@ -10,11 +15,9 @@ using Telegram.Bot.Types; namespace Nocr.TelegramClient.AppServices.Handlers.Messages.SubscribeMessage; -public class SubscribeMessageHandler : IMatchingUpdateHandler +public class SubscribeMessageHandler : ViewSubscriptionHandlerBase, IMatchingUpdateHandler { - private readonly IMessageDispatcherQueue _messageQueue; private readonly IUsersService _usersService; - private readonly ITextSubscriptionsController _textSubscriptionsController; /// /// Regex to match command "/subscribe @username match_type keywords".
@@ -24,26 +27,28 @@ public class SubscribeMessageHandler : IMatchingUpdateHandler logger, + ILocalizer localizer, + IMessageDispatcherQueue messageQueue, + IUsersService usersService, + IBot bot, + ITextSubscriptionsController subscriptionsController) + : base(logger, localizer, messageQueue, bot, subscriptionsController) { - _messageQueue = messageQueue ?? throw new ArgumentNullException(nameof(messageQueue)); _usersService = usersService ?? throw new ArgumentNullException(nameof(usersService)); - _textSubscriptionsController = - textSubscriptionsController ?? throw new ArgumentNullException(nameof(textSubscriptionsController)); } public async Task Handle(Update update, CancellationToken cancellationToken = default) { - var telegramId = update.Message.From.Id; + var receiverId = update.Message.From.Id; var match = _commandRegex.Match(update.Message.Text); if (!match.Success) { - _messageQueue.Enqueue(new TextMessage(telegramId) + MessageQueue.Enqueue(new TextMessage(receiverId) { - // TODO: Add localizer - Text = "Команда не удовлетворяет формату" + Text = Localizer.Get(nameof(SubscribeMessageHandler), "CommandHasWrongFormat") }); return; } @@ -51,18 +56,17 @@ public class SubscribeMessageHandler : IMatchingUpdateHandler(match.Groups[2].Value, true, out var rule)) { - _messageQueue.Enqueue(new TextMessage(telegramId) + MessageQueue.Enqueue(new TextMessage(receiverId) { - // TODO: Add localizer - Text = "Не удалось извлечь тип подписки" + Text = Localizer.Get(nameof(SubscribeMessageHandler), "WrongSubscriptionType") }); return; } - + var template = match.Groups[3].Value; - var user = await _usersService.GetOrCreate(telegramId, update.Message.From.Username, cancellationToken); - var subscriptionId = await _textSubscriptionsController.Create(new CreateTextSubscriptionRequest + var user = await _usersService.GetOrCreate(receiverId, update.Message.From.Username, cancellationToken); + var subscriptionId = await SubscriptionsController.Create(new CreateTextSubscriptionRequest { UserId = user.Id, ChatUsername = username, @@ -70,10 +74,13 @@ public class SubscribeMessageHandler : IMatchingUpdateHandler +public class SubscriptionsMessageHandler : ViewSubscriptionHandlerBase, + IMatchingUpdateHandler { - private readonly ILocalizer _localizer; - private readonly IMessageDispatcherQueue _messageQueue; private readonly IUsersService _usersService; - private readonly ITextSubscriptionsController _textSubscriptionsController; - public SubscriptionsMessageHandler(ILocalizer localizer, + public SubscriptionsMessageHandler( + ILogger logger, + ILocalizer localizer, IMessageDispatcherQueue messageQueue, IUsersService usersService, - ITextSubscriptionsController textSubscriptionsController) + IBot bot, + ITextSubscriptionsController subscriptionsController) + : base(logger, localizer, messageQueue, bot, subscriptionsController) { - _localizer = localizer ?? throw new ArgumentNullException(nameof(localizer)); - _messageQueue = messageQueue ?? throw new ArgumentNullException(nameof(messageQueue)); _usersService = usersService ?? throw new ArgumentNullException(nameof(usersService)); - _textSubscriptionsController = textSubscriptionsController ?? - throw new ArgumentNullException(nameof(textSubscriptionsController)); } public async Task Handle(Update update, CancellationToken cancellationToken = default) @@ -34,17 +32,9 @@ public class SubscriptionsMessageHandler : IMatchingUpdateHandler x.Id); - foreach (var subscription in subscriptions) - { - var textMessage = new TextMessage(telegramId) - { - Text = subscription.TextView(_localizer), - ParseMode = ParseMode.Html - }; - - _messageQueue.Enqueue(textMessage); - } + await SendSubscriptionMessage(telegramId, subscription, CancellationToken.None); } } \ No newline at end of file diff --git a/src/Nocr.TelegramClient.AppServices/Matches/Handlers/TextMatchMatchedHandler.cs b/src/Nocr.TelegramClient.AppServices/Matches/Handlers/TextSubscriptionMatched.cs similarity index 85% rename from src/Nocr.TelegramClient.AppServices/Matches/Handlers/TextMatchMatchedHandler.cs rename to src/Nocr.TelegramClient.AppServices/Matches/Handlers/TextSubscriptionMatched.cs index fa0d14a..aa77bd2 100644 --- a/src/Nocr.TelegramClient.AppServices/Matches/Handlers/TextMatchMatchedHandler.cs +++ b/src/Nocr.TelegramClient.AppServices/Matches/Handlers/TextSubscriptionMatched.cs @@ -5,21 +5,20 @@ using Microsoft.Extensions.Logging; using Nocr.TelegramClient.AppServices.Bots.MessageDispatcher; using Nocr.TelegramClient.AppServices.Links; using Nocr.TelegramClient.AppServices.Users; -using Nocr.TextMatcher.Async.Api.Contracts; using Nocr.Users.Api.Contracts.Users; using Rebus.Handlers; using Telegram.Bot.Types.Enums; namespace Nocr.TelegramClient.AppServices.Matches.Handlers; -public class TextMatchMatchedHandler : IHandleMessages +public class TextSubscriptionMatched : IHandleMessages { - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly ILocalizer _localizer; private readonly IMessageDispatcherQueue _messageDispatcherQueue; private readonly IUsersService _usersService; - public TextMatchMatchedHandler(ILogger logger, ILocalizer localizer, + public TextSubscriptionMatched(ILogger logger, ILocalizer localizer, IMessageDispatcherQueue messageDispatcherQueue, IUsersService usersService) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); @@ -29,7 +28,7 @@ public class TextMatchMatchedHandler : IHandleMessages _usersService = usersService ?? throw new ArgumentNullException(nameof(usersService)); } - public async Task Handle(TextSubscriptionMatched message) + public async Task Handle(TextMatcher.Async.Api.Contracts.TextSubscriptionMatched message) { // TODO: Set from user context Localizer.CurrentCulture = "ru-ru"; @@ -52,7 +51,7 @@ public class TextMatchMatchedHandler : IHandleMessages var link = new PublicTelegramMessageLink(false, message.ChatUsername, message.MessageId); var fromUsername = string.IsNullOrWhiteSpace(message.From) ? "anonymous" : message.From; - var text = _localizer.Get("messages", "TextSubscriptionMatched") + var text = _localizer.Get(nameof(TextSubscriptionMatched), "Text") .FormatWith(new { SubscriptionRule = message.Rule.TextView(_localizer), diff --git a/src/Nocr.TelegramClient.AppServices/Matches/TextMatchExtensions.cs b/src/Nocr.TelegramClient.AppServices/Matches/TextMatchExtensions.cs deleted file mode 100644 index 547bb5b..0000000 --- a/src/Nocr.TelegramClient.AppServices/Matches/TextMatchExtensions.cs +++ /dev/null @@ -1,47 +0,0 @@ -using FormatWith; -using Insight.Localizer; -using Nocr.TextMatcher.Api.Contracts.TextMatches.Dto; -using Nocr.TextMatcher.Contracts; - -namespace Nocr.TelegramClient.AppServices.Matches; - -public static class TextMatchExtensions -{ - public static string TextView(this TextSubscriptionData textSubscription, ILocalizer localizer) - { - var activeText = textSubscription.Active - ? localizer.Get(nameof(TextSubscriptionData), "Active") - : localizer.Get(nameof(TextSubscriptionData), "Inactive"); - var activeCommandText = textSubscription.Active - ? GetFormattedCommand("Deactivate", textSubscription.Id) - : GetFormattedCommand("Activate", textSubscription.Id); - - var deleteCommandText = GetFormattedCommand("Delete", textSubscription.Id); - return - $"[{textSubscription.Id}] (@{textSubscription.ChatUsername}) {activeText}: '{textSubscription.Rule.TextView(localizer)}' > '{textSubscription.Template}'\n{activeCommandText}\n{deleteCommandText}"; - - string GetFormattedCommand(string key, long subscriptionId) - { - return localizer.Get(nameof(TextSubscriptionData), key) - .FormatWith(new - { - SubscriptionId = subscriptionId - }); - } - } - - public static string TextView(this TextSubscriptionRule rule, ILocalizer localizer) - { - switch (rule) - { - case TextSubscriptionRule.Full: - return localizer.Get(nameof(TextSubscriptionRule), nameof(TextSubscriptionRule.Full)); - case TextSubscriptionRule.AllWords: - return localizer.Get(nameof(TextSubscriptionRule), nameof(TextSubscriptionRule.AllWords)); - case TextSubscriptionRule.AnyWord: - return localizer.Get(nameof(TextSubscriptionRule), nameof(TextSubscriptionRule.AnyWord)); - default: - throw new IndexOutOfRangeException(nameof(rule)); - } - } -} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.AppServices/Matches/TextSubscriptionRuleExtensions.cs b/src/Nocr.TelegramClient.AppServices/Matches/TextSubscriptionRuleExtensions.cs new file mode 100644 index 0000000..e00d2b2 --- /dev/null +++ b/src/Nocr.TelegramClient.AppServices/Matches/TextSubscriptionRuleExtensions.cs @@ -0,0 +1,22 @@ +using Insight.Localizer; +using Nocr.TextMatcher.Contracts; + +namespace Nocr.TelegramClient.AppServices.Matches; + +public static class TextSubscriptionRuleExtensions +{ + public static string TextView(this TextSubscriptionRule rule, ILocalizer localizer) + { + switch (rule) + { + case TextSubscriptionRule.Full: + return localizer.Get(nameof(TextSubscriptionRule), nameof(TextSubscriptionRule.Full)); + case TextSubscriptionRule.AllWords: + return localizer.Get(nameof(TextSubscriptionRule), nameof(TextSubscriptionRule.AllWords)); + case TextSubscriptionRule.AnyWord: + return localizer.Get(nameof(TextSubscriptionRule), nameof(TextSubscriptionRule.AnyWord)); + default: + throw new IndexOutOfRangeException(nameof(rule)); + } + } +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.AppServices/Nocr.TelegramClient.AppServices.csproj b/src/Nocr.TelegramClient.AppServices/Nocr.TelegramClient.AppServices.csproj index 4829a34..7ab8657 100644 --- a/src/Nocr.TelegramClient.AppServices/Nocr.TelegramClient.AppServices.csproj +++ b/src/Nocr.TelegramClient.AppServices/Nocr.TelegramClient.AppServices.csproj @@ -19,5 +19,4 @@ - diff --git a/src/Nocr.TelegramClient.AppServices/ServiceCollectionExtensions.cs b/src/Nocr.TelegramClient.AppServices/ServiceCollectionExtensions.cs index 39b6c4d..96d41fe 100644 --- a/src/Nocr.TelegramClient.AppServices/ServiceCollectionExtensions.cs +++ b/src/Nocr.TelegramClient.AppServices/ServiceCollectionExtensions.cs @@ -20,7 +20,7 @@ public static class ServiceCollectionExtensions throw new ArgumentNullException(nameof(services)); // Add registrations here - services.AddRebusHandler(); + services.AddRebusHandler(); services.AddHttpClient(); services.Configure(configuration.GetSection(nameof(UsersRestEaseOptions))); diff --git a/src/Nocr.TelegramClient.Host/Nocr.TelegramClient.Host.csproj b/src/Nocr.TelegramClient.Host/Nocr.TelegramClient.Host.csproj index 6ac1caf..4cf8745 100644 --- a/src/Nocr.TelegramClient.Host/Nocr.TelegramClient.Host.csproj +++ b/src/Nocr.TelegramClient.Host/Nocr.TelegramClient.Host.csproj @@ -25,4 +25,5 @@ + diff --git a/src/Nocr.TelegramClient.Host/Resources/Elements/TextSubscriptionData/TextSubscriptionData.ru-ru.json b/src/Nocr.TelegramClient.Host/Resources/Elements/TextSubscriptionData/TextSubscriptionData.ru-ru.json deleted file mode 100644 index a488555..0000000 --- a/src/Nocr.TelegramClient.Host/Resources/Elements/TextSubscriptionData/TextSubscriptionData.ru-ru.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "Active": "Активна", - "Inactive": "Не активна", - "Activate": "Активировать: /activate_subscription_{SubscriptionId}", - "Deactivate": "Деактивировать: /deactivate_subscription_{SubscriptionId}", - "Delete": "Удалить: /delete_subscription_{SubscriptionId}" -} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.Host/Resources/ErrorMessages/errorMessages.en-us.json b/src/Nocr.TelegramClient.Host/Resources/ErrorMessages/errorMessages.en-us.json deleted file mode 100644 index b98d6f3..0000000 --- a/src/Nocr.TelegramClient.Host/Resources/ErrorMessages/errorMessages.en-us.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "InvalidTimeFormat": "Time {ReceivedTime} does not correspond to the acceptable formats!", - "InvalidDateFormat": "Date {ReceivedDate} does not correspond to the acceptable formats!" -} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.Host/Resources/ErrorMessages/errorMessages.ru-ru.json b/src/Nocr.TelegramClient.Host/Resources/ErrorMessages/errorMessages.ru-ru.json deleted file mode 100644 index 49c7074..0000000 --- a/src/Nocr.TelegramClient.Host/Resources/ErrorMessages/errorMessages.ru-ru.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "InvalidTimeFormat": "Время {ReceivedTime} не соответствует допустимым форматам!", - "InvalidDateFormat": "Дата {ReceivedDate} не соответствует допустимым форматам!" -} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.Host/Resources/Handlers/EventHandlers/TextSubscriptionMatched/TextSubscriptionMatchedHandler.ru-ru.json b/src/Nocr.TelegramClient.Host/Resources/Handlers/EventHandlers/TextSubscriptionMatched/TextSubscriptionMatchedHandler.ru-ru.json new file mode 100644 index 0000000..f344025 --- /dev/null +++ b/src/Nocr.TelegramClient.Host/Resources/Handlers/EventHandlers/TextSubscriptionMatched/TextSubscriptionMatchedHandler.ru-ru.json @@ -0,0 +1,3 @@ +{ + "Text": "Тип совпадения: {SubscriptionRule}\nШаблон: {Template}\nСообщение: {Link}\n{FromUsername} в @{ChatUsername}" +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/Base/SubscriptionHandlerBase/ViewSubscriptionHandlerBase.ru-ru.json b/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/Base/SubscriptionHandlerBase/ViewSubscriptionHandlerBase.ru-ru.json new file mode 100644 index 0000000..b06f7f5 --- /dev/null +++ b/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/Base/SubscriptionHandlerBase/ViewSubscriptionHandlerBase.ru-ru.json @@ -0,0 +1,8 @@ +{ + "Active": "Активна", + "Inactive": "Не активна", + "Text": "Подписка #{Id}\nЧат: (@{ChatUsername})\nСтатус: {ActiveText}\nПравило: {Rule}\nШаблон: {Template}", + + "ActivateButton": "Активировать", + "DeactivateButton": "Деактивировать" +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/CallbackQueries/ActivateSubscription/ActivateSubscriptionHandler.ru-ru.json b/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/CallbackQueries/ActivateSubscription/ActivateSubscriptionHandler.ru-ru.json new file mode 100644 index 0000000..ebe076b --- /dev/null +++ b/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/CallbackQueries/ActivateSubscription/ActivateSubscriptionHandler.ru-ru.json @@ -0,0 +1,3 @@ +{ + "FailedToActivateSubscription": "Не удалось активировать подписку" +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/CallbackQueries/DeactivateSubscriptions/DeactivateSubscriptionHandler.ru-ru.json b/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/CallbackQueries/DeactivateSubscriptions/DeactivateSubscriptionHandler.ru-ru.json new file mode 100644 index 0000000..6e681a7 --- /dev/null +++ b/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/CallbackQueries/DeactivateSubscriptions/DeactivateSubscriptionHandler.ru-ru.json @@ -0,0 +1,3 @@ +{ + "FailedToDeactivateSubscription": "Не удалось деактивировать подписку" +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/CallbackQueries/DeleteSubscription/DeleteSubscriptionHandler.ru-ru.json b/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/CallbackQueries/DeleteSubscription/DeleteSubscriptionHandler.ru-ru.json new file mode 100644 index 0000000..1562b2a --- /dev/null +++ b/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/CallbackQueries/DeleteSubscription/DeleteSubscriptionHandler.ru-ru.json @@ -0,0 +1,4 @@ +{ + "FailedToDeleteSubscription": "Не удалось удалить подписку", + "Text": "Подписка #{Id} удалена" +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/Messages/StartMessage/StartMessageHandler.ru-ru.json b/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/Messages/StartMessage/StartMessageHandler.ru-ru.json new file mode 100644 index 0000000..5f3dcbc --- /dev/null +++ b/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/Messages/StartMessage/StartMessageHandler.ru-ru.json @@ -0,0 +1,3 @@ +{ + "Text": "Привет! Я, Nocr 🤖!" +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/Messages/SubscribeMessage/SubscribeMessageHandler.ru-ru.json b/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/Messages/SubscribeMessage/SubscribeMessageHandler.ru-ru.json new file mode 100644 index 0000000..67fc5f4 --- /dev/null +++ b/src/Nocr.TelegramClient.Host/Resources/Handlers/TelegramHandlers/Messages/SubscribeMessage/SubscribeMessageHandler.ru-ru.json @@ -0,0 +1,6 @@ +{ + "Text": "Подписка #{Id} создана", + + "CommandHasWrongFormat": "Команда не удовлетворяет формату", + "WrongSubscriptionType": "Не удалось извлечь тип подписки" +} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.Host/Resources/Messages/messages.en-us.json b/src/Nocr.TelegramClient.Host/Resources/Messages/messages.en-us.json deleted file mode 100644 index 7a73a41..0000000 --- a/src/Nocr.TelegramClient.Host/Resources/Messages/messages.en-us.json +++ /dev/null @@ -1,2 +0,0 @@ -{ -} \ No newline at end of file diff --git a/src/Nocr.TelegramClient.Host/Resources/Messages/messages.ru-ru.json b/src/Nocr.TelegramClient.Host/Resources/Messages/messages.ru-ru.json deleted file mode 100644 index fb9d176..0000000 --- a/src/Nocr.TelegramClient.Host/Resources/Messages/messages.ru-ru.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "StartMessage": "Привет! Я, Nocr 🤖!", - "TextSubscriptionMatched": "Тип совпадения: {SubscriptionRule}\nШаблон: {Template}\n{FromUsername} в @{ChatUsername}:\n{MessageText}\n\n{Link}" -} \ No newline at end of file