More target-typed new and redundant paranthesis cleanup

This commit is contained in:
Kwoth
2021-12-20 00:33:11 +01:00
parent 345a9e9524
commit 1b2017024c
152 changed files with 573 additions and 580 deletions

View File

@@ -9,7 +9,7 @@ public class Rule34Object : IImageData
public ImageData ToCachedImageData(Booru type)
{
return new ImageData(
return new(
$"https://img.rule34.xxx//images/{Directory}/{Image}",
Booru.Rule34,
Tags.Split(' '),

View File

@@ -22,7 +22,7 @@ public class NSFW : NadekoModule<ISearchImagesService>
public NSFW(IHttpClientFactory factory)
{
_httpFactory = factory;
_rng = new NadekoRandom();
_rng = new();
}
private async Task InternalBoobs()
@@ -85,7 +85,7 @@ public class NSFW : NadekoModule<ISearchImagesService>
if (interval < 20)
return;
t = new Timer(async (state) =>
t = new(async state =>
{
try
{
@@ -135,7 +135,7 @@ public class NSFW : NadekoModule<ISearchImagesService>
if (interval < 20)
return;
t = new Timer(async (state) =>
t = new(async state =>
{
try
{
@@ -175,7 +175,7 @@ public class NSFW : NadekoModule<ISearchImagesService>
if (interval < 20)
return;
t = new Timer(async (state) =>
t = new(async state =>
{
try
{

View File

@@ -12,7 +12,6 @@ namespace NadekoBot.Modules.Nsfw.Common;
public class SearchImageCacher : INService
{
private readonly IHttpClientFactory _httpFactory;
private readonly SemaphoreSlim _lock = new SemaphoreSlim(1, 1);
private readonly Random _rng;
private static readonly ISet<string> defaultTagBlacklist = new HashSet<string>()

View File

@@ -76,7 +76,7 @@ public class SearchImagesService : ISearchImagesService, INService
{
if (!tags.All(x => IsValidTag(x)))
{
return new UrlReply
return new()
{
Error = "One or more tags are invalid.",
Url = ""
@@ -106,7 +106,7 @@ public class SearchImagesService : ISearchImagesService, INService
if (result is null)
{
return new UrlReply
return new()
{
Error = "Image not found.",
Url = ""
@@ -129,7 +129,7 @@ public class SearchImagesService : ISearchImagesService, INService
catch (Exception ex)
{
Log.Error(ex, "Failed getting {Dapi} image: {Message}", dapi, ex.Message);
return new UrlReply
return new()
{
Error = ex.Message,
Url = ""
@@ -198,7 +198,7 @@ public class SearchImagesService : ISearchImagesService, INService
while (tasks.Count > 0); // keep looping as long as there is any task remaining to be attempted
// if we ran out of tasks, that means all tasks failed - return an error
return new UrlReply()
return new()
{
Error = "No hentai image found."
};
@@ -210,7 +210,7 @@ public class SearchImagesService : ISearchImagesService, INService
{
JToken obj;
obj = JArray.Parse(await _http.GetStringAsync($"http://api.oboobs.ru/boobs/{_rng.Next(0, 12000)}").ConfigureAwait(false))[0];
return new UrlReply
return new()
{
Error = "",
Url = $"http://media.oboobs.ru/{obj["preview"]}",
@@ -219,7 +219,7 @@ public class SearchImagesService : ISearchImagesService, INService
catch (Exception ex)
{
Log.Error(ex, "Error retreiving boob image: {Message}", ex.Message);
return new UrlReply
return new()
{
Error = ex.Message,
Url = "",
@@ -245,7 +245,7 @@ public class SearchImagesService : ISearchImagesService, INService
}
else
{
uow.NsfwBlacklistedTags.Add(new NsfwBlacklistedTag()
uow.NsfwBlacklistedTags.Add(new()
{
Tag = tag,
GuildId = guildId
@@ -278,7 +278,7 @@ public class SearchImagesService : ISearchImagesService, INService
{
JToken obj;
obj = JArray.Parse(await _http.GetStringAsync($"http://api.obutts.ru/butts/{_rng.Next(0, 6100)}"))[0];
return new UrlReply
return new()
{
Error = "",
Url = $"http://media.obutts.ru/{obj["preview"]}",
@@ -287,7 +287,7 @@ public class SearchImagesService : ISearchImagesService, INService
catch (Exception ex)
{
Log.Error(ex, "Error retreiving butt image: {Message}", ex.Message);
return new UrlReply
return new()
{
Error = ex.Message,
Url = "",
@@ -311,7 +311,7 @@ public class SearchImagesService : ISearchImagesService, INService
+ GetNhentaiExtensionInternal(model.Images.Thumbnail.T);
var url = $"https://nhentai.net/g/{model.Id}";
return new Gallery(
return new(
model.Id.ToString(),
url,
model.Title.English,