Removed unneeded httpclient for searchimages and some minor cleanup

This commit is contained in:
Kwoth
2022-03-21 13:33:43 +01:00
parent aab5bc9744
commit 4cf3bdb53a
2 changed files with 15 additions and 16 deletions

View File

@@ -7,12 +7,6 @@ using Newtonsoft.Json.Linq;
namespace NadekoBot.Modules.Nsfw;
public record TagRequest(
ulong GuildId,
bool ForceExplicit,
Booru SearchType,
params string[] Tags);
public record UrlReply
{
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> AutoButtTimers { get; } = new();
private readonly Random _rng;
private readonly HttpClient _http;
private readonly SearchImageCacher _cache;
private readonly IHttpClientFactory _httpFactory;
private readonly DbService _db;
@@ -39,14 +32,11 @@ public class SearchImagesService : ISearchImagesService, INService
public SearchImagesService(
DbService db,
IHttpClientFactory http,
SearchImageCacher cacher,
IHttpClientFactory httpFactory)
{
_db = db;
_rng = new NadekoRandom();
_http = http.CreateClient();
_http.AddFakeHeaders();
_cache = cacher;
_httpFactory = httpFactory;
@@ -205,8 +195,10 @@ public class SearchImagesService : ISearchImagesService, INService
{
try
{
using var http = _httpFactory.CreateClient();
http.AddFakeHeaders();
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()
{
Error = "",
@@ -269,8 +261,10 @@ public class SearchImagesService : ISearchImagesService, INService
{
try
{
using var http = _httpFactory.CreateClient();
http.AddFakeHeaders();
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()
{
Error = "",

View File

@@ -1,4 +1,4 @@
#nullable disable
#nullable disable
using Humanizer.Localisation;
using NadekoBot.Common.ModuleBehaviors;
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;
textChannels = guilds.Sum(g => g.Channels.Count(cx => cx is ITextChannel));
voiceChannels = guilds.Sum(g => g.Channels.Count(cx => cx is IVoiceChannel));
textChannels = guilds.Sum(static g => g.Channels.Count(static cx => cx is ITextChannel));
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));
do