mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[store] other use default client factory
This commit is contained in:
@@ -55,6 +55,7 @@ namespace Kruzya.TelegramBot.Core
|
|||||||
services.AddHostedService<DeleteService>();
|
services.AddHostedService<DeleteService>();
|
||||||
|
|
||||||
services.AddScoped<IOptionProvider, DbOptionProvider>();
|
services.AddScoped<IOptionProvider, DbOptionProvider>();
|
||||||
|
services.AddHttpClient();
|
||||||
|
|
||||||
// Trigger module handlers.
|
// Trigger module handlers.
|
||||||
_core.Modules.ConfigureServices(services);
|
_core.Modules.ConfigureServices(services);
|
||||||
|
|||||||
@@ -10,12 +10,10 @@ public class AnimBoobsService : AbstractNsfwService
|
|||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
public override StoreItem StoreItem { get; } = new("anim_boobs", "Сиськи.gif", 120, 40);
|
public override StoreItem StoreItem { get; } = new("anim_boobs", "Сиськи.gif", 120, 40);
|
||||||
|
|
||||||
public AnimBoobsService(AllowNsfw allowNsfw) : base(allowNsfw)
|
public AnimBoobsService(AllowNsfw allowNsfw, IHttpClientFactory factory) : base(allowNsfw)
|
||||||
{
|
{
|
||||||
_httpClient = new HttpClient
|
_httpClient = factory.CreateClient();
|
||||||
{
|
_httpClient.BaseAddress = new Uri("https://westdev.me/_boobs/");
|
||||||
BaseAddress = new Uri("https://westdev.me/_boobs/")
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<RandomMedia> GetRandomMediaAsync()
|
public override async Task<RandomMedia> GetRandomMediaAsync()
|
||||||
|
|||||||
@@ -9,15 +9,12 @@ public abstract class AnimalAsAService : IRandomMediaService
|
|||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
public abstract StoreItem StoreItem { get; }
|
public abstract StoreItem StoreItem { get; }
|
||||||
|
|
||||||
protected AnimalAsAService(Uri baseAddress)
|
protected AnimalAsAService(IHttpClientFactory factory, Uri baseAddress)
|
||||||
{
|
{
|
||||||
_httpClient = new HttpClient
|
_httpClient = factory.CreateClient();
|
||||||
{
|
_httpClient.BaseAddress = baseAddress;
|
||||||
BaseAddress = baseAddress
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<RandomMedia> GetRandomMediaAsync()
|
public async Task<RandomMedia> GetRandomMediaAsync()
|
||||||
{
|
{
|
||||||
var resp = await _httpClient.GetAsync("images/search");
|
var resp = await _httpClient.GetAsync("images/search");
|
||||||
|
|||||||
@@ -5,5 +5,6 @@ namespace West.TelegramBot.ContentStore.Service;
|
|||||||
public class CatApiService : AnimalAsAService
|
public class CatApiService : AnimalAsAService
|
||||||
{
|
{
|
||||||
public override StoreItem StoreItem { get; } = new("cat", "Котэ", 40, 10);
|
public override StoreItem StoreItem { get; } = new("cat", "Котэ", 40, 10);
|
||||||
public CatApiService() : base(new Uri("https://api.thecatapi.com/v1/")) {}
|
public CatApiService(IHttpClientFactory factory) :
|
||||||
|
base(factory, new Uri("https://api.thecatapi.com/v1/")) {}
|
||||||
}
|
}
|
||||||
@@ -5,5 +5,6 @@ namespace West.TelegramBot.ContentStore.Service;
|
|||||||
public class DogApiService : AnimalAsAService
|
public class DogApiService : AnimalAsAService
|
||||||
{
|
{
|
||||||
public override StoreItem StoreItem { get; } = new("dog", "Пёсель", 40, 20);
|
public override StoreItem StoreItem { get; } = new("dog", "Пёсель", 40, 20);
|
||||||
public DogApiService() : base(new Uri("https://api.thedogapi.com/v1/")) {}
|
public DogApiService(IHttpClientFactory factory) :
|
||||||
|
base(factory, new Uri("https://api.thedogapi.com/v1/")) {}
|
||||||
}
|
}
|
||||||
@@ -12,12 +12,10 @@ public class OBoobsService : AbstractNsfwService
|
|||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
public override StoreItem StoreItem { get; } = new("boobs", "Сиськи", 60, 30);
|
public override StoreItem StoreItem { get; } = new("boobs", "Сиськи", 60, 30);
|
||||||
|
|
||||||
public OBoobsService(AllowNsfw allowNsfw) : base(allowNsfw)
|
public OBoobsService(AllowNsfw allowNsfw, IHttpClientFactory factory) : base(allowNsfw)
|
||||||
{
|
{
|
||||||
_httpClient = new HttpClient
|
_httpClient = factory.CreateClient();
|
||||||
{
|
_httpClient.BaseAddress = new Uri("http://api.oboobs.ru");
|
||||||
BaseAddress = new Uri("http://api.oboobs.ru")
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<RandomMedia> GetRandomMediaAsync()
|
public override async Task<RandomMedia> GetRandomMediaAsync()
|
||||||
|
|||||||
Reference in New Issue
Block a user