mirror of
https://github.com/Jetsparrow/jetherald.git
synced 2026-04-26 06:05:04 +03:00
Redo proxy support + minor fixes
This commit is contained in:
parent
5100f7462d
commit
37faf1b601
@ -8,11 +8,13 @@ public class ConnectionStrings
|
|||||||
public class TelegramConfig
|
public class TelegramConfig
|
||||||
{
|
{
|
||||||
public string ApiKey { get; set; }
|
public string ApiKey { get; set; }
|
||||||
|
public string? ProxyUrl { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DiscordConfig
|
public class DiscordConfig
|
||||||
{
|
{
|
||||||
public string Token { get; set; }
|
public string Token { get; set; }
|
||||||
|
public string? ProxyUrl { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TimeoutConfig
|
public class TimeoutConfig
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
using DSharpPlus;
|
using DSharpPlus;
|
||||||
using DSharpPlus.CommandsNext;
|
using DSharpPlus.CommandsNext;
|
||||||
using JetHerald.Commands;
|
using JetHerald.Commands;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
namespace JetHerald.Services;
|
namespace JetHerald.Services;
|
||||||
public partial class JetHeraldBot
|
public partial class JetHeraldBot
|
||||||
{
|
{
|
||||||
@ -9,15 +11,27 @@ public partial class JetHeraldBot
|
|||||||
async Task StartDiscord()
|
async Task StartDiscord()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(DiscordConfig.Token))
|
if (string.IsNullOrWhiteSpace(DiscordConfig.Token))
|
||||||
|
{
|
||||||
|
Log.LogInformation("No Discord token, ignoring.");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DiscordBot = new DiscordClient(new()
|
Log.LogInformation("Starting Discord client.");
|
||||||
|
|
||||||
|
DiscordConfiguration cfg = new()
|
||||||
{
|
{
|
||||||
Token = DiscordConfig.Token,
|
Token = DiscordConfig.Token,
|
||||||
TokenType = TokenType.Bot,
|
TokenType = TokenType.Bot,
|
||||||
Intents = DiscordIntents.AllUnprivileged,
|
Intents = DiscordIntents.AllUnprivileged,
|
||||||
LoggerFactory = LoggerFactory
|
LoggerFactory = LoggerFactory
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(DiscordConfig.ProxyUrl))
|
||||||
|
{
|
||||||
|
cfg.Proxy = new WebProxy(DiscordConfig.ProxyUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
DiscordBot = new DiscordClient(cfg);
|
||||||
|
|
||||||
var commands = DiscordBot.UseCommandsNext(new CommandsNextConfiguration()
|
var commands = DiscordBot.UseCommandsNext(new CommandsNextConfiguration()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
|
using JetHerald.Commands;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
|
using Telegram.Bot.Exceptions;
|
||||||
using Telegram.Bot.Polling;
|
using Telegram.Bot.Polling;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegram.Bot.Exceptions;
|
|
||||||
|
|
||||||
using JetHerald.Commands;
|
|
||||||
|
|
||||||
namespace JetHerald.Services;
|
namespace JetHerald.Services;
|
||||||
public partial class JetHeraldBot
|
public partial class JetHeraldBot
|
||||||
@ -18,9 +18,23 @@ public partial class JetHeraldBot
|
|||||||
async Task StartTelegram()
|
async Task StartTelegram()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(TelegramConfig.ApiKey))
|
if (string.IsNullOrWhiteSpace(TelegramConfig.ApiKey))
|
||||||
|
{
|
||||||
|
Log.LogInformation("No Telegram token, ignoring.");
|
||||||
return;
|
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();
|
Me = await Client.GetMeAsync();
|
||||||
|
|
||||||
Log.LogInformation("Connected to Telegram as {username}, id:{id})", Me.Username, Me.Id);
|
Log.LogInformation("Connected to Telegram as {username}, id:{id})", Me.Username, Me.Id);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user