Compare commits

...

2 Commits

Author SHA1 Message Date
bd2859913f Bump .net version and dependencies 2026-04-05 23:02:53 +03:00
fa8a30463c proxy support 2026-04-05 22:53:18 +03:00
4 changed files with 21 additions and 19 deletions

View File

@ -12,15 +12,7 @@ public class Config : ConfigBase
public string ApiKey { get; private set; } public string ApiKey { get; private set; }
public string ConnectionString { get; private set; } public string ConnectionString { get; private set; }
public class ProxySettings public string Proxy { get; private set; }
{
public string Url { get; private set; }
public int Port { get; private set; }
public string Login { get; private set; }
public string Password { get; private set; }
}
public ProxySettings Proxy { get; private set; }
public class TimeoutConfig public class TimeoutConfig
{ {
public int DebtLimitSeconds { get; private set; } = 60 * 60 * 2; public int DebtLimitSeconds { get; private set; } = 60 * 60 * 2;

View File

@ -3,7 +3,8 @@ using JetKarmaBot.Models;
using JetKarmaBot.Services; using JetKarmaBot.Services;
using JetKarmaBot.Services.Handling; using JetKarmaBot.Services.Handling;
using NLog; using NLog;
using System.Net;
using System.Net.Http;
using Telegram.Bot; using Telegram.Bot;
using Telegram.Bot.Polling; using Telegram.Bot.Polling;
using Telegram.Bot.Types; using Telegram.Bot.Types;
@ -33,7 +34,16 @@ public class JetKarmaBot : IDisposable
using (KarmaContext db = Db.GetContext()) using (KarmaContext db = Db.GetContext())
await db.Database.EnsureCreatedAsync(); await db.Database.EnsureCreatedAsync();
Client = new TelegramBotClient(Config.ApiKey); var httpClientHandler = new HttpClientHandler();
if (Config.Proxy is string url)
{
httpClientHandler.Proxy = new WebProxy(url);
httpClientHandler.UseProxy = true;
}
var httpClient = new HttpClient(httpClientHandler);
Client = new TelegramBotClient(Config.ApiKey, httpClient);
Container.AddInstance(Client); Container.AddInstance(Client);
timeoutWaitTaskToken = new CancellationTokenSource(); timeoutWaitTaskToken = new CancellationTokenSource();
@ -52,7 +62,7 @@ public class JetKarmaBot : IDisposable
public async Task Stop() public async Task Stop()
{ {
if (stopped) return; if (stopped) return;
Client?.CloseAsync(); Client?.Close();
timeoutWaitTaskToken?.Cancel(); timeoutWaitTaskToken?.Cancel();
try try
{ {

View File

@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" /> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
<PackageReference Include="Telegram.Bot" Version="22.0.2" /> <PackageReference Include="Telegram.Bot" Version="22.9.6" />
<PackageReference Include="NLog" Version="5.3.4" /> <PackageReference Include="NLog" Version="6.1.2" />
<ProjectReference Include="..\perfusion\Perfusion\Perfusion.csproj" /> <ProjectReference Include="..\perfusion\Perfusion\Perfusion.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -18,7 +18,7 @@ public class ChatCommandRouter : IRequestHandler
public async Task Start() public async Task Start()
{ {
Me = await Client.GetMeAsync(); Me = await Client.GetMe();
} }
public Task Handle(RequestContext ctx, Func<RequestContext, Task> next) public Task Handle(RequestContext ctx, Func<RequestContext, Task> next)