Add socks proxy support
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@ obj/
|
|||||||
.env
|
.env
|
||||||
data/
|
data/
|
||||||
Folder.DotSettings.user
|
Folder.DotSettings.user
|
||||||
|
docker-compose.yaml
|
||||||
|
@@ -19,10 +19,11 @@ public class ConfigData
|
|||||||
var adminNumId = DotNetEnv.Env.GetString("ADMIN_NUMID") ?? Environment.GetEnvironmentVariable("ADMIN_NUMID");
|
var adminNumId = DotNetEnv.Env.GetString("ADMIN_NUMID") ?? Environment.GetEnvironmentVariable("ADMIN_NUMID");
|
||||||
var instance = DotNetEnv.Env.GetString("CUSTOM_INSTANCE") ??
|
var instance = DotNetEnv.Env.GetString("CUSTOM_INSTANCE") ??
|
||||||
Environment.GetEnvironmentVariable("CUSTOM_INSTANCE") ?? "https://haminoa.net";
|
Environment.GetEnvironmentVariable("CUSTOM_INSTANCE") ?? "https://haminoa.net";
|
||||||
|
var socksProxy = DotNetEnv.Env.GetString("SOCKS_PROXY") ?? Environment.GetEnvironmentVariable("SOCKS_PROXY") ?? String.Empty;
|
||||||
|
|
||||||
// Check if any of the values are still null or empty
|
// Check if any of the values are still null or empty
|
||||||
if (string.IsNullOrEmpty(botToken) || string.IsNullOrEmpty(tag)
|
if (string.IsNullOrEmpty(botToken) || string.IsNullOrEmpty(tag)
|
||||||
|| string.IsNullOrEmpty(channelNumId) || string.IsNullOrEmpty(adminNumId))
|
|| string.IsNullOrEmpty(channelNumId) || string.IsNullOrEmpty(adminNumId) || string.IsNullOrEmpty(mongoDbConnectionString))
|
||||||
return null; // Failure if any are missing
|
return null; // Failure if any are missing
|
||||||
|
|
||||||
// If all required variables are present, assign to the config
|
// If all required variables are present, assign to the config
|
||||||
@@ -34,7 +35,8 @@ public class ConfigData
|
|||||||
TAG = tag,
|
TAG = tag,
|
||||||
CHANNEL_NUMID = channelNumId,
|
CHANNEL_NUMID = channelNumId,
|
||||||
ADMIN_NUMID = adminNumId,
|
ADMIN_NUMID = adminNumId,
|
||||||
INSTANCE = instance
|
INSTANCE = instance,
|
||||||
|
SOCKS_PROXY = socksProxy
|
||||||
};
|
};
|
||||||
|
|
||||||
return config; // Success
|
return config; // Success
|
||||||
@@ -49,5 +51,6 @@ public class ConfigData
|
|||||||
public string ADMIN_NUMID { get; set; }
|
public string ADMIN_NUMID { get; set; }
|
||||||
public string INSTANCE { get; set; }
|
public string INSTANCE { get; set; }
|
||||||
public string MONGODB_CONNECTION_STRING { get; set; }
|
public string MONGODB_CONNECTION_STRING { get; set; }
|
||||||
|
public string SOCKS_PROXY { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
19
Program.cs
19
Program.cs
@@ -1,4 +1,5 @@
|
|||||||
using CatsOfMastodonBot.Models;
|
using System.Net;
|
||||||
|
using CatsOfMastodonBot.Models;
|
||||||
using CatsOfMastodonBot.Services;
|
using CatsOfMastodonBot.Services;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
@@ -48,7 +49,21 @@ public class MastodonBot
|
|||||||
|
|
||||||
|
|
||||||
// Setup bot
|
// 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();
|
var me = await bot.GetMe();
|
||||||
await bot.DropPendingUpdates();
|
await bot.DropPendingUpdates();
|
||||||
|
Reference in New Issue
Block a user