Kotz's editorconfig styles slightly modified. Target typed new usage. Brackets in expressions used for clarity.

This commit is contained in:
Kwoth
2021-12-26 02:52:09 +01:00
parent 68741ec484
commit d18f9429c6
172 changed files with 921 additions and 494 deletions

View File

@@ -4,7 +4,7 @@ namespace SystemTextJsonSamples;
public class LowerCaseNamingPolicy : JsonNamingPolicy
{
public static LowerCaseNamingPolicy Default = new LowerCaseNamingPolicy();
public static LowerCaseNamingPolicy Default = new();
public override string ConvertName(string name) =>
name.ToLower();

View File

@@ -15,5 +15,5 @@ public class StreamData
public string StreamUrl { get; set; }
public string AvatarUrl { get; set; }
public StreamDataKey CreateKey() => new StreamDataKey(StreamType, UniqueName.ToLower());
public StreamDataKey CreateKey() => new(StreamType, UniqueName.ToLower());
}

View File

@@ -9,7 +9,7 @@ public class PicartoProvider : Provider
{
private readonly IHttpClientFactory _httpClientFactory;
private static Regex Regex { get; } = new Regex(@"picarto.tv/(?<name>.+[^/])/?",
private static Regex Regex { get; } = new(@"picarto.tv/(?<name>.+[^/])/?",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
public override FollowedStream.FType Platform => FollowedStream.FType.Picarto;

View File

@@ -51,8 +51,7 @@ public abstract class Provider
/// <summary>
/// When was the first time the stream continually had errors while being retrieved
/// </summary>
protected readonly ConcurrentDictionary<string, DateTime> _failingStreams =
new ConcurrentDictionary<string, DateTime>();
protected readonly ConcurrentDictionary<string, DateTime> _failingStreams = new();
public void ClearErrorsFor(string login)
=> _failingStreams.TryRemove(login, out _);

View File

@@ -9,7 +9,7 @@ public class TwitchProvider : Provider
{
private readonly IHttpClientFactory _httpClientFactory;
private static Regex Regex { get; } = new Regex(@"twitch.tv/(?<name>.+[^/])/?",
private static Regex Regex { get; } = new(@"twitch.tv/(?<name>.+[^/])/?",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
public override FollowedStream.FType Platform => FollowedStream.FType.Twitch;

View File

@@ -9,7 +9,7 @@ public partial class Searches
public class FeedCommands : NadekoSubmodule<FeedsService>
{
private static readonly Regex YtChannelRegex =
new Regex(@"youtube\.com\/(?:c\/|channel\/|user\/)?(?<channelid>[a-zA-Z0-9\-]{1,})");
new(@"youtube\.com\/(?:c\/|channel\/|user\/)?(?<channelid>[a-zA-Z0-9\-]{1,})");
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
@@ -97,7 +97,7 @@ public partial class Searches
var i = 0;
var fs = string.Join("\n", feeds.Skip(cur * 10)
.Take(10)
.Select(x => $"`{cur * 10 + ++i}.` <#{x.ChannelId}> {x.Url}"));
.Select(x => $"`{(cur * 10) + ++i}.` <#{x.ChannelId}> {x.Url}"));
return embed.WithDescription(fs);

View File

@@ -200,16 +200,16 @@ public partial class Searches
double totalHits;
if (mode == 0)
{
hitPoints = play.Count50 * 50 +
play.Count100 * 100 +
play.Count300 * 300;
hitPoints = (play.Count50 * 50) +
(play.Count100 * 100) +
(play.Count300 * 300);
totalHits = play.Count50 + play.Count100 +
play.Count300 + play.Countmiss;
totalHits *= 300;
}
else if (mode == 1)
{
hitPoints = play.Countmiss * 0 + play.Count100 * 0.5 + play.Count300;
hitPoints = (play.Countmiss * 0) + (play.Count100 * 0.5) + play.Count300;
totalHits = (play.Countmiss + play.Count100 + play.Count300) * 300;
hitPoints *= 300;
}
@@ -221,10 +221,10 @@ public partial class Searches
}
else
{
hitPoints = play.Count50 * 50 +
play.Count100 * 100 +
play.Countkatu * 200 +
(play.Count300 + play.Countgeki) * 300;
hitPoints = (play.Count50 * 50) +
(play.Count100 * 100) +
(play.Countkatu * 200) +
((play.Count300 + play.Countgeki) * 300);
totalHits = (play.Countmiss + play.Count50 + play.Count100 +
play.Countkatu + play.Count300 + play.Countgeki) * 300;

View File

@@ -84,7 +84,7 @@ public partial class Searches
{
var character = tempList[i];
sb.AppendLine($"#{i + 1 + curPage * 9,-4}{character.Name,-23}{ShortLeagueName(character.League),-10}{character.Class,-13}{character.Level,-3}");
sb.AppendLine($"#{i + 1 + (curPage * 9),-4}{character.Name,-23}{ShortLeagueName(character.League),-10}{character.Class,-13}{character.Level,-3}");
}
sb.AppendLine("```");
@@ -212,7 +212,7 @@ public partial class Searches
}
}
private Dictionary<string, string> currencyDictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
private Dictionary<string, string> currencyDictionary = new(StringComparer.OrdinalIgnoreCase)
{
{"Chaos Orb", "Chaos Orb" },
{"Orb of Alchemy", "Orb of Alchemy" },

View File

@@ -267,7 +267,7 @@ public partial class Searches : NadekoModule<SearchesService>
public string ResultUrl { get; set; }
}
private static readonly ConcurrentDictionary<string, string> cachedShortenedLinks = new ConcurrentDictionary<string, string>();
private static readonly ConcurrentDictionary<string, string> cachedShortenedLinks = new();
[NadekoCommand, Aliases]
public async Task Shorten([Leftover] string query)
@@ -491,7 +491,7 @@ public partial class Searches : NadekoModule<SearchesService>
var data = JsonConvert.DeserializeObject<DefineModel>(res);
var datas = data.Results
.Where(x => !(x.Senses is null) && x.Senses.Count > 0 && !(x.Senses[0].Definition is null))
.Where(x => x.Senses is not null && x.Senses.Count > 0 && x.Senses[0].Definition is not null)
.Select(x => (Sense: x.Senses[0], x.PartOfSpeech));
if (!datas.Any())
@@ -611,10 +611,10 @@ public partial class Searches : NadekoModule<SearchesService>
{
var x = i * 50;
img.Mutate(m => m.FillPolygon(colorObjects[i], new PointF[] {
new PointF(x, 0),
new PointF(x + 50, 0),
new PointF(x + 50, 50),
new PointF(x, 50)
new(x, 0),
new(x + 50, 0),
new(x + 50, 50),
new(x, 50)
}));
}

View File

@@ -53,7 +53,7 @@ public class CryptoService : INService
return (crypto, null);
}
private readonly SemaphoreSlim getCryptoLock = new SemaphoreSlim(1, 1);
private readonly SemaphoreSlim getCryptoLock = new(1, 1);
public async Task<List<CryptoResponseData>> CryptoData()
{
await getCryptoLock.WaitAsync();

View File

@@ -12,8 +12,7 @@ public class FeedsService : INService
private readonly DiscordSocketClient _client;
private readonly IEmbedBuilderService _eb;
private readonly ConcurrentDictionary<string, DateTime> _lastPosts =
new ConcurrentDictionary<string, DateTime>();
private readonly ConcurrentDictionary<string, DateTime> _lastPosts = new();
public FeedsService(Bot bot, DbService db, DiscordSocketClient client, IEmbedBuilderService eb)
{
@@ -59,7 +58,7 @@ public class FeedsService : INService
.Select(item => (Item: item, LastUpdate: item.PublishingDate?.ToUniversalTime()
?? (item.SpecificItem as AtomFeedItem)?.UpdatedDate
?.ToUniversalTime()))
.Where(data => !(data.LastUpdate is null))
.Where(data => data.LastUpdate is not null)
.Select(data => (data.Item, LastUpdate: (DateTime) data.LastUpdate))
.OrderByDescending(data => data.LastUpdate)
.Reverse() // start from the oldest

View File

@@ -23,8 +23,8 @@ public class SearchesService : INService
private readonly IBotCredentials _creds;
private readonly NadekoRandom _rng;
public List<WoWJoke> WowJokes { get; } = new List<WoWJoke>();
public List<MagicItem> MagicItems { get; } = new List<MagicItem>();
public List<WoWJoke> WowJokes { get; } = new();
public List<MagicItem> MagicItems { get; } = new();
private readonly List<string> _yomamaJokes;
public SearchesService(IGoogleApiService google,
@@ -282,7 +282,7 @@ public class SearchesService : INService
_rng.Next(1, max).ToString("000") + ".png";
}
private readonly object yomamaLock = new object();
private readonly object yomamaLock = new();
private int yomamaJokeIndex = 0;
public Task<string> GetYomamaJoke()
{
@@ -567,7 +567,7 @@ public class SearchesService : INService
}
}
private static readonly HtmlParser _googleParser = new HtmlParser(new()
private static readonly HtmlParser _googleParser = new(new()
{
IsScripting = false,
IsEmbedded = false,

View File

@@ -17,10 +17,9 @@ public sealed class StreamNotificationService : INService
private readonly DiscordSocketClient _client;
private readonly NotifChecker _streamTracker;
private readonly object _shardLock = new object();
private readonly object _shardLock = new();
private readonly Dictionary<StreamDataKey, HashSet<ulong>> _trackCounter =
new Dictionary<StreamDataKey, HashSet<ulong>>();
private readonly Dictionary<StreamDataKey, HashSet<ulong>> _trackCounter = new();
private readonly Dictionary<StreamDataKey, Dictionary<ulong, HashSet<FollowedStream>>> _shardTrackedStreams;
private readonly ConcurrentHashSet<ulong> _offlineNotificationServers;

View File

@@ -118,7 +118,7 @@ public partial class Searches
{
var elem = elements[index];
eb.AddField(
$"**#{index + 1 + 12 * cur}** {elem.Username.ToLower()}",
$"**#{index + 1 + (12 * cur)}** {elem.Username.ToLower()}",
$"【{elem.Type}】\n<#{elem.ChannelId}>\n{elem.Message?.TrimTo(50)}",
true);
}