Update dependencies

This commit is contained in:
Sergey Nazarov 2024-03-28 09:03:02 +03:00
parent 7cc69e36c2
commit 3bca09b3b9
6 changed files with 25 additions and 34 deletions

View File

@ -7,9 +7,9 @@
<InsightTelegramBotVersion>0.16.0</InsightTelegramBotVersion> <InsightTelegramBotVersion>0.16.0</InsightTelegramBotVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup Label="Nocr"> <ItemGroup Label="Nocr">
<PackageVersion Include="Nocr.TextMatcher.Api.Contracts" Version="0.4.13" /> <PackageVersion Include="Nocr.TextMatcher.Api.Contracts" Version="0.4.22" />
<PackageVersion Include="Nocr.TextMatcher.Async.Api.Contracts" Version="0.4.13" /> <PackageVersion Include="Nocr.TextMatcher.Async.Api.Contracts" Version="0.4.22" />
<PackageVersion Include="Nocr.Users.Api.Contracts" Version="0.4.11" /> <PackageVersion Include="Nocr.Users.Api.Contracts" Version="0.4.22" />
</ItemGroup> </ItemGroup>
<ItemGroup Label="Rebus"> <ItemGroup Label="Rebus">
<PackageVersion Include="Rebus" Version="8.2.2" /> <PackageVersion Include="Rebus" Version="8.2.2" />

View File

@ -4,8 +4,9 @@ using Microsoft.Extensions.Logging;
using Nocr.TelegramClient.AppServices.Users; using Nocr.TelegramClient.AppServices.Users;
using Nocr.TextMatcher.Api.Contracts.TextMatches; using Nocr.TextMatcher.Api.Contracts.TextMatches;
using Nocr.TextMatcher.Async.Api.Contracts; using Nocr.TextMatcher.Async.Api.Contracts;
using Nocr.Users.AppServices.Contracts.Users; using Nocr.Users.Api.Contracts.Users;
using Rebus.Handlers; using Rebus.Handlers;
using Telegram.Bot.Types.Enums;
namespace Nocr.TelegramClient.AppServices.Matches; namespace Nocr.TelegramClient.AppServices.Matches;
@ -13,45 +14,39 @@ public class TextMatchMatchedHandler : IHandleMessages<TextMatchMatched>
{ {
private readonly ILogger<TextMatchMatchedHandler> _logger; private readonly ILogger<TextMatchMatchedHandler> _logger;
private readonly IBot _bot; private readonly IBot _bot;
private readonly ITextMatchesController _textMatchesController;
private readonly IUsersService _usersService; private readonly IUsersService _usersService;
public TextMatchMatchedHandler(ILogger<TextMatchMatchedHandler> logger, IBot bot, public TextMatchMatchedHandler(ILogger<TextMatchMatchedHandler> logger, IBot bot, IUsersService usersService)
ITextMatchesController textMatchesController, IUsersService usersService)
{ {
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); _logger = logger ?? throw new ArgumentNullException(nameof(logger));
_bot = bot ?? throw new ArgumentNullException(nameof(bot)); _bot = bot ?? throw new ArgumentNullException(nameof(bot));
_textMatchesController =
textMatchesController ?? throw new ArgumentNullException(nameof(textMatchesController));
_usersService = usersService ?? throw new ArgumentNullException(nameof(usersService)); _usersService = usersService ?? throw new ArgumentNullException(nameof(usersService));
} }
public async Task Handle(TextMatchMatched message) 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); var user = await _usersService.GetById(message.MatchUserId);
if (user == null) 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; return;
} }
var identity = user.Identities.FirstOrDefault(x => x.Type == UserIdentityType.TelegramId); var identity = user.Identities.FirstOrDefault(x => x.Type == UserIdentityType.TelegramId);
if (identity == null) 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; return;
} }
var fromUsername = string.IsNullOrWhiteSpace(message.FromUsername) ? "anonymous" : message.FromUsername;
var textMessage = new TextMessage(long.Parse(identity.Identity)) 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}] Найдено совпадение.</br>Тип совпадения: <b>'{GetTextMatchRule((TextMatchRule)message.Rule)}'</b></br>Шаблон: <b>'{message.Template}'</b></br>{fromUsername} в @{message.ChatUsername}: <i>{message.Text}</i>",
ParseMode = ParseMode.Html
}; };
await _bot.SendMessageAsync(textMessage); await _bot.SendMessageAsync(textMessage);

View File

@ -4,18 +4,18 @@
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Insight.TelegramBot" /> <PackageReference Include="Insight.TelegramBot"/>
<PackageReference Include="Insight.TelegramBot.Handling" /> <PackageReference Include="Insight.TelegramBot.Handling"/>
<PackageReference Include="Microsoft.Extensions.Http" /> <PackageReference Include="Microsoft.Extensions.Http"/>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" /> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions"/>
<PackageReference Include="Nocr.Users.Api.Contracts" /> <PackageReference Include="Nocr.Users.Api.Contracts"/>
<PackageReference Include="Rebus" /> <PackageReference Include="Rebus"/>
<PackageReference Include="Rebus.ServiceProvider" /> <PackageReference Include="Rebus.ServiceProvider"/>
<PackageReference Include="Nocr.TextMatcher.Async.Api.Contracts" /> <PackageReference Include="Nocr.TextMatcher.Api.Contracts"/>
<PackageReference Include="Nocr.TextMatcher.Api.Contracts" /> <PackageReference Include="Nocr.TextMatcher.Async.Api.Contracts"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Nocr.TelegramClient.Core\Nocr.TelegramClient.Core.csproj" /> <ProjectReference Include="..\Nocr.TelegramClient.Core\Nocr.TelegramClient.Core.csproj"/>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,11 +1,9 @@
using System.Resources;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Nocr.TelegramClient.AppServices.Matches; using Nocr.TelegramClient.AppServices.Matches;
using Nocr.TelegramClient.AppServices.Options; using Nocr.TelegramClient.AppServices.Options;
using Nocr.TelegramClient.AppServices.Users; using Nocr.TelegramClient.AppServices.Users;
using Nocr.TelegramClient.Core.Options;
using Nocr.TextMatcher.Api.Contracts.TextMatches; using Nocr.TextMatcher.Api.Contracts.TextMatches;
using Nocr.Users.Api.Contracts.Users; using Nocr.Users.Api.Contracts.Users;
using Rebus.Config; using Rebus.Config;

View File

@ -1,7 +1,6 @@
using Nocr.Users.Api.Contracts.Users; using Nocr.Users.Api.Contracts.Users;
using Nocr.Users.Api.Contracts.Users.Dto; using Nocr.Users.Api.Contracts.Users.Dto;
using Nocr.Users.Api.Contracts.Users.Dto.Requests; using Nocr.Users.Api.Contracts.Users.Dto.Requests;
using Nocr.Users.AppServices.Contracts.Users;
namespace Nocr.TelegramClient.AppServices.Users; namespace Nocr.TelegramClient.AppServices.Users;

View File

@ -1,4 +1,3 @@
using System.Data;
using Insight.TelegramBot.Handling.Infrastructure; using Insight.TelegramBot.Handling.Infrastructure;
using Insight.TelegramBot.Hosting.DependencyInjection.Infrastructure; using Insight.TelegramBot.Hosting.DependencyInjection.Infrastructure;
using Insight.TelegramBot.Hosting.Polling.ExceptionHandlers; using Insight.TelegramBot.Hosting.Polling.ExceptionHandlers;