diff --git a/PluralKit.Bot/Bot.cs b/PluralKit.Bot/Bot.cs index f03dea5b..96c168c0 100644 --- a/PluralKit.Bot/Bot.cs +++ b/PluralKit.Bot/Bot.cs @@ -96,6 +96,7 @@ namespace PluralKit.Bot // LogLevel = LogSeverity.Debug // We filter log levels in Serilog, so just pass everything through (Debug is lower than Verbose) })) .AddSingleton() + .AddSingleton(_ => new HttpClient { Timeout = TimeSpan.FromSeconds(5) }) .AddTransient() .AddTransient() diff --git a/PluralKit.Bot/Services/ProxyService.cs b/PluralKit.Bot/Services/ProxyService.cs index e1ced38b..98e5baad 100644 --- a/PluralKit.Bot/Services/ProxyService.cs +++ b/PluralKit.Bot/Services/ProxyService.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Net.Http; using System.Threading.Tasks; using Discord; @@ -21,7 +20,7 @@ namespace PluralKit.Bot public string InnerText; } - class ProxyService: IDisposable { + class ProxyService { private IDiscordClient _client; private LogChannelService _logChannel; private IDataStore _data; @@ -29,9 +28,7 @@ namespace PluralKit.Bot private ILogger _logger; private WebhookExecutorService _webhookExecutor; private ProxyCacheService _cache; - - private HttpClient _httpClient; - + public ProxyService(IDiscordClient client, LogChannelService logChannel, IDataStore data, EmbedService embeds, ILogger logger, ProxyCacheService cache, WebhookExecutorService webhookExecutor) { _client = client; @@ -41,8 +38,6 @@ namespace PluralKit.Bot _cache = cache; _webhookExecutor = webhookExecutor; _logger = logger.ForContext(); - - _httpClient = new HttpClient(); } private ProxyMatch GetProxyTagMatch(string message, IEnumerable potentialMembers) @@ -272,10 +267,5 @@ namespace PluralKit.Bot _logger.Information("Bulk deleting {Count} messages in channel {Channel}", messages.Count, channel.Id); await _data.DeleteMessagesBulk(messages.Select(m => m.Id).ToList()); } - - public void Dispose() - { - _httpClient.Dispose(); - } } } \ No newline at end of file diff --git a/PluralKit.Bot/Services/WebhookExecutorService.cs b/PluralKit.Bot/Services/WebhookExecutorService.cs index d3d071e8..ed9a319a 100644 --- a/PluralKit.Bot/Services/WebhookExecutorService.cs +++ b/PluralKit.Bot/Services/WebhookExecutorService.cs @@ -25,12 +25,12 @@ namespace PluralKit.Bot private IMetrics _metrics; private HttpClient _client; - public WebhookExecutorService(IMetrics metrics, WebhookCacheService webhookCache, ILogger logger) + public WebhookExecutorService(IMetrics metrics, WebhookCacheService webhookCache, ILogger logger, HttpClient client) { _metrics = metrics; _webhookCache = webhookCache; + _client = client; _logger = logger.ForContext(); - _client = new HttpClient {Timeout = TimeSpan.FromSeconds(5)}; } public async Task ExecuteWebhook(ITextChannel channel, string name, string avatarUrl, string content, IReadOnlyCollection attachments)