diff --git a/modules/CombotAntiSpam/Combot/CombotClient.cs b/modules/CombotAntiSpam/Combot/CombotClient.cs index 1ddd371..ddfe4c1 100644 --- a/modules/CombotAntiSpam/Combot/CombotClient.cs +++ b/modules/CombotAntiSpam/Combot/CombotClient.cs @@ -1,5 +1,4 @@ -using System; -using System.Net.Http; +using System.Net.Http; using System.Threading.Tasks; using Kruzya.TelegramBot.Core.Extensions; using Telegram.Bot.Types; @@ -8,12 +7,11 @@ namespace Kruzya.TelegramBot.CombotAntiSpam.Combot; public class CombotClient : ICombotClient { - public HttpClient _HttpClient; + private readonly HttpClient _httpClient; - public CombotClient() + public CombotClient(HttpClient httpClient) { - _HttpClient = new HttpClient(); - _HttpClient.BaseAddress = new Uri("https://api.cas.chat/check"); + _httpClient = httpClient; } public bool IsSpammer(User user) @@ -23,7 +21,7 @@ public class CombotClient : ICombotClient public async Task IsSpammerAsync(User user) { - var result = await _HttpClient.GetJsonAsync($"?user_id={user.Id}"); + var result = await _httpClient.GetJsonAsync($"?user_id={user.Id}"); return result.IsSpammer; } } \ No newline at end of file diff --git a/modules/CombotAntiSpam/CombotAntiSpam.cs b/modules/CombotAntiSpam/CombotAntiSpam.cs index 9bd9944..0abc135 100644 --- a/modules/CombotAntiSpam/CombotAntiSpam.cs +++ b/modules/CombotAntiSpam/CombotAntiSpam.cs @@ -1,6 +1,7 @@ using Kruzya.TelegramBot.CombotAntiSpam.Combot; using Kruzya.TelegramBot.Core; using Microsoft.Extensions.DependencyInjection; +using System; namespace Kruzya.TelegramBot.CombotAntiSpam; @@ -12,6 +13,9 @@ public class CombotAntiSpam : Module public override void ConfigureServices(IServiceCollection services) { - services.AddSingleton(); + services.AddHttpClient(c => + { + c.BaseAddress = new Uri("https://api.cas.chat/check"); + }); } } \ No newline at end of file