- More code cleanup and codestyle updates

- Fixed some possible nullref exceptions
- Methods signatures now have up to 3 parameters before breakaing down each parameter in a separate line
- Method invocations have the same rule, except the first parameter will be in the same line as the invocation to prevent some ugliness when passing lambas as arguments
- Applied many more codestyles
- Extensions folder fully reformatted
This commit is contained in:
Kwoth
2021-12-26 17:28:39 +01:00
parent b85ba177cd
commit d5fd6aae8e
217 changed files with 1017 additions and 1494 deletions

View File

@@ -20,5 +20,5 @@ public class AnimeResult
public string AverageScore { get; set; }
public string Link => "http://anilist.co/anime/" + Id;
public string Synopsis => Description?.Substring(0, Description.Length > 500 ? 500 : Description.Length) + "...";
public string Synopsis => Description?[..(Description.Length > 500 ? 500 : Description.Length)] + "...";
}

View File

@@ -33,12 +33,8 @@ public class ImageCacherObject : IComparable<ImageCacherObject>
}
public override string ToString()
{
return FileUrl;
}
=> FileUrl;
public int CompareTo(ImageCacherObject other)
{
return string.Compare(FileUrl, other.FileUrl, StringComparison.InvariantCulture);
}
=> string.Compare(FileUrl, other.FileUrl, StringComparison.InvariantCulture);
}

View File

@@ -20,5 +20,5 @@ public class MangaResult
[JsonProperty("average_score")]
public string AverageScore { get; set; }
public string Link => "http://anilist.co/manga/" + Id;
public string Synopsis => Description?.Substring(0, Description.Length > 500 ? 500 : Description.Length) + "...";
public string Synopsis => Description?[..(Description.Length > 500 ? 500 : Description.Length)] + "...";
}

View File

@@ -236,7 +236,5 @@ public class NotifChecker
}
public void UntrackStreamByKey(in StreamDataKey key)
{
CacheDeleteData(key);
}
=> CacheDeleteData(key);
}

View File

@@ -15,9 +15,7 @@ public class PicartoProvider : Provider
public override FollowedStream.FType Platform => FollowedStream.FType.Picarto;
public PicartoProvider(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
}
=> _httpClientFactory = httpClientFactory;
public override Task<bool> IsValidUrl(string url)
{
@@ -82,8 +80,7 @@ public class PicartoProvider : Provider
}
private StreamData ToStreamData(PicartoChannelResponse stream)
{
return new()
=> new()
{
StreamType = FollowedStream.FType.Picarto,
Name = stream.Name,
@@ -96,5 +93,4 @@ public class PicartoProvider : Provider
StreamUrl = $"https://picarto.tv/{stream.Name}",
AvatarUrl = stream.Avatar
};
}
}

View File

@@ -15,9 +15,7 @@ public class TwitchProvider : Provider
public override FollowedStream.FType Platform => FollowedStream.FType.Twitch;
public TwitchProvider(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
}
=> _httpClientFactory = httpClientFactory;
public override Task<bool> IsValidUrl(string url)
{
@@ -111,8 +109,7 @@ public class TwitchProvider : Provider
}
private StreamData ToStreamData(TwitchResponseV5.Stream stream)
{
return new()
=> new()
{
StreamType = FollowedStream.FType.Twitch,
Name = stream.Channel.DisplayName,
@@ -125,5 +122,4 @@ public class TwitchProvider : Provider
StreamUrl = $"https://twitch.tv/{stream.Channel.Name}",
AvatarUrl = stream.Channel.Logo
};
}
}

View File

@@ -10,9 +10,7 @@ public partial class Searches
[NadekoCommand, Aliases]
public async Task Yomama()
{
await SendConfirmAsync(await _service.GetYomamaJoke().ConfigureAwait(false)).ConfigureAwait(false);
}
=> await SendConfirmAsync(await _service.GetYomamaJoke().ConfigureAwait(false)).ConfigureAwait(false);
[NadekoCommand, Aliases]
public async Task Randjoke()
@@ -23,9 +21,7 @@ public partial class Searches
[NadekoCommand, Aliases]
public async Task ChuckNorris()
{
await SendConfirmAsync(await _service.GetChuckNorrisJoke().ConfigureAwait(false)).ConfigureAwait(false);
}
=> await SendConfirmAsync(await _service.GetChuckNorrisJoke().ConfigureAwait(false)).ConfigureAwait(false);
[NadekoCommand, Aliases]
public async Task WowJoke()

View File

@@ -29,9 +29,7 @@ public partial class Searches
private readonly IHttpClientFactory _httpFactory;
public MemegenCommands(IHttpClientFactory factory)
{
_httpFactory = factory;
}
=> _httpFactory = factory;
[NadekoCommand, Aliases]
public async Task Memelist(int page = 1)

View File

@@ -21,9 +21,7 @@ public partial class Searches
private readonly IHttpClientFactory _httpFactory;
public PathOfExileCommands(IHttpClientFactory httpFactory)
{
_httpFactory = httpFactory;
}
=> _httpFactory = httpFactory;
[NadekoCommand, Aliases]
public async Task PathOfExile(string usr, string league = "", int page = 1)

View File

@@ -22,11 +22,9 @@ public partial class Searches
[NadekoCommand, Aliases]
public async Task Placelist()
{
await SendConfirmAsync(GetText(strs.list_of_place_tags(Prefix)),
=> await SendConfirmAsync(GetText(strs.list_of_place_tags(Prefix)),
_typesStr)
.ConfigureAwait(false);
}
[NadekoCommand, Aliases]
public async Task Place(PlaceType placeType, uint width = 0, uint height = 0)
@@ -60,10 +58,10 @@ public partial class Searches
break;
}
var rng = new NadekoRandom();
if (width <= 0 || width > 1000)
if (width is <= 0 or > 1000)
width = (uint)rng.Next(250, 850);
if (height <= 0 || height > 1000)
if (height is <= 0 or > 1000)
height = (uint)rng.Next(250, 850);
url += $"/{width}/{height}";

View File

@@ -14,9 +14,7 @@ public partial class Searches
public IReadOnlyDictionary<string, SearchPokemonAbility> PokemonAbilities => _cache.LocalData.PokemonAbilities;
public PokemonSearchCommands(IDataCache cache)
{
_cache = cache;
}
=> _cache = cache;
[NadekoCommand, Aliases]
public async Task Pokemon([Leftover] string pokemon = null)

View File

@@ -130,7 +130,7 @@ public class FeedsService : INService
embed.WithTitle(title.TrimTo(256));
var desc = feedItem.Description?.StripHTML();
var desc = feedItem.Description?.StripHtml();
if (!string.IsNullOrWhiteSpace(feedItem.Description))
embed.WithDescription(desc.TrimTo(2048));
@@ -167,7 +167,7 @@ public class FeedsService : INService
public bool AddFeed(ulong guildId, ulong channelId, string rssFeed)
{
rssFeed.ThrowIfNull(nameof(rssFeed));
ArgumentNullException.ThrowIfNull(rssFeed, nameof(rssFeed));
var fs = new FeedSub()
{

View File

@@ -163,13 +163,12 @@ public class SearchesService : INService
}
public Task<((string Address, DateTime Time, string TimeZoneName), TimeErrors?)> GetTimeDataAsync(string arg)
{
return GetTimeDataFactory(arg);
//return _cache.GetOrAddCachedDataAsync($"nadeko_time_{arg}",
// GetTimeDataFactory,
// arg,
// TimeSpan.FromMinutes(1));
}
=> GetTimeDataFactory(arg);
//return _cache.GetOrAddCachedDataAsync($"nadeko_time_{arg}",
// GetTimeDataFactory,
// arg,
// TimeSpan.FromMinutes(1));
private async Task<((string Address, DateTime Time, string TimeZoneName), TimeErrors?)> GetTimeDataFactory(string query)
{
query = query.Trim();

View File

@@ -3,7 +3,6 @@ using NadekoBot.Modules.Searches.Common;
using NadekoBot.Modules.Searches.Common.StreamNotifications;
using NadekoBot.Services.Database.Models;
using StackExchange.Redis;
using NadekoBot.Common.Collections;
using NadekoBot.Db;
using NadekoBot.Db.Models;
@@ -477,9 +476,7 @@ public sealed class StreamNotificationService : INService
}
public Task<StreamData> GetStreamDataAsync(string url)
{
return _streamTracker.GetStreamDataByUrlAsync(url);
}
=> _streamTracker.GetStreamDataByUrlAsync(url);
private HashSet<FollowedStream> GetLocalGuildStreams(in StreamDataKey key, ulong guildId)
{

View File

@@ -13,9 +13,7 @@ public partial class Searches
private readonly DbService _db;
public StreamNotificationCommands(DbService db)
{
_db = db;
}
=> _db = db;
// private static readonly Regex picartoRegex = new Regex(@"picarto.tv/(?<name>.+[^/])/?",
// RegexOptions.Compiled | RegexOptions.IgnoreCase);

View File

@@ -87,9 +87,6 @@ public partial class Searches
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Translangs()
{
await ctx.Channel.SendTableAsync(_service.GetLanguages(), str => $"{str,-15}", 3).ConfigureAwait(false);
}
=> await ctx.Channel.SendTableAsync(_service.GetLanguages(), str => $"{str,-15}", 3).ConfigureAwait(false);
}
}

View File

@@ -11,9 +11,7 @@ public partial class Searches
private readonly IHttpClientFactory _httpFactory;
public XkcdCommands(IHttpClientFactory factory)
{
_httpFactory = factory;
}
=> _httpFactory = factory;
[NadekoCommand, Aliases]
[Priority(0)]