Updated editorconfig to (mostly?) require braces around if/else statements, and applied the new formatting rules

This commit is contained in:
Kwoth
2022-02-02 01:44:45 +01:00
parent b22cd5a81e
commit ffa2c3f119
202 changed files with 2108 additions and 920 deletions

View File

@@ -65,7 +65,8 @@ public partial class NSFW : NadekoModule<ISearchImagesService>
if (interval == 0)
{
if (!_service.AutoHentaiTimers.TryRemove(ctx.Channel.Id, out t)) return;
if (!_service.AutoHentaiTimers.TryRemove(ctx.Channel.Id, out t))
return;
t.Change(Timeout.Infinite, Timeout.Infinite); //proper way to disable the timer
await ReplyConfirmLocalizedAsync(strs.stopped);
@@ -120,7 +121,8 @@ public partial class NSFW : NadekoModule<ISearchImagesService>
if (interval == 0)
{
if (!_service.AutoBoobTimers.TryRemove(ctx.Channel.Id, out t)) return;
if (!_service.AutoBoobTimers.TryRemove(ctx.Channel.Id, out t))
return;
t.Change(Timeout.Infinite, Timeout.Infinite);
await ReplyConfirmLocalizedAsync(strs.stopped);
@@ -166,7 +168,8 @@ public partial class NSFW : NadekoModule<ISearchImagesService>
if (interval == 0)
{
if (!_service.AutoButtTimers.TryRemove(ctx.Channel.Id, out t)) return;
if (!_service.AutoButtTimers.TryRemove(ctx.Channel.Id, out t))
return;
t.Change(Timeout.Infinite, Timeout.Infinite); //proper way to disable the timer
await ReplyConfirmLocalizedAsync(strs.stopped);

View File

@@ -87,6 +87,7 @@ public class SearchImageCacher : INService
// both 'kiss' (real tag returned by the image) and 'kissing' will be populated with
// retreived images
foreach (var tag in img.Tags.Concat(tags).Distinct())
{
if (typeUsedTags.Contains(tag))
{
var set = _cache.GetOrCreate<HashSet<ImageData>>(Key(type, tag),
@@ -99,6 +100,7 @@ public class SearchImageCacher : INService
if (set.Count < 100)
set.Add(img);
}
}
}
}
@@ -127,10 +129,12 @@ public class SearchImageCacher : INService
foreach (var tag in tags)
// if any tag is missing from cache, that means there is no result
{
if (_cache.TryGetValue<HashSet<ImageData>>(Key(type, tag), out var set))
setList.Add(set);
else
return null;
}
if (setList.Count == 0)
return null;
@@ -169,8 +173,11 @@ public class SearchImageCacher : INService
// remove from cache
foreach (var tag in tags)
{
if (_cache.TryGetValue<HashSet<ImageData>>(Key(type, tag), out var items))
items.Remove(toReturn);
}
return toReturn;
}
}

View File

@@ -75,7 +75,11 @@ public class SearchImagesService : ISearchImagesService, INService
CancellationToken cancel)
{
if (!tags.All(x => IsValidTag(x)))
return new() { Error = "One or more tags are invalid.", Url = "" };
return new()
{
Error = "One or more tags are invalid.",
Url = ""
};
Log.Information("Getting {V} image for Guild: {GuildId}...", dapi.ToString(), guildId);
try
@@ -84,22 +88,33 @@ public class SearchImagesService : ISearchImagesService, INService
if (dapi == Booru.E621)
for (var i = 0; i < tags.Length; ++i)
{
if (tags[i] == "yuri")
tags[i] = "female/female";
}
if (dapi == Booru.Derpibooru)
for (var i = 0; i < tags.Length; ++i)
{
if (tags[i] == "yuri")
tags[i] = "lesbian";
}
var result = await _cache.GetImageNew(tags, forceExplicit, dapi, blTags ?? new HashSet<string>(), cancel);
if (result is null)
return new() { Error = "Image not found.", Url = "" };
return new()
{
Error = "Image not found.",
Url = ""
};
var reply = new UrlReply
{
Error = "", Url = result.FileUrl, Rating = result.Rating, Provider = result.SearchType.ToString()
Error = "",
Url = result.FileUrl,
Rating = result.Rating,
Provider = result.SearchType.ToString()
};
reply.Tags.AddRange(result.Tags);
@@ -109,7 +124,11 @@ public class SearchImagesService : ISearchImagesService, INService
catch (Exception ex)
{
Log.Error(ex, "Failed getting {Dapi} image: {Message}", dapi, ex.Message);
return new() { Error = ex.Message, Url = "" };
return new()
{
Error = ex.Message,
Url = ""
};
}
}
@@ -168,7 +187,10 @@ 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() { Error = "No hentai image found." };
return new()
{
Error = "No hentai image found."
};
}
public async Task<UrlReply> Boobs()
@@ -177,12 +199,20 @@ public class SearchImagesService : ISearchImagesService, INService
{
JToken obj;
obj = JArray.Parse(await _http.GetStringAsync($"http://api.oboobs.ru/boobs/{_rng.Next(0, 12000)}"))[0];
return new() { Error = "", Url = $"http://media.oboobs.ru/{obj["preview"]}" };
return new()
{
Error = "",
Url = $"http://media.oboobs.ru/{obj["preview"]}"
};
}
catch (Exception ex)
{
Log.Error(ex, "Error retreiving boob image: {Message}", ex.Message);
return new() { Error = ex.Message, Url = "" };
return new()
{
Error = ex.Message,
Url = ""
};
}
}
@@ -203,7 +233,11 @@ public class SearchImagesService : ISearchImagesService, INService
}
else
{
uow.NsfwBlacklistedTags.Add(new() { Tag = tag, GuildId = guildId });
uow.NsfwBlacklistedTags.Add(new()
{
Tag = tag,
GuildId = guildId
});
uow.SaveChanges();
}
@@ -216,7 +250,8 @@ public class SearchImagesService : ISearchImagesService, INService
{
lock (_taglock)
{
if (BlacklistedTags.TryGetValue(guildId, out var tags)) return new(tags.ToArray());
if (BlacklistedTags.TryGetValue(guildId, out var tags))
return new(tags.ToArray());
return new(Array.Empty<string>());
}
@@ -228,12 +263,20 @@ 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() { Error = "", Url = $"http://media.obutts.ru/{obj["preview"]}" };
return new()
{
Error = "",
Url = $"http://media.obutts.ru/{obj["preview"]}"
};
}
catch (Exception ex)
{
Log.Error(ex, "Error retreiving butt image: {Message}", ex.Message);
return new() { Error = ex.Message, Url = "" };
return new()
{
Error = ex.Message,
Url = ""
};
}
}
@@ -262,7 +305,11 @@ public class SearchImagesService : ISearchImagesService, INService
model.NumPages,
model.NumFavorites,
model.UploadDate.ToUnixTimestamp().UtcDateTime,
model.Tags.Map(x => new Tag { Name = x.Name, Url = "https://nhentai.com/" + x.Url }));
model.Tags.Map(x => new Tag
{
Name = x.Name,
Url = "https://nhentai.com/" + x.Url
}));
}
private async Task<NhentaiApiModel.Gallery> GetNhentaiByIdInternalAsync(uint id)

View File

@@ -26,7 +26,8 @@ public sealed class DanbooruImageDownloader : DapiImageDownloader
_baseUrl + "/tags.json" + $"?search[name_or_alias_matches]={tag}",
_serializerOptions,
cancel);
if (tags is { Length: > 0 }) return _existentTags[tag] = true;
if (tags is { Length: > 0 })
return _existentTags[tag] = true;
return _nonexistentTags[tag] = false;
}

View File

@@ -19,8 +19,10 @@ public abstract class DapiImageDownloader : ImageDownloader<DapiImageObject>
// if any of the tags is not valid, the query is not valid
foreach (var result in results)
{
if (!result)
return false;
}
return true;
}