mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[cas] use http client factory
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System.Net.Http;
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kruzya.TelegramBot.Core.Extensions;
|
using Kruzya.TelegramBot.Core.Extensions;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
@@ -8,12 +7,11 @@ namespace Kruzya.TelegramBot.CombotAntiSpam.Combot;
|
|||||||
|
|
||||||
public class CombotClient : ICombotClient
|
public class CombotClient : ICombotClient
|
||||||
{
|
{
|
||||||
public HttpClient _HttpClient;
|
private readonly HttpClient _httpClient;
|
||||||
|
|
||||||
public CombotClient()
|
public CombotClient(HttpClient httpClient)
|
||||||
{
|
{
|
||||||
_HttpClient = new HttpClient();
|
_httpClient = httpClient;
|
||||||
_HttpClient.BaseAddress = new Uri("https://api.cas.chat/check");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsSpammer(User user)
|
public bool IsSpammer(User user)
|
||||||
@@ -23,7 +21,7 @@ public class CombotClient : ICombotClient
|
|||||||
|
|
||||||
public async Task<bool> IsSpammerAsync(User user)
|
public async Task<bool> IsSpammerAsync(User user)
|
||||||
{
|
{
|
||||||
var result = await _HttpClient.GetJsonAsync<CombotApiResponse>($"?user_id={user.Id}");
|
var result = await _httpClient.GetJsonAsync<CombotApiResponse>($"?user_id={user.Id}");
|
||||||
return result.IsSpammer;
|
return result.IsSpammer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using Kruzya.TelegramBot.CombotAntiSpam.Combot;
|
using Kruzya.TelegramBot.CombotAntiSpam.Combot;
|
||||||
using Kruzya.TelegramBot.Core;
|
using Kruzya.TelegramBot.Core;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.CombotAntiSpam;
|
namespace Kruzya.TelegramBot.CombotAntiSpam;
|
||||||
|
|
||||||
@@ -12,6 +13,9 @@ public class CombotAntiSpam : Module
|
|||||||
|
|
||||||
public override void ConfigureServices(IServiceCollection services)
|
public override void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddSingleton<ICombotClient, CombotClient>();
|
services.AddHttpClient<ICombotClient, CombotClient>(c =>
|
||||||
|
{
|
||||||
|
c.BaseAddress = new Uri("https://api.cas.chat/check");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user