mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
Removed unneeded httpclient for searchimages and some minor cleanup
This commit is contained in:
@@ -7,12 +7,6 @@ using Newtonsoft.Json.Linq;
|
|||||||
|
|
||||||
namespace NadekoBot.Modules.Nsfw;
|
namespace NadekoBot.Modules.Nsfw;
|
||||||
|
|
||||||
public record TagRequest(
|
|
||||||
ulong GuildId,
|
|
||||||
bool ForceExplicit,
|
|
||||||
Booru SearchType,
|
|
||||||
params string[] Tags);
|
|
||||||
|
|
||||||
public record UrlReply
|
public record UrlReply
|
||||||
{
|
{
|
||||||
public string Error { get; init; }
|
public string Error { get; init; }
|
||||||
@@ -30,7 +24,6 @@ public class SearchImagesService : ISearchImagesService, INService
|
|||||||
public ConcurrentDictionary<ulong, Timer> AutoBoobTimers { get; } = new();
|
public ConcurrentDictionary<ulong, Timer> AutoBoobTimers { get; } = new();
|
||||||
public ConcurrentDictionary<ulong, Timer> AutoButtTimers { get; } = new();
|
public ConcurrentDictionary<ulong, Timer> AutoButtTimers { get; } = new();
|
||||||
private readonly Random _rng;
|
private readonly Random _rng;
|
||||||
private readonly HttpClient _http;
|
|
||||||
private readonly SearchImageCacher _cache;
|
private readonly SearchImageCacher _cache;
|
||||||
private readonly IHttpClientFactory _httpFactory;
|
private readonly IHttpClientFactory _httpFactory;
|
||||||
private readonly DbService _db;
|
private readonly DbService _db;
|
||||||
@@ -39,14 +32,11 @@ public class SearchImagesService : ISearchImagesService, INService
|
|||||||
|
|
||||||
public SearchImagesService(
|
public SearchImagesService(
|
||||||
DbService db,
|
DbService db,
|
||||||
IHttpClientFactory http,
|
|
||||||
SearchImageCacher cacher,
|
SearchImageCacher cacher,
|
||||||
IHttpClientFactory httpFactory)
|
IHttpClientFactory httpFactory)
|
||||||
{
|
{
|
||||||
_db = db;
|
_db = db;
|
||||||
_rng = new NadekoRandom();
|
_rng = new NadekoRandom();
|
||||||
_http = http.CreateClient();
|
|
||||||
_http.AddFakeHeaders();
|
|
||||||
_cache = cacher;
|
_cache = cacher;
|
||||||
_httpFactory = httpFactory;
|
_httpFactory = httpFactory;
|
||||||
|
|
||||||
@@ -205,8 +195,10 @@ public class SearchImagesService : ISearchImagesService, INService
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
using var http = _httpFactory.CreateClient();
|
||||||
|
http.AddFakeHeaders();
|
||||||
JToken obj;
|
JToken obj;
|
||||||
obj = JArray.Parse(await _http.GetStringAsync($"http://api.oboobs.ru/boobs/{_rng.Next(0, 12000)}"))[0];
|
obj = JArray.Parse(await http.GetStringAsync($"http://api.oboobs.ru/boobs/{_rng.Next(0, 12000)}"))[0];
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
Error = "",
|
Error = "",
|
||||||
@@ -269,8 +261,10 @@ public class SearchImagesService : ISearchImagesService, INService
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
using var http = _httpFactory.CreateClient();
|
||||||
|
http.AddFakeHeaders();
|
||||||
JToken obj;
|
JToken obj;
|
||||||
obj = JArray.Parse(await _http.GetStringAsync($"http://api.obutts.ru/butts/{_rng.Next(0, 6100)}"))[0];
|
obj = JArray.Parse(await http.GetStringAsync($"http://api.obutts.ru/butts/{_rng.Next(0, 6100)}"))[0];
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
Error = "",
|
Error = "",
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
using Humanizer.Localisation;
|
using Humanizer.Localisation;
|
||||||
using NadekoBot.Common.ModuleBehaviors;
|
using NadekoBot.Common.ModuleBehaviors;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -133,11 +133,16 @@ public class StatsService : IStatsService, IReadyExecutor, INService, IDisposabl
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task OnReadyAsync()
|
private void InitializeChannelCount()
|
||||||
{
|
{
|
||||||
var guilds = _client.Guilds;
|
var guilds = _client.Guilds;
|
||||||
textChannels = guilds.Sum(g => g.Channels.Count(cx => cx is ITextChannel));
|
textChannels = guilds.Sum(static g => g.Channels.Count(static cx => cx is ITextChannel));
|
||||||
voiceChannels = guilds.Sum(g => g.Channels.Count(cx => cx is IVoiceChannel));
|
voiceChannels = guilds.Sum(static g => g.Channels.Count(static cx => cx is IVoiceChannel));
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task OnReadyAsync()
|
||||||
|
{
|
||||||
|
InitializeChannelCount();
|
||||||
|
|
||||||
using var timer = new PeriodicTimer(TimeSpan.FromHours(1));
|
using var timer = new PeriodicTimer(TimeSpan.FromHours(1));
|
||||||
do
|
do
|
||||||
|
Reference in New Issue
Block a user