mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
fix: build and lots of obsolete warnings
This commit is contained in:
@@ -3,10 +3,9 @@ using BotFramework.Config;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Controllers
|
||||
@@ -16,14 +15,12 @@ namespace Kruzya.TelegramBot.Core.Controllers
|
||||
private const string SecretTokenHeader = "X-Telegram-Bot-Api-Secret-Token";
|
||||
|
||||
private readonly ILogger<Telegram> _logger;
|
||||
private readonly ITelegramBotClient _client;
|
||||
private readonly IUpdateTarget _updateTarget;
|
||||
private readonly string _secretToken;
|
||||
|
||||
public Telegram(ILogger<Telegram> logger, ITelegramBotClient client, IUpdateTarget updateTarget, IOptions<BotConfig> config)
|
||||
public Telegram(ILogger<Telegram> logger, IUpdateTarget updateTarget, IOptions<BotConfig> config)
|
||||
{
|
||||
_logger = logger;
|
||||
_client = client;
|
||||
_updateTarget = updateTarget;
|
||||
|
||||
_secretToken = config.Value.Webhook.SecretToken;
|
||||
@@ -50,7 +47,7 @@ namespace Kruzya.TelegramBot.Core.Controllers
|
||||
}
|
||||
|
||||
var body = await (new StreamReader(Request.Body)).ReadToEndAsync();
|
||||
LaunchHandle(JsonConvert.DeserializeObject<Update>(body));
|
||||
LaunchHandle(JsonSerializer.Deserialize<Update>(body));
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -4,11 +4,11 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<AssemblyName>TelegramBot</AssemblyName>
|
||||
<RootNamespace>Kruzya.TelegramBot.Core</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(RunConfiguration)' == 'Core' " />
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AleXr64.BotFramework" Version="2.0.8-gf720999661" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.7">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
@@ -17,6 +17,9 @@
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.7" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
|
||||
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\AleXr64\Telegram-bot-framework\TGBotFramework\BotFramework\BotFramework.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Extensions;
|
||||
|
||||
public static class HttpClientExtension
|
||||
{
|
||||
public static async Task<T> GetJsonAsync<T>(this HttpClient client, Uri requestUri)
|
||||
public static async Task<T?> GetJsonAsync<T>(this HttpClient client, Uri requestUri)
|
||||
{
|
||||
var response = await client.GetStringAsync(requestUri);
|
||||
return JsonConvert.DeserializeObject<T>(response);
|
||||
return JsonSerializer.Deserialize<T>(response);
|
||||
}
|
||||
|
||||
public static async Task<T> GetJsonAsync<T>(this HttpClient client, string requestUri)
|
||||
public static async Task<T?> GetJsonAsync<T>(this HttpClient client, string requestUri)
|
||||
{
|
||||
var response = await client.GetStringAsync(requestUri);
|
||||
return JsonConvert.DeserializeObject<T>(response);
|
||||
return JsonSerializer.Deserialize<T>(response);
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,8 @@ public abstract class CommonHandler : BotEventHandler
|
||||
|
||||
protected virtual async Task<Message> Reply(string text)
|
||||
{
|
||||
return await Bot.SendTextMessageAsync(Chat.Id, text,
|
||||
replyToMessageId: Message?.MessageId, parseMode: ParseMode.Html);
|
||||
return await Bot.SendMessage(Chat.Id, text,
|
||||
replyParameters: Message?.MessageId, parseMode: ParseMode.Html);
|
||||
}
|
||||
|
||||
protected async Task<bool> CanPunish()
|
||||
@@ -38,14 +38,14 @@ public abstract class CommonHandler : BotEventHandler
|
||||
|
||||
protected async Task BanMember(long userId, DateTime banEnd)
|
||||
{
|
||||
await Bot.RestrictChatMemberAsync(
|
||||
await Bot.RestrictChatMember(
|
||||
Chat.Id,
|
||||
userId,
|
||||
new ChatPermissions
|
||||
{
|
||||
CanSendMessages = false
|
||||
},
|
||||
banEnd
|
||||
untilDate: banEnd
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user