Update project and dependencies to .NET8

This commit is contained in:
Jetsparrow 2024-04-27 16:23:32 +03:00
parent b938e37fdd
commit db970fe87d
3 changed files with 30 additions and 27 deletions

View File

@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<PreserveCompilationContext>false</PreserveCompilationContext>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper.Transaction" Version="2.0.35.2" />
<PackageReference Include="DSharpPlus" Version="4.2.0" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.2.0" />
<PackageReference Include="MySql.Data" Version="8.0.28" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.0.0-rc2" />
<PackageReference Include="Telegram.Bot.Extensions.Polling" Version="1.0.2" />
<PackageReference Include="Dapper.Transaction" Version="2.1.28" />
<PackageReference Include="DSharpPlus" Version="4.4.6" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.4.6" />
<PackageReference Include="MySql.Data" Version="8.3.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.8" />
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
</ItemGroup>
</Project>

View File

@ -13,13 +13,18 @@ using JetHerald.Middlewares;
using JetHerald.Utils;
using JetHerald.Authorization;
using Microsoft.Extensions.Hosting;
using NLog;
#if DEBUG
var debug = true;
var nlogConfigPath = "nlog.debug.config";
#else
var debug = false;
var nlogConfigPath = "nlog.config";
#endif
var log = NLogBuilder.ConfigureNLog(debug ? "nlog.debug.config" : "nlog.config").GetCurrentClassLogger();
LogManager.ThrowConfigExceptions = true;
LogManager.Setup().LoadConfigurationFromFile(nlogConfigPath);
var log = LogManager.GetCurrentClassLogger();
try
{
@ -127,10 +132,7 @@ try
app.UseStatusCodePagesWithReExecute("/ui/{0}");
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.MapControllers();
app.Run();
}
catch (Exception exception)

View File

@ -1,16 +1,17 @@
using System.Threading;
using Telegram.Bot;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Extensions.Polling;
using Telegram.Bot.Exceptions;
using Telegram.Bot.Polling;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Exceptions;
using JetHerald.Commands;
using Telegram.Bot.Types.ReplyMarkups;
namespace JetHerald.Services;
public partial class JetHeraldBot
{
TelegramBotClient TelegramBot { get; set; }
TelegramBotClient Client { get; set; }
Telegram.Bot.Types.User Me { get; set; }
ChatCommandRouter Commands;
CancellationTokenSource TelegramBotShutdownToken { get; } = new();
@ -19,16 +20,16 @@ public partial class JetHeraldBot
if (string.IsNullOrWhiteSpace(TelegramConfig.ApiKey))
return;
TelegramBot = new TelegramBotClient(TelegramConfig.ApiKey);
Me = await TelegramBot.GetMeAsync();
Client = new TelegramBotClient(TelegramConfig.ApiKey);
Me = await Client.GetMeAsync();
Commands = new ChatCommandRouter(Me.Username, Log);
Commands.Add(new SubscribeCommand(Db, TelegramBot), "subscribe", "sub");
Commands.Add(new UnsubscribeCommand(Db, TelegramBot), "unsubscribe", "unsub");
Commands.Add(new ListCommand(Db, TelegramBot), "list");
Commands.Add(new SubscribeCommand(Db, Client), "subscribe", "sub");
Commands.Add(new UnsubscribeCommand(Db, Client), "unsubscribe", "unsub");
Commands.Add(new ListCommand(Db, Client), "list");
var receiverOptions = new ReceiverOptions { AllowedUpdates = new[] { UpdateType.Message } };
TelegramBot.StartReceiving(
Client.StartReceiving(
HandleUpdateAsync,
HandleErrorAsync,
receiverOptions,
@ -44,7 +45,7 @@ public partial class JetHeraldBot
Task SendMessageToTelegramChannel(NamespacedId chat, string formatted)
{
var id = long.Parse(chat.Id);
return TelegramBot.SendTextMessageAsync(id, formatted);
return Client.SendTextMessageAsync(id, formatted);
}
Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken)
@ -67,7 +68,7 @@ public partial class JetHeraldBot
{
var reply = await Commands.Execute(sender, update);
if (reply != null)
await TelegramBot.SendTextMessageAsync(
await Client.SendTextMessageAsync(
chatId: msg.Chat.Id,
text: reply,
replyToMessageId: msg.MessageId);