From 3b7002af0482d7c8d2034ab85f895b2e32f2836b Mon Sep 17 00:00:00 2001 From: ImoutoChan Date: Sat, 7 Dec 2024 11:24:18 +0500 Subject: [PATCH] Upgrade to net 9.0 and update packages --- ...irth.Infrastructure.ImageProcessing.csproj | 8 ++-- .../WetPicsRebirth.Tests.csproj | 12 +++--- Source/WetPicsRebirth.sln | 5 +++ .../ServiceCommands/CheckPostQueryHandler.cs | 10 ++--- .../ServiceCommands/Posting/PostNext.cs | 4 +- .../ServiceCommands/Posting/PostTop.cs | 4 +- .../UserCommands/Abstract/MessageHandler.cs | 18 ++++---- .../Actresses/AddActressCommandHandler.cs | 40 +++++++++--------- .../Actresses/GetActressesCommandHandler.cs | 34 +++++++-------- .../Actresses/RemoveActressCommandHandler.cs | 22 +++++----- .../UserCommands/Help/HelpCommandHandler.cs | 12 +++--- .../UserCommands/Help/ListCommandHandler.cs | 10 ++--- .../UserCommands/LikeCallbackHandler.cs | 2 +- .../Moderation/ModerationCallbackHandler.cs | 8 ++-- .../Posting/PostManuallyCommandHandler.cs | 42 +++++++++---------- .../Posting/TurnOffPostingCommandHandler.cs | 28 ++++++------- .../Posting/TurnOnPostingCommandHandler.cs | 34 +++++++-------- .../UserAccounts/SetAccountCommandHandler.cs | 20 ++++----- Source/WetPicsRebirth/Dockerfile | 4 +- .../LikesCounterUpdater.cs | 4 +- .../Services/TelegramHostedService.cs | 8 ++-- Source/WetPicsRebirth/WetPicsRebirth.csproj | 38 ++++++++--------- Source/global.json | 4 +- 23 files changed, 188 insertions(+), 183 deletions(-) diff --git a/Source/WetPicsRebirth.Infrastructure.ImageProcessing/WetPicsRebirth.Infrastructure.ImageProcessing.csproj b/Source/WetPicsRebirth.Infrastructure.ImageProcessing/WetPicsRebirth.Infrastructure.ImageProcessing.csproj index e895c4b..839f91a 100644 --- a/Source/WetPicsRebirth.Infrastructure.ImageProcessing/WetPicsRebirth.Infrastructure.ImageProcessing.csproj +++ b/Source/WetPicsRebirth.Infrastructure.ImageProcessing/WetPicsRebirth.Infrastructure.ImageProcessing.csproj @@ -1,18 +1,18 @@  - net8.0 + net9.0 enable true true - + - - + + diff --git a/Source/WetPicsRebirth.Tests/WetPicsRebirth.Tests.csproj b/Source/WetPicsRebirth.Tests/WetPicsRebirth.Tests.csproj index abaaeb8..f0426b5 100644 --- a/Source/WetPicsRebirth.Tests/WetPicsRebirth.Tests.csproj +++ b/Source/WetPicsRebirth.Tests/WetPicsRebirth.Tests.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 enable true true @@ -10,11 +10,11 @@ - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/Source/WetPicsRebirth.sln b/Source/WetPicsRebirth.sln index e259d47..ae5d561 100644 --- a/Source/WetPicsRebirth.sln +++ b/Source/WetPicsRebirth.sln @@ -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 diff --git a/Source/WetPicsRebirth/Commands/ServiceCommands/CheckPostQueryHandler.cs b/Source/WetPicsRebirth/Commands/ServiceCommands/CheckPostQueryHandler.cs index a3eadbc..eb6840a 100644 --- a/Source/WetPicsRebirth/Commands/ServiceCommands/CheckPostQueryHandler.cs +++ b/Source/WetPicsRebirth/Commands/ServiceCommands/CheckPostQueryHandler.cs @@ -25,11 +25,11 @@ public CheckPostQueryHandler( _logger = logger; } - public async Task Handle(CheckPostQuery request, CancellationToken cancellationToken) + public async Task Handle(CheckPostQuery request, CancellationToken ct) { try { - return await HandleInternal(request, cancellationToken); + return await HandleInternal(request, ct); } catch (Exception e) { @@ -38,7 +38,7 @@ public async Task Handle(CheckPostQuery request, CancellationToken cancell } } - private async Task HandleInternal(CheckPostQuery request, CancellationToken cancellationToken) + private async Task HandleInternal(CheckPostQuery request, CancellationToken ct) { var post = request.Post; var hash = post.PostHeader.Md5Hash ?? GetHash(post.File); @@ -50,13 +50,13 @@ private async Task 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); diff --git a/Source/WetPicsRebirth/Commands/ServiceCommands/Posting/PostNext.cs b/Source/WetPicsRebirth/Commands/ServiceCommands/Posting/PostNext.cs index 2a1eb75..7d2ef4e 100644 --- a/Source/WetPicsRebirth/Commands/ServiceCommands/Posting/PostNext.cs +++ b/Source/WetPicsRebirth/Commands/ServiceCommands/Posting/PostNext.cs @@ -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, @@ -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, diff --git a/Source/WetPicsRebirth/Commands/ServiceCommands/Posting/PostTop.cs b/Source/WetPicsRebirth/Commands/ServiceCommands/Posting/PostTop.cs index 31104f9..3b2f22c 100644 --- a/Source/WetPicsRebirth/Commands/ServiceCommands/Posting/PostTop.cs +++ b/Source/WetPicsRebirth/Commands/ServiceCommands/Posting/PostTop.cs @@ -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 topMedia) diff --git a/Source/WetPicsRebirth/Commands/UserCommands/Abstract/MessageHandler.cs b/Source/WetPicsRebirth/Commands/UserCommands/Abstract/MessageHandler.cs index f28a36e..0be43b5 100644 --- a/Source/WetPicsRebirth/Commands/UserCommands/Abstract/MessageHandler.cs +++ b/Source/WetPicsRebirth/Commands/UserCommands/Abstract/MessageHandler.cs @@ -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) { @@ -50,9 +50,9 @@ public async Task Handle(MessageNotification notification, CancellationToken can } } - private async Task GetCommand(Message message, CancellationToken cancellationToken) + private async Task GetCommand(Message message, CancellationToken ct) { - var me = await GetUser(cancellationToken); + var me = await GetUser(ct); var botUsername = me.Username!; var text = message.Text; @@ -67,14 +67,14 @@ public async Task Handle(MessageNotification notification, CancellationToken can return command; } - private async Task GetUser(CancellationToken cancellationToken) + private async Task GetUser(CancellationToken ct) { return await _memoryCache.GetRequiredOrCreateAsync( MeMemoryCacheKey, entry => { entry.SetAbsoluteExpiration(TimeSpan.FromMinutes(10)); - return _telegramBotClient.GetMeAsync(cancellationToken); + return _telegramBotClient.GetMe(ct); }); } @@ -82,13 +82,13 @@ private async Task GetUser(CancellationToken cancellationToken) 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 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); diff --git a/Source/WetPicsRebirth/Commands/UserCommands/Actresses/AddActressCommandHandler.cs b/Source/WetPicsRebirth/Commands/UserCommands/Actresses/AddActressCommandHandler.cs index 659a8cd..aa3f2e0 100644 --- a/Source/WetPicsRebirth/Commands/UserCommands/Actresses/AddActressCommandHandler.cs +++ b/Source/WetPicsRebirth/Commands/UserCommands/Actresses/AddActressCommandHandler.cs @@ -37,72 +37,72 @@ public override IEnumerable 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(); 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( @@ -151,4 +151,4 @@ private static bool TryGetImageSource(string sourceString, out ImageSource sourc source = (ImageSource)result!; return true; } -} \ No newline at end of file +} diff --git a/Source/WetPicsRebirth/Commands/UserCommands/Actresses/GetActressesCommandHandler.cs b/Source/WetPicsRebirth/Commands/UserCommands/Actresses/GetActressesCommandHandler.cs index d8ce4f8..e8bb419 100644 --- a/Source/WetPicsRebirth/Commands/UserCommands/Actresses/GetActressesCommandHandler.cs +++ b/Source/WetPicsRebirth/Commands/UserCommands/Actresses/GetActressesCommandHandler.cs @@ -32,38 +32,38 @@ public override IEnumerable 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(); 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; } @@ -71,22 +71,22 @@ await _telegramBotClient.SendTextMessageAsync( 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 actresses) @@ -111,4 +111,4 @@ private static string GetActressesListMessage(IReadOnlyCollection actre return sb.ToString(); } -} \ No newline at end of file +} diff --git a/Source/WetPicsRebirth/Commands/UserCommands/Actresses/RemoveActressCommandHandler.cs b/Source/WetPicsRebirth/Commands/UserCommands/Actresses/RemoveActressCommandHandler.cs index f7b06e9..02e1e4d 100644 --- a/Source/WetPicsRebirth/Commands/UserCommands/Actresses/RemoveActressCommandHandler.cs +++ b/Source/WetPicsRebirth/Commands/UserCommands/Actresses/RemoveActressCommandHandler.cs @@ -31,37 +31,37 @@ public override IEnumerable ProvidedCommands protected override bool WantHandle(Message message, string? command) => command?.StartsWith("/removeactress") ?? false; - 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(); if (parameters.Length != 1) { - await _telegramBotClient.SendTextMessageAsync( + await _telegramBotClient.SendMessage( message.Chat.Id, "Команда должна выглядеть как /removeactress_6B29FC40CA471067B31D00DD010662DA, " + "где первый параметр это айди актрисы", - replyToMessageId: message.MessageId, - cancellationToken: cancellationToken); + replyParameters: message.MessageId, + cancellationToken: ct); return; } if (parameters[0].Length < 33 || !Guid.TryParse(parameters[0][^32..], out var actressId)) { - await _telegramBotClient.SendTextMessageAsync( + await _telegramBotClient.SendMessage( message.Chat.Id, "Неверный айди актрисы", - replyToMessageId: message.MessageId, - cancellationToken: cancellationToken); + replyParameters: message.MessageId, + cancellationToken: ct); return; } await _actressesRepository.Remove(actressId); - await _telegramBotClient.SendTextMessageAsync( + await _telegramBotClient.SendMessage( message.Chat.Id, "Вы уволили актрису, что поделать..", - replyToMessageId: message.MessageId, - cancellationToken: cancellationToken); + replyParameters: message.MessageId, + cancellationToken: ct); } -} \ No newline at end of file +} diff --git a/Source/WetPicsRebirth/Commands/UserCommands/Help/HelpCommandHandler.cs b/Source/WetPicsRebirth/Commands/UserCommands/Help/HelpCommandHandler.cs index 5a978da..74a8e17 100644 --- a/Source/WetPicsRebirth/Commands/UserCommands/Help/HelpCommandHandler.cs +++ b/Source/WetPicsRebirth/Commands/UserCommands/Help/HelpCommandHandler.cs @@ -18,17 +18,17 @@ public HelpCommandHandler( } public override IEnumerable ProvidedCommands - => new[] { "/help", "/start" }; + => ["/help", "/start"]; protected override bool WantHandle(Message message, string? command) => command is "/help" or "/start"; - protected override async Task Handle(Message message, string? command, CancellationToken cancellationToken) + protected override async Task Handle(Message message, string? command, CancellationToken ct) { - await _telegramBotClient.SendTextMessageAsync( + await _telegramBotClient.SendMessage( message.Chat.Id, "Girls are getting ready, please kindly wait", - replyToMessageId: message.MessageId, - cancellationToken: cancellationToken); + replyParameters: message.MessageId, + cancellationToken: ct); } -} \ No newline at end of file +} diff --git a/Source/WetPicsRebirth/Commands/UserCommands/Help/ListCommandHandler.cs b/Source/WetPicsRebirth/Commands/UserCommands/Help/ListCommandHandler.cs index ac71b23..c4dc021 100644 --- a/Source/WetPicsRebirth/Commands/UserCommands/Help/ListCommandHandler.cs +++ b/Source/WetPicsRebirth/Commands/UserCommands/Help/ListCommandHandler.cs @@ -26,7 +26,7 @@ public override IEnumerable ProvidedCommands protected override bool WantHandle(Message message, string? command) => command is "/list"; - protected override async Task Handle(Message message, string? command, CancellationToken cancellationToken) + protected override async Task Handle(Message message, string? command, CancellationToken ct) { var commands = GetType().Assembly .GetTypes() @@ -35,10 +35,10 @@ protected override async Task Handle(Message message, string? command, Cancellat .Select(x => (MessageHandler)_serviceProvider.GetRequiredService(x)) .SelectMany(x => x.ProvidedCommands); - await _telegramBotClient.SendTextMessageAsync( + await _telegramBotClient.SendMessage( message.Chat.Id, "Your hands today, sir: \n\n" + string.Join("\n", commands), - replyToMessageId: message.MessageId, - cancellationToken: cancellationToken); + replyParameters: message.MessageId, + cancellationToken: ct); } -} \ No newline at end of file +} diff --git a/Source/WetPicsRebirth/Commands/UserCommands/LikeCallbackHandler.cs b/Source/WetPicsRebirth/Commands/UserCommands/LikeCallbackHandler.cs index a81eb9f..fe627dd 100644 --- a/Source/WetPicsRebirth/Commands/UserCommands/LikeCallbackHandler.cs +++ b/Source/WetPicsRebirth/Commands/UserCommands/LikeCallbackHandler.cs @@ -56,7 +56,7 @@ public async Task Handle(CallbackNotification notification, CancellationToken to await _usersRepository.AddOrUpdate(user); var counts = await _votesRepository.AddOrIgnore(vote); - await _telegramBotClient.AnswerCallbackQueryAsync( + await _telegramBotClient.AnswerCallbackQuery( notification.CallbackQuery.Id, cancellationToken: token) .TryRun(_logger); diff --git a/Source/WetPicsRebirth/Commands/UserCommands/Moderation/ModerationCallbackHandler.cs b/Source/WetPicsRebirth/Commands/UserCommands/Moderation/ModerationCallbackHandler.cs index c0a5fb9..234bfbd 100644 --- a/Source/WetPicsRebirth/Commands/UserCommands/Moderation/ModerationCallbackHandler.cs +++ b/Source/WetPicsRebirth/Commands/UserCommands/Moderation/ModerationCallbackHandler.cs @@ -21,7 +21,7 @@ public ModerationCallbackHandler( _moderatedPostsRepository = moderatedPostsRepository; } - public async Task Handle(CallbackNotification notification, CancellationToken token) + public async Task Handle(CallbackNotification notification, CancellationToken ct) { if (notification.CallbackQuery.Data?.StartsWith(CallbackStartsWith) != true) return; @@ -31,15 +31,15 @@ public async Task Handle(CallbackNotification notification, CancellationToken to var isApproved = notification.CallbackQuery.Data == CallbackApproveMessage; await _moderatedPostsRepository.Set(messageId, isApproved); - await _telegramBotClient.AnswerCallbackQueryAsync(notification.CallbackQuery.Id, cancellationToken: token); + await _telegramBotClient.AnswerCallbackQuery(notification.CallbackQuery.Id, cancellationToken: ct); if (isApproved) { - await _telegramBotClient.DeleteMessageAsync(chatId, messageId, token); + await _telegramBotClient.DeleteMessage(chatId, messageId, ct); } else { - await _telegramBotClient.EditMessageReplyMarkupAsync(chatId, messageId, null, token); + await _telegramBotClient.EditMessageReplyMarkup(chatId, messageId, null, cancellationToken: ct); } } } diff --git a/Source/WetPicsRebirth/Commands/UserCommands/Posting/PostManuallyCommandHandler.cs b/Source/WetPicsRebirth/Commands/UserCommands/Posting/PostManuallyCommandHandler.cs index fed42d5..482c960 100644 --- a/Source/WetPicsRebirth/Commands/UserCommands/Posting/PostManuallyCommandHandler.cs +++ b/Source/WetPicsRebirth/Commands/UserCommands/Posting/PostManuallyCommandHandler.cs @@ -48,60 +48,60 @@ public override IEnumerable ProvidedCommands protected override bool WantHandle(Message message, string? command) => command == "/post"; - 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(); if (parameters.Length != 4) { - await _telegramBotClient.SendTextMessageAsync( + await _telegramBotClient.SendMessage( message.Chat.Id, "Команда должна выглядеть как /post -1001411191119 rule34 1234, " + "где первый параметр это айди чата или канала, " + "второй источник поста, " + "третий id поста в иточнике", - 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 (!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 (!int.TryParse(parameters[3], out var postId)) { - 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; } @@ -126,7 +126,7 @@ await _postedMediaRepository.Add( } catch (Exception e) { - await _telegramBotClient.SendTextMessageAsync( + await _telegramBotClient.SendMessage( message.Chat.Id, "Не удалось отправить пост: " + e.Message @@ -136,8 +136,8 @@ await _telegramBotClient.SendTextMessageAsync( + e.InnerException?.Message + Environment.NewLine + e.InnerException?.StackTrace, - replyToMessageId: message.MessageId, - cancellationToken: cancellationToken); + replyParameters: message.MessageId, + cancellationToken: ct); } } @@ -194,7 +194,7 @@ private string EnrichCaption(string caption) { await using var file = _telegramPreparer.Prepare(post.File, post.FileSize); - var sentPost = await _telegramBotClient.SendPhotoAsync( + var sentPost = await _telegramBotClient.SendPhoto( chatId: chatId, photo: InputFile.FromStream(file, post.FileName), caption: caption, @@ -212,7 +212,7 @@ private string EnrichCaption(string caption) private async Task<(Message sentPost, string fileId)> SendVideo(long chatId, Post post, string caption) { - var sentPost = await _telegramBotClient.SendVideoAsync( + var sentPost = await _telegramBotClient.SendVideo( chatId, InputFile.FromStream(post.File, post.FileName), caption: caption, diff --git a/Source/WetPicsRebirth/Commands/UserCommands/Posting/TurnOffPostingCommandHandler.cs b/Source/WetPicsRebirth/Commands/UserCommands/Posting/TurnOffPostingCommandHandler.cs index feb8d7b..cef8d4b 100644 --- a/Source/WetPicsRebirth/Commands/UserCommands/Posting/TurnOffPostingCommandHandler.cs +++ b/Source/WetPicsRebirth/Commands/UserCommands/Posting/TurnOffPostingCommandHandler.cs @@ -30,47 +30,47 @@ public override IEnumerable ProvidedCommands protected override bool WantHandle(Message message, string? command) => command == "/wetpicsoff"; - 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(); if (parameters.Length != 2) { - await _telegramBotClient.SendTextMessageAsync( + await _telegramBotClient.SendMessage( message.Chat.Id, "Команда должна выглядеть как /wetpicsoff -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; } await _scenesRepository.Disable(targetId); - await _telegramBotClient.SendTextMessageAsync( + await _telegramBotClient.SendMessage( message.Chat.Id, "Постинг выключен! Плак..", - replyToMessageId: message.MessageId, - cancellationToken: cancellationToken); + replyParameters: message.MessageId, + cancellationToken: ct); } -} \ No newline at end of file +} diff --git a/Source/WetPicsRebirth/Commands/UserCommands/Posting/TurnOnPostingCommandHandler.cs b/Source/WetPicsRebirth/Commands/UserCommands/Posting/TurnOnPostingCommandHandler.cs index 5c01fd8..750850a 100644 --- a/Source/WetPicsRebirth/Commands/UserCommands/Posting/TurnOnPostingCommandHandler.cs +++ b/Source/WetPicsRebirth/Commands/UserCommands/Posting/TurnOnPostingCommandHandler.cs @@ -30,58 +30,58 @@ public override IEnumerable ProvidedCommands protected override bool WantHandle(Message message, string? command) => command == "/wetpicson"; - 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(); if (parameters.Length != 3) { - await _telegramBotClient.SendTextMessageAsync( + await _telegramBotClient.SendMessage( message.Chat.Id, "Команда должна выглядеть как /wetpicson -1001411191119 15, " + "где первый параметр это айди чата или канала, " + "а второй количество минут, через которое происходит постинг файлов.", - 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 (!int.TryParse(parameters[2], out var time)) { - 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; } await _scenesRepository.CreateOrUpdate(targetId, time); - await _telegramBotClient.SendTextMessageAsync( + await _telegramBotClient.SendMessage( message.Chat.Id, "Постинг включен! Наслаждайтесь картиночками~", - replyToMessageId: message.MessageId, - cancellationToken: cancellationToken); + replyParameters: message.MessageId, + cancellationToken: ct); } -} \ No newline at end of file +} diff --git a/Source/WetPicsRebirth/Commands/UserCommands/UserAccounts/SetAccountCommandHandler.cs b/Source/WetPicsRebirth/Commands/UserCommands/UserAccounts/SetAccountCommandHandler.cs index 3f352e3..efbf5b0 100644 --- a/Source/WetPicsRebirth/Commands/UserCommands/UserAccounts/SetAccountCommandHandler.cs +++ b/Source/WetPicsRebirth/Commands/UserCommands/UserAccounts/SetAccountCommandHandler.cs @@ -33,7 +33,7 @@ public override IEnumerable ProvidedCommands protected override bool WantHandle(Message message, string? command) => command == "/setaccount"; - protected override async Task Handle(Message message, string? command, CancellationToken cancellationToken) + protected override async Task Handle(Message message, string? command, CancellationToken ct) { var userId = message.From!.Id; @@ -41,24 +41,24 @@ protected override async Task Handle(Message message, string? command, Cancellat if (parameters.Length != 4) { - await _telegramBotClient.SendTextMessageAsync( + await _telegramBotClient.SendMessage( message.Chat.Id, "Команда должна выглядеть как /setaccount danbooru username sad1234jf3kl312aj341jkl123, " + "где первый параметр это источник картинок, " + "второй — ваш логин в источнике, " + "третий — ваш ключ ApiKey (обычно можно посмотреть на сайте в профиле).", - replyToMessageId: message.MessageId, - cancellationToken: cancellationToken); + replyParameters: message.MessageId, + cancellationToken: ct); return; } if (!TryGetImageSource(parameters[1], out var source) || source == ImageSource.Pixiv) { - await _telegramBotClient.SendTextMessageAsync( + await _telegramBotClient.SendMessage( message.Chat.Id, "Неверный источник, доступны: yandere, danbooru", - replyToMessageId: message.MessageId, - cancellationToken: cancellationToken); + replyParameters: message.MessageId, + cancellationToken: ct); return; } @@ -67,11 +67,11 @@ await _telegramBotClient.SendTextMessageAsync( await _userAccountsRepository.Set(userId, source, login, apikey); - await _telegramBotClient.SendTextMessageAsync( + await _telegramBotClient.SendMessage( message.Chat.Id, "Ваш персональный пропуск к актрисам сохранен!", - replyToMessageId: message.MessageId, - cancellationToken: cancellationToken); + replyParameters: message.MessageId, + cancellationToken: ct); } private static bool TryGetImageSource(string sourceString, out ImageSource source) diff --git a/Source/WetPicsRebirth/Dockerfile b/Source/WetPicsRebirth/Dockerfile index a630c89..b45daa4 100644 --- a/Source/WetPicsRebirth/Dockerfile +++ b/Source/WetPicsRebirth/Dockerfile @@ -1,10 +1,10 @@ #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. -FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base WORKDIR /app EXPOSE 80 -FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build WORKDIR /src COPY ["WetPicsRebirth/WetPicsRebirth.csproj", "WetPicsRebirth/"] COPY ["WetPicsRebirth.Infrastructure.ImageProcessing/WetPicsRebirth.Infrastructure.ImageProcessing.csproj", "WetPicsRebirth.Infrastructure.ImageProcessing/"] diff --git a/Source/WetPicsRebirth/Services/LikesCounterUpdater/LikesCounterUpdater.cs b/Source/WetPicsRebirth/Services/LikesCounterUpdater/LikesCounterUpdater.cs index be33171..e6911b9 100644 --- a/Source/WetPicsRebirth/Services/LikesCounterUpdater/LikesCounterUpdater.cs +++ b/Source/WetPicsRebirth/Services/LikesCounterUpdater/LikesCounterUpdater.cs @@ -30,11 +30,11 @@ private async Task UpdateMessageWithRetries( try { var currentCount = await _votesRepository.GetCountForPost(chatId, messageId); - await _telegramBotClient.EditMessageReplyMarkupAsync( + await _telegramBotClient.EditMessageReplyMarkup( chatId, messageId, Keyboards.WithLikes(currentCount), - ct); + cancellationToken: ct); } catch (ApiRequestException e) when (e.Message.Contains("retry after")) { diff --git a/Source/WetPicsRebirth/Services/TelegramHostedService.cs b/Source/WetPicsRebirth/Services/TelegramHostedService.cs index b41e319..679c9de 100644 --- a/Source/WetPicsRebirth/Services/TelegramHostedService.cs +++ b/Source/WetPicsRebirth/Services/TelegramHostedService.cs @@ -24,22 +24,22 @@ public async Task StartAsync(CancellationToken cancellationToken) var address = _configuration.GetRequiredValue("WebHookAddress"); _logger.LogInformation("Removing WebHook"); - await _telegramBotClient.DeleteWebhookAsync(cancellationToken: cancellationToken); + await _telegramBotClient.DeleteWebhook(cancellationToken: cancellationToken); _logger.LogInformation("Setting WebHook to {Address}", address); - await _telegramBotClient.SetWebhookAsync( + await _telegramBotClient.SetWebhook( address, maxConnections: 5, cancellationToken: cancellationToken); _logger.LogInformation("WebHook is set to {Address}", address); - var webHookInfo = await _telegramBotClient.GetWebhookInfoAsync(cancellationToken); + var webHookInfo = await _telegramBotClient.GetWebhookInfo(cancellationToken); _logger.LogInformation("WebHook info: {Info}", JsonConvert.SerializeObject(webHookInfo)); } public async Task StopAsync(CancellationToken cancellationToken) { - await _telegramBotClient.DeleteWebhookAsync(cancellationToken: cancellationToken); + await _telegramBotClient.DeleteWebhook(cancellationToken: cancellationToken); _logger.LogInformation("WebHook removed"); } } diff --git a/Source/WetPicsRebirth/WetPicsRebirth.csproj b/Source/WetPicsRebirth/WetPicsRebirth.csproj index b6c2eda..6ffcc9a 100644 --- a/Source/WetPicsRebirth/WetPicsRebirth.csproj +++ b/Source/WetPicsRebirth/WetPicsRebirth.csproj @@ -1,36 +1,36 @@  - net8.0 + net9.0 enable true true - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - + + - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Source/global.json b/Source/global.json index c65c9ea..e533352 100644 --- a/Source/global.json +++ b/Source/global.json @@ -1,7 +1,7 @@ { "sdk": { - "version": "8.0.0", + "version": "9.0.0", "rollForward": "latestMinor", "allowPrerelease": true } -} \ No newline at end of file +}