From 253a05ae313c4b58a0e3076a088a6a9638c513ac Mon Sep 17 00:00:00 2001 From: jetsparrow Date: Wed, 25 Mar 2026 00:20:28 +0300 Subject: [PATCH] Add proxy support --- Jetsparrow.Aasb/Config.cs | 1 + Jetsparrow.Aasb/Services/Aasb.cs | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Jetsparrow.Aasb/Config.cs b/Jetsparrow.Aasb/Config.cs index b6f8f1c..daaeddd 100644 --- a/Jetsparrow.Aasb/Config.cs +++ b/Jetsparrow.Aasb/Config.cs @@ -21,6 +21,7 @@ public class SearchDictionarySettings public class TelegramSettings { public string ApiKey { get; set; } + public string Proxy { get; set; } } public class AccessSettings diff --git a/Jetsparrow.Aasb/Services/Aasb.cs b/Jetsparrow.Aasb/Services/Aasb.cs index 197d79c..b548def 100644 --- a/Jetsparrow.Aasb/Services/Aasb.cs +++ b/Jetsparrow.Aasb/Services/Aasb.cs @@ -1,10 +1,11 @@ -using System.Text.RegularExpressions; - +using Jetsparrow.Aasb.Commands; +using System.Net; +using System.Net.Http; +using System.Text.RegularExpressions; using Telegram.Bot; using Telegram.Bot.Polling; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; -using Jetsparrow.Aasb.Commands; namespace Jetsparrow.Aasb.Services; @@ -37,11 +38,20 @@ public class AntiAntiSwearingBot : IHostedService { if (string.IsNullOrWhiteSpace(TelegramSettings.ApiKey)) { - Log.LogWarning("No ApiKey found in config!"); + Log.LogCritical("No ApiKey found in config!"); throw new Exception("No ApiKey found in config!"); - return; } - TelegramBot = new TelegramBotClient(TelegramSettings.ApiKey); + + var httpClientHandler = new HttpClientHandler(); + + if (TelegramSettings.Proxy is string url) + { + httpClientHandler.Proxy = new WebProxy(url); + httpClientHandler.UseProxy = true; + } + var httpClient = new HttpClient(httpClientHandler); + + TelegramBot = new TelegramBotClient(TelegramSettings.ApiKey, httpClient); Log.LogInformation("Connecting to Telegram..."); Me = await TelegramBot.GetMeAsync();