Skip to content

Commit

Permalink
Upgrade to net 9.0 and update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ImoutoChan committed Dec 7, 2024
1 parent b88dbd8 commit 3b7002a
Show file tree
Hide file tree
Showing 23 changed files with 188 additions and 183 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageReference Include="NetVips.Native.linux-x64" Version="8.11.3.1" Condition="$([MSBuild]::IsOsPlatform('Linux'))" />
<PackageReference Include="NetVips.Native.osx-x64" Version="8.11.3.1" Condition="$([MSBuild]::IsOsPlatform('OSX'))" />
<PackageReference Include="NetVips" Version="2.4.1" />
<PackageReference Include="NetVips.Native.win-x64" Version="8.15.2" />
<PackageReference Include="NetVips" Version="3.0.0" />
<PackageReference Include="NetVips.Native.win-x64" Version="8.16.0" />
</ItemGroup>

</Project>
12 changes: 6 additions & 6 deletions Source/WetPicsRebirth.Tests/WetPicsRebirth.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<ImplicitUsings>true</ImplicitUsings>
Expand All @@ -10,11 +10,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bogus" Version="35.5.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.8">
<PackageReference Include="Bogus" Version="35.6.1" />
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
5 changes: 5 additions & 0 deletions Source/WetPicsRebirth.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
..\.github\workflows\main.yml = ..\.github\workflows\main.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{216980EC-4BF9-4265-BFEC-5DA4251F0C1E}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public CheckPostQueryHandler(
_logger = logger;
}

public async Task<bool> Handle(CheckPostQuery request, CancellationToken cancellationToken)
public async Task<bool> Handle(CheckPostQuery request, CancellationToken ct)
{
try
{
return await HandleInternal(request, cancellationToken);
return await HandleInternal(request, ct);
}
catch (Exception e)
{
Expand All @@ -38,7 +38,7 @@ public async Task<bool> Handle(CheckPostQuery request, CancellationToken cancell
}
}

private async Task<bool> HandleInternal(CheckPostQuery request, CancellationToken cancellationToken)
private async Task<bool> HandleInternal(CheckPostQuery request, CancellationToken ct)
{
var post = request.Post;
var hash = post.PostHeader.Md5Hash ?? GetHash(post.File);
Expand All @@ -50,13 +50,13 @@ private async Task<bool> HandleInternal(CheckPostQuery request, CancellationToke

var file = _telegramPreparer.Prepare(post.File, post.FileSize);

var sentPost = await _telegramBotClient.SendPhotoAsync(
var sentPost = await _telegramBotClient.SendPhoto(
chatId: request.ModeratorId,
photo: InputFile.FromStream(file, post.FileName),
caption: post.PostHtmlCaption,
parseMode: ParseMode.Html,
replyMarkup: Keyboards.WithModeration,
cancellationToken: cancellationToken);
cancellationToken: ct);

await _moderatedPostsRepository.Add(post.PostHeader.Id, hash, sentPost.MessageId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private static bool ShouldSkip(LoadedPost loadedPost)
{
await using var file = _telegramPreparer.Prepare(post.File, post.FileSize);

var sentPost = await _telegramBotClient.SendPhotoAsync(
var sentPost = await _telegramBotClient.SendPhoto(
chatId: actress.ChatId,
photo: InputFile.FromStream(file, post.FileName),
caption: caption,
Expand All @@ -199,7 +199,7 @@ private static bool ShouldSkip(LoadedPost loadedPost)

private async Task<(Message sentPost, string fileId)> SendVideo(Actress actress, Post post, string caption)
{
var sentPost = await _telegramBotClient.SendVideoAsync(
var sentPost = await _telegramBotClient.SendVideo(
actress.ChatId,
InputFile.FromStream(post.File, post.FileName),
caption: caption,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ private async Task PostTopForScene(TopType topType, Scene scene, IReadOnlyCollec
if (!fileIds.Any())
return;

var topMessage = await _telegramBotClient.SendMediaGroupAsync(scene.ChatId, fileIds);
await _telegramBotClient.PinChatMessageAsync(scene.ChatId, topMessage[0].MessageId);
var topMessage = await _telegramBotClient.SendMediaGroup(scene.ChatId, fileIds);
await _telegramBotClient.PinChatMessage(scene.ChatId, topMessage[0].MessageId);
}

private static string GetCaption(TopType topType, IReadOnlyCollection<PostedMedia> topMedia)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ protected MessageHandler(
_handlerName = GetType().FullName!;
}

public async Task Handle(MessageNotification notification, CancellationToken cancellationToken)
public async Task Handle(MessageNotification notification, CancellationToken ct)
{
try
{
var command = await GetCommand(notification.Message, cancellationToken);
var command = await GetCommand(notification.Message, ct);

if (!WantHandle(notification.Message, command))
return;

_logger.LogInformation("Command received {Command} by {Handler}", command, _handlerName);
await Handle(notification.Message, command, cancellationToken);
await Handle(notification.Message, command, ct);
}
catch (Exception e)
{
Expand All @@ -50,9 +50,9 @@ public async Task Handle(MessageNotification notification, CancellationToken can
}
}

private async Task<string?> GetCommand(Message message, CancellationToken cancellationToken)
private async Task<string?> GetCommand(Message message, CancellationToken ct)
{
var me = await GetUser(cancellationToken);
var me = await GetUser(ct);
var botUsername = me.Username!;

var text = message.Text;
Expand All @@ -67,28 +67,28 @@ public async Task Handle(MessageNotification notification, CancellationToken can
return command;
}

private async Task<User> GetUser(CancellationToken cancellationToken)
private async Task<User> GetUser(CancellationToken ct)
{
return await _memoryCache.GetRequiredOrCreateAsync(
MeMemoryCacheKey,
entry =>
{
entry.SetAbsoluteExpiration(TimeSpan.FromMinutes(10));
return _telegramBotClient.GetMeAsync(cancellationToken);
return _telegramBotClient.GetMe(ct);
});
}

public virtual IEnumerable<string> ProvidedCommands => Array.Empty<string>();

protected abstract bool WantHandle(Message message, string? command);

protected abstract Task Handle(Message message, string? command, CancellationToken cancellationToken);
protected abstract Task Handle(Message message, string? command, CancellationToken ct);

protected async Task<bool> CheckOnAdmin(long targetChatId, long userId)
{
try
{
var admins = await _telegramBotClient.GetChatAdministratorsAsync(new ChatId(targetChatId));
var admins = await _telegramBotClient.GetChatAdministrators(new ChatId(targetChatId));

var isAdmin = admins.FirstOrDefault(x => x.User.Id == userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,72 +37,72 @@ public override IEnumerable<string> ProvidedCommands

protected override bool WantHandle(Message message, string? command) => command == "/addactress";

protected override async Task Handle(Message message, string? command, CancellationToken cancellationToken)
protected override async Task Handle(Message message, string? command, CancellationToken ct)
{
var parameters = message.Text?.Split(' ') ?? Array.Empty<string>();

if (parameters.Length != 4)
{
await _telegramBotClient.SendTextMessageAsync(
await _telegramBotClient.SendMessage(
message.Chat.Id,
"Команда должна выглядеть как /addactress -1001411191119 yandere month, " +
"где первый параметр это айди чата или канала, " +
"второй — источник картинок, " +
"третий — параметр источника.",
replyToMessageId: message.MessageId,
cancellationToken: cancellationToken);
replyParameters: message.MessageId,
cancellationToken: ct);
return;
}

if (!long.TryParse(parameters[1], out var targetId))
{
await _telegramBotClient.SendTextMessageAsync(
await _telegramBotClient.SendMessage(
message.Chat.Id,
"Неверный айди чата или канала",
replyToMessageId: message.MessageId,
cancellationToken: cancellationToken);
replyParameters: message.MessageId,
cancellationToken: ct);
return;
}

if (!await CheckOnAdmin(targetId, message.From!.Id))
{
await _telegramBotClient.SendTextMessageAsync(
await _telegramBotClient.SendMessage(
message.Chat.Id,
"У вас должны быть права администратора в выбранном чате или канале",
replyToMessageId: message.MessageId,
cancellationToken: cancellationToken);
replyParameters: message.MessageId,
cancellationToken: ct);
return;
}

if (!TryGetImageSource(parameters[2], out var source))
{
await _telegramBotClient.SendTextMessageAsync(
await _telegramBotClient.SendMessage(
message.Chat.Id,
"Неверный источник, доступны: pixiv, yandere, danbooru",
replyToMessageId: message.MessageId,
cancellationToken: cancellationToken);
replyParameters: message.MessageId,
cancellationToken: ct);
return;
}

if (!TryGetImageSourceOptions(parameters[3], source, out var options))
{
await _telegramBotClient.SendTextMessageAsync(
await _telegramBotClient.SendMessage(
message.Chat.Id,
"Неверная опция для источника, доступны: day|week|month " +
"или dailygeneral|dailyr18|weeklygeneral|weeklyr18|monthly|" +
"rookie|original|bymalegeneral|bymaler18|byfemalegeneral|byfemaler18|r18g",
replyToMessageId: message.MessageId,
cancellationToken: cancellationToken);
replyParameters: message.MessageId,
cancellationToken: ct);
return;
}

await _actressesRepository.Add(targetId, source, options);

await _telegramBotClient.SendTextMessageAsync(
await _telegramBotClient.SendMessage(
message.Chat.Id,
"Актрисы прихорошились и готовы к выступлению!",
replyToMessageId: message.MessageId,
cancellationToken: cancellationToken);
replyParameters: message.MessageId,
cancellationToken: ct);
}

private static bool TryGetImageSourceOptions(
Expand Down Expand Up @@ -151,4 +151,4 @@ private static bool TryGetImageSource(string sourceString, out ImageSource sourc
source = (ImageSource)result!;
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,61 +32,61 @@ public override IEnumerable<string> ProvidedCommands

protected override bool WantHandle(Message message, string? command) => command == "/getactresses";

protected override async Task Handle(Message message, string? command, CancellationToken cancellationToken)
protected override async Task Handle(Message message, string? command, CancellationToken ct)
{
var parameters = message.Text?.Split(' ') ?? Array.Empty<string>();

if (parameters.Length != 2)
{
await _telegramBotClient.SendTextMessageAsync(
await _telegramBotClient.SendMessage(
message.Chat.Id,
"Команда должна выглядеть как /getactress -1001411191119, " +
"где параметр это айди чата или канала",
replyToMessageId: message.MessageId,
cancellationToken: cancellationToken);
replyParameters: message.MessageId,
cancellationToken: ct);
return;
}

if (!long.TryParse(parameters[1], out var targetId))
{
await _telegramBotClient.SendTextMessageAsync(
await _telegramBotClient.SendMessage(
message.Chat.Id,
"Неверный айди чата или канала",
replyToMessageId: message.MessageId,
cancellationToken: cancellationToken);
replyParameters: message.MessageId,
cancellationToken: ct);
return;
}

if (!await CheckOnAdmin(targetId, message.From!.Id))
{
await _telegramBotClient.SendTextMessageAsync(
await _telegramBotClient.SendMessage(
message.Chat.Id,
"У вас должны быть права администратора в выбранном чате или канале",
replyToMessageId: message.MessageId,
cancellationToken: cancellationToken);
replyParameters: message.MessageId,
cancellationToken: ct);
return;
}

var actresses = await _actressesRepository.GetForChat(targetId);

if (!actresses.Any())
{
await _telegramBotClient.SendTextMessageAsync(
await _telegramBotClient.SendMessage(
message.Chat.Id,
"Актрисы не готовы!",
replyToMessageId: message.MessageId,
cancellationToken: cancellationToken);
replyParameters: message.MessageId,
cancellationToken: ct);
return;
}

var actressesListMessage = GetActressesListMessage(actresses);

await _telegramBotClient.SendTextMessageAsync(
await _telegramBotClient.SendMessage(
message.Chat.Id,
actressesListMessage,
replyToMessageId: message.MessageId,
replyParameters: message.MessageId,
parseMode: ParseMode.Html,
cancellationToken: cancellationToken);
cancellationToken: ct);
}

private static string GetActressesListMessage(IReadOnlyCollection<Actress> actresses)
Expand All @@ -111,4 +111,4 @@ private static string GetActressesListMessage(IReadOnlyCollection<Actress> actre

return sb.ToString();
}
}
}
Loading

0 comments on commit 3b7002a

Please sign in to comment.