diff --git a/Directory.Packages.props b/Directory.Packages.props index d758c13..467cb4b 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -7,9 +7,9 @@ 0.16.0 - - - + + + diff --git a/src/Nocr.TelegramClient.AppServices/Matches/TextMatchMatchedHandler.cs b/src/Nocr.TelegramClient.AppServices/Matches/TextMatchMatchedHandler.cs index fcffbe6..e13745b 100644 --- a/src/Nocr.TelegramClient.AppServices/Matches/TextMatchMatchedHandler.cs +++ b/src/Nocr.TelegramClient.AppServices/Matches/TextMatchMatchedHandler.cs @@ -4,8 +4,9 @@ using Microsoft.Extensions.Logging; using Nocr.TelegramClient.AppServices.Users; using Nocr.TextMatcher.Api.Contracts.TextMatches; using Nocr.TextMatcher.Async.Api.Contracts; -using Nocr.Users.AppServices.Contracts.Users; +using Nocr.Users.Api.Contracts.Users; using Rebus.Handlers; +using Telegram.Bot.Types.Enums; namespace Nocr.TelegramClient.AppServices.Matches; @@ -13,45 +14,39 @@ public class TextMatchMatchedHandler : IHandleMessages { private readonly ILogger _logger; private readonly IBot _bot; - private readonly ITextMatchesController _textMatchesController; private readonly IUsersService _usersService; - public TextMatchMatchedHandler(ILogger logger, IBot bot, - ITextMatchesController textMatchesController, IUsersService usersService) + public TextMatchMatchedHandler(ILogger logger, IBot bot, IUsersService usersService) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _bot = bot ?? throw new ArgumentNullException(nameof(bot)); - _textMatchesController = - textMatchesController ?? throw new ArgumentNullException(nameof(textMatchesController)); _usersService = usersService ?? throw new ArgumentNullException(nameof(usersService)); } public async Task Handle(TextMatchMatched message) { - var match = await _textMatchesController.GetById(message.MatchId); - if (match == null) - { - _logger.LogWarning("Match [{MatchId}] from message {MessageId} not found", message.MatchId, message.Id); - return; - } - var user = await _usersService.GetById(message.MatchUserId); if (user == null) { - _logger.LogWarning("User [{UserId}] of [{MatchId}] from message {MessageId} not found", message.MatchUserId, message.MatchId, message.Id); + _logger.LogWarning("User [{UserId}] of [{MatchId}] from message {MessageId} not found", message.MatchUserId, + message.MatchId, message.Id); return; } var identity = user.Identities.FirstOrDefault(x => x.Type == UserIdentityType.TelegramId); if (identity == null) { - _logger.LogWarning("There is no identity with type '{IdentityType}' for user '{UserId}'", UserIdentityType.TelegramId, user.Id); + _logger.LogWarning("There is no identity with type '{IdentityType}' for user '{UserId}'", + UserIdentityType.TelegramId, user.Id); return; } - + + var fromUsername = string.IsNullOrWhiteSpace(message.FromUsername) ? "anonymous" : message.FromUsername; var textMessage = new TextMessage(long.Parse(identity.Identity)) { - Text = $"[{message.PublishedDateTime:MM.dd.yyyy HH:mm:ss}] Найдено совпадение.\n @{match.ChatUsername}. Тип совпадения: '{GetTextMatchRule(match.Rule)}', шаблон: '{match.Template}'" + Text = + $"[{message.PublishedDateTime:MM.dd.yyyy HH:mm:ss}] Найдено совпадение.
Тип совпадения: '{GetTextMatchRule((TextMatchRule)message.Rule)}'
Шаблон: '{message.Template}'
{fromUsername} в @{message.ChatUsername}: {message.Text}", + ParseMode = ParseMode.Html }; await _bot.SendMessageAsync(textMessage); diff --git a/src/Nocr.TelegramClient.AppServices/Nocr.TelegramClient.AppServices.csproj b/src/Nocr.TelegramClient.AppServices/Nocr.TelegramClient.AppServices.csproj index 784c41e..f92f7c1 100644 --- a/src/Nocr.TelegramClient.AppServices/Nocr.TelegramClient.AppServices.csproj +++ b/src/Nocr.TelegramClient.AppServices/Nocr.TelegramClient.AppServices.csproj @@ -4,18 +4,18 @@ false - - - - - - - - - + + + + + + + + + - + diff --git a/src/Nocr.TelegramClient.AppServices/ServiceCollectionExtensions.cs b/src/Nocr.TelegramClient.AppServices/ServiceCollectionExtensions.cs index ab520f3..c2c3dd7 100644 --- a/src/Nocr.TelegramClient.AppServices/ServiceCollectionExtensions.cs +++ b/src/Nocr.TelegramClient.AppServices/ServiceCollectionExtensions.cs @@ -1,11 +1,9 @@ -using System.Resources; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Nocr.TelegramClient.AppServices.Matches; using Nocr.TelegramClient.AppServices.Options; using Nocr.TelegramClient.AppServices.Users; -using Nocr.TelegramClient.Core.Options; using Nocr.TextMatcher.Api.Contracts.TextMatches; using Nocr.Users.Api.Contracts.Users; using Rebus.Config; diff --git a/src/Nocr.TelegramClient.AppServices/Users/UsersService.cs b/src/Nocr.TelegramClient.AppServices/Users/UsersService.cs index 175359b..0e4a656 100644 --- a/src/Nocr.TelegramClient.AppServices/Users/UsersService.cs +++ b/src/Nocr.TelegramClient.AppServices/Users/UsersService.cs @@ -1,7 +1,6 @@ using Nocr.Users.Api.Contracts.Users; using Nocr.Users.Api.Contracts.Users.Dto; using Nocr.Users.Api.Contracts.Users.Dto.Requests; -using Nocr.Users.AppServices.Contracts.Users; namespace Nocr.TelegramClient.AppServices.Users; diff --git a/src/Nocr.TelegramClient.Host/Infrastructure/Startup.cs b/src/Nocr.TelegramClient.Host/Infrastructure/Startup.cs index 329c1b2..bbea9c3 100644 --- a/src/Nocr.TelegramClient.Host/Infrastructure/Startup.cs +++ b/src/Nocr.TelegramClient.Host/Infrastructure/Startup.cs @@ -1,4 +1,3 @@ -using System.Data; using Insight.TelegramBot.Handling.Infrastructure; using Insight.TelegramBot.Hosting.DependencyInjection.Infrastructure; using Insight.TelegramBot.Hosting.Polling.ExceptionHandlers;