mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-04-26 06:05:05 +03:00
proxy support
This commit is contained in:
parent
2cc286ad9c
commit
fa8a30463c
@ -12,15 +12,7 @@ public class Config : ConfigBase
|
||||
public string ApiKey { get; private set; }
|
||||
public string ConnectionString { get; private set; }
|
||||
|
||||
public class ProxySettings
|
||||
{
|
||||
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 string Proxy { get; private set; }
|
||||
public class TimeoutConfig
|
||||
{
|
||||
public int DebtLimitSeconds { get; private set; } = 60 * 60 * 2;
|
||||
|
||||
@ -3,7 +3,8 @@ using JetKarmaBot.Models;
|
||||
using JetKarmaBot.Services;
|
||||
using JetKarmaBot.Services.Handling;
|
||||
using NLog;
|
||||
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Polling;
|
||||
using Telegram.Bot.Types;
|
||||
@ -33,7 +34,16 @@ public class JetKarmaBot : IDisposable
|
||||
using (KarmaContext db = Db.GetContext())
|
||||
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);
|
||||
|
||||
timeoutWaitTaskToken = new CancellationTokenSource();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user