Add socks proxy support

This commit is contained in:
2025-01-02 16:01:42 +03:30
parent 798a80e820
commit 153d9c577b
3 changed files with 23 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
using CatsOfMastodonBot.Models;
using System.Net;
using CatsOfMastodonBot.Models;
using CatsOfMastodonBot.Services;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
@@ -48,7 +49,21 @@ public class MastodonBot
// Setup bot
var bot = new TelegramBotClient(config.BOT_TOKEN);
TelegramBotClient bot;
if (!String.IsNullOrEmpty(config.SOCKS_PROXY))
{
WebProxy proxy = new (config.SOCKS_PROXY);
HttpClient httpClient = new (
new SocketsHttpHandler { Proxy = proxy, UseProxy = true }
);
bot = new TelegramBotClient(config.BOT_TOKEN, httpClient);
}
else
{
bot = new TelegramBotClient(config.BOT_TOKEN);
}
var me = await bot.GetMe();
await bot.DropPendingUpdates();