diff --git a/JetHerald/Options.cs b/JetHerald/Options.cs index 7c1832f..0e79af4 100644 --- a/JetHerald/Options.cs +++ b/JetHerald/Options.cs @@ -8,11 +8,13 @@ public class ConnectionStrings public class TelegramConfig { public string ApiKey { get; set; } + public string? ProxyUrl { get; set; } } public class DiscordConfig { public string Token { get; set; } + public string? ProxyUrl { get; set; } } public class TimeoutConfig diff --git a/JetHerald/Services/JetHeraldBot.Discord.cs b/JetHerald/Services/JetHeraldBot.Discord.cs index 06c2eca..5a884bd 100644 --- a/JetHerald/Services/JetHeraldBot.Discord.cs +++ b/JetHerald/Services/JetHeraldBot.Discord.cs @@ -1,6 +1,8 @@ using DSharpPlus; using DSharpPlus.CommandsNext; using JetHerald.Commands; +using System.Net; +using System.Net.Http; namespace JetHerald.Services; public partial class JetHeraldBot { @@ -9,15 +11,27 @@ public partial class JetHeraldBot async Task StartDiscord() { if (string.IsNullOrWhiteSpace(DiscordConfig.Token)) + { + Log.LogInformation("No Discord token, ignoring."); return; + } - DiscordBot = new DiscordClient(new() + Log.LogInformation("Starting Discord client."); + + DiscordConfiguration cfg = new() { Token = DiscordConfig.Token, TokenType = TokenType.Bot, Intents = DiscordIntents.AllUnprivileged, LoggerFactory = LoggerFactory - }); + }; + + if (!string.IsNullOrWhiteSpace(DiscordConfig.ProxyUrl)) + { + cfg.Proxy = new WebProxy(DiscordConfig.ProxyUrl); + } + + DiscordBot = new DiscordClient(cfg); var commands = DiscordBot.UseCommandsNext(new CommandsNextConfiguration() { diff --git a/JetHerald/Services/JetHeraldBot.Telegram.cs b/JetHerald/Services/JetHeraldBot.Telegram.cs index 2a1f961..224dec7 100644 --- a/JetHerald/Services/JetHeraldBot.Telegram.cs +++ b/JetHerald/Services/JetHeraldBot.Telegram.cs @@ -1,12 +1,12 @@ +using JetHerald.Commands; +using System.Net; +using System.Net.Http; using System.Threading; - using Telegram.Bot; +using Telegram.Bot.Exceptions; using Telegram.Bot.Polling; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; -using Telegram.Bot.Exceptions; - -using JetHerald.Commands; namespace JetHerald.Services; public partial class JetHeraldBot @@ -18,9 +18,23 @@ public partial class JetHeraldBot async Task StartTelegram() { if (string.IsNullOrWhiteSpace(TelegramConfig.ApiKey)) + { + Log.LogInformation("No Telegram token, ignoring."); return; + } - Client = new TelegramBotClient(TelegramConfig.ApiKey); + Log.LogInformation("Starting Telegram client."); + + var httpClientHandler = new HttpClientHandler(); + + if (!string.IsNullOrWhiteSpace(TelegramConfig.ProxyUrl)) + { + httpClientHandler.Proxy = new WebProxy(TelegramConfig.ProxyUrl); + httpClientHandler.UseProxy = true; + } + var httpClient = new HttpClient(httpClientHandler); + + Client = new TelegramBotClient(TelegramConfig.ApiKey, httpClient); Me = await Client.GetMeAsync(); Log.LogInformation("Connected to Telegram as {username}, id:{id})", Me.Username, Me.Id); diff --git a/JetHerald/appsettings.Development.json b/JetHerald/appsettings.json similarity index 100% rename from JetHerald/appsettings.Development.json rename to JetHerald/appsettings.json