proxy support

This commit is contained in:
jetsparrow 2026-04-05 22:53:18 +03:00
parent 2cc286ad9c
commit fa8a30463c
2 changed files with 14 additions and 12 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;
@ -32,8 +33,17 @@ 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();