mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
Kotz's editorconfig styles slightly modified. Target typed new usage. Brackets in expressions used for clarity.
This commit is contained in:
@@ -3,11 +3,10 @@
|
||||
public static class CommandNameLoadHelper
|
||||
{
|
||||
|
||||
private static YamlDotNet.Serialization.IDeserializer _deserializer
|
||||
private static readonly YamlDotNet.Serialization.IDeserializer _deserializer
|
||||
= new YamlDotNet.Serialization.Deserializer();
|
||||
|
||||
public static Lazy<Dictionary<string, string[]>> LazyCommandAliases
|
||||
= new Lazy<Dictionary<string, string[]>>(() => LoadCommandNames());
|
||||
public static Lazy<Dictionary<string, string[]>> LazyCommandAliases = new(() => LoadCommandNames());
|
||||
public static Dictionary<string, string[]> LoadCommandNames(string aliasesFilePath = "data/aliases.yml")
|
||||
{
|
||||
var text = File.ReadAllText(aliasesFilePath);
|
||||
|
@@ -344,7 +344,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
Node previous = null;
|
||||
for (var current = tables.Buckets[bucketNo]; current != null; current = current.Next)
|
||||
{
|
||||
Debug.Assert(previous is null && current == tables.Buckets[bucketNo] || previous.Next == current);
|
||||
Debug.Assert((previous is null && current == tables.Buckets[bucketNo]) || previous.Next == current);
|
||||
|
||||
if (hashcode == current.Hashcode && _comparer.Equals(current.Item, item))
|
||||
{
|
||||
@@ -470,7 +470,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
Node previous = null;
|
||||
for (var current = tables.Buckets[bucketNo]; current != null; current = current.Next)
|
||||
{
|
||||
Debug.Assert(previous is null && current == tables.Buckets[bucketNo] || previous.Next == current);
|
||||
Debug.Assert((previous is null && current == tables.Buckets[bucketNo]) || previous.Next == current);
|
||||
if (hashcode == current.Hashcode && _comparer.Equals(current.Item, item))
|
||||
{
|
||||
return false;
|
||||
@@ -581,7 +581,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
checked
|
||||
{
|
||||
// Double the size of the buckets table and add one, so that we have an odd integer.
|
||||
newLength = tables.Buckets.Length * 2 + 1;
|
||||
newLength = (tables.Buckets.Length * 2) + 1;
|
||||
|
||||
// Now, we only need to check odd integers, and find the first that is not divisible
|
||||
// by 3, 5 or 7.
|
||||
|
@@ -6,7 +6,7 @@ namespace NadekoBot.Common.Collections;
|
||||
public class IndexedCollection<T> : IList<T> where T : class, IIndexed
|
||||
{
|
||||
public List<T> Source { get; }
|
||||
private readonly object _locker = new object();
|
||||
private readonly object _locker = new();
|
||||
|
||||
public int Count => Source.Count;
|
||||
public bool IsReadOnly => false;
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
public class DownloadTracker : INService
|
||||
{
|
||||
private ConcurrentDictionary<ulong, DateTime> LastDownloads { get; } = new ConcurrentDictionary<ulong, DateTime>();
|
||||
private SemaphoreSlim downloadUsersSemaphore = new SemaphoreSlim(1, 1);
|
||||
private ConcurrentDictionary<ulong, DateTime> LastDownloads { get; } = new();
|
||||
private readonly SemaphoreSlim downloadUsersSemaphore = new(1, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Ensures all users on the specified guild were downloaded within the last hour.
|
||||
|
@@ -49,7 +49,7 @@ public readonly struct kwum : IEquatable<kwum>
|
||||
}
|
||||
|
||||
public static kwum operator +(kwum left, kwum right)
|
||||
=> new kwum(left._value + right._value);
|
||||
=> new(left._value + right._value);
|
||||
|
||||
public static bool operator ==(kwum left, kwum right)
|
||||
=> left._value == right._value;
|
||||
@@ -63,7 +63,7 @@ public readonly struct kwum : IEquatable<kwum>
|
||||
public static implicit operator int(kwum kwum)
|
||||
=> kwum._value;
|
||||
public static implicit operator kwum(int num)
|
||||
=> new kwum(num);
|
||||
=> new(num);
|
||||
|
||||
public static bool IsValidChar(char c)
|
||||
=> ValidCharacters.Contains(c);
|
||||
@@ -77,7 +77,7 @@ public readonly struct kwum : IEquatable<kwum>
|
||||
while (localValue > 0)
|
||||
{
|
||||
localValue = Math.DivRem(localValue, count, out var rem);
|
||||
chars[--arrSize] = ValidCharacters[(int)rem];
|
||||
chars[--arrSize] = ValidCharacters[rem];
|
||||
}
|
||||
|
||||
return new(chars);
|
||||
|
@@ -112,8 +112,8 @@ public abstract class NadekoModule : ModuleBase
|
||||
{
|
||||
var _ = Task.Run(() =>
|
||||
{
|
||||
if (!(arg is SocketUserMessage userMsg) ||
|
||||
!(userMsg.Channel is ITextChannel chan) ||
|
||||
if (arg is not SocketUserMessage userMsg ||
|
||||
userMsg.Channel is not ITextChannel chan ||
|
||||
userMsg.Author.Id != userId ||
|
||||
userMsg.Channel.Id != channelId)
|
||||
{
|
||||
|
@@ -36,7 +36,7 @@ public class NadekoRandom : Random
|
||||
var bytes = new byte[sizeof(int)];
|
||||
_rng.GetBytes(bytes);
|
||||
var sign = Math.Sign(BitConverter.ToInt32(bytes, 0));
|
||||
return sign * BitConverter.ToInt32(bytes, 0) % (maxValue - minValue) + minValue;
|
||||
return (sign * BitConverter.ToInt32(bytes, 0) % (maxValue - minValue)) + minValue;
|
||||
}
|
||||
|
||||
public long NextLong(long minValue, long maxValue)
|
||||
@@ -48,7 +48,7 @@ public class NadekoRandom : Random
|
||||
var bytes = new byte[sizeof(long)];
|
||||
_rng.GetBytes(bytes);
|
||||
var sign = Math.Sign(BitConverter.ToInt64(bytes, 0));
|
||||
return sign * BitConverter.ToInt64(bytes, 0) % (maxValue - minValue) + minValue;
|
||||
return (sign * BitConverter.ToInt64(bytes, 0) % (maxValue - minValue)) + minValue;
|
||||
}
|
||||
|
||||
public override void NextBytes(byte[] buffer)
|
||||
@@ -60,7 +60,7 @@ public class NadekoRandom : Random
|
||||
{
|
||||
var bytes = new byte[sizeof(double)];
|
||||
_rng.GetBytes(bytes);
|
||||
return Math.Abs(BitConverter.ToDouble(bytes, 0) / double.MaxValue + 1);
|
||||
return Math.Abs((BitConverter.ToDouble(bytes, 0) / double.MaxValue) + 1);
|
||||
}
|
||||
|
||||
public override double NextDouble()
|
||||
|
@@ -2,9 +2,8 @@
|
||||
|
||||
public class EventPubSub : IPubSub
|
||||
{
|
||||
private readonly Dictionary<string, Dictionary<Delegate, List<Func<object, ValueTask>>>> _actions
|
||||
= new Dictionary<string, Dictionary<Delegate, List<Func<object, ValueTask>>>>();
|
||||
private readonly object locker = new object();
|
||||
private readonly Dictionary<string, Dictionary<Delegate, List<Func<object, ValueTask>>>> _actions = new();
|
||||
private readonly object locker = new();
|
||||
|
||||
public Task Sub<TData>(in TypedKey<TData> key, Func<TData, ValueTask> action)
|
||||
{
|
||||
|
@@ -5,7 +5,7 @@ namespace NadekoBot.Common;
|
||||
|
||||
public class JsonSeria : ISeria
|
||||
{
|
||||
private JsonSerializerOptions serializerOptions = new JsonSerializerOptions()
|
||||
private readonly JsonSerializerOptions serializerOptions = new()
|
||||
{
|
||||
Converters =
|
||||
{
|
||||
|
@@ -10,7 +10,7 @@ public readonly struct TypedKey<TData>
|
||||
}
|
||||
|
||||
public static implicit operator TypedKey<TData>(in string input)
|
||||
=> new TypedKey<TData>(input);
|
||||
=> new(input);
|
||||
public static implicit operator string(in TypedKey<TData> input)
|
||||
=> input.Key;
|
||||
|
||||
|
@@ -11,7 +11,7 @@ public class YamlSeria : IConfigSeria
|
||||
private readonly IDeserializer _deserializer;
|
||||
|
||||
private static readonly Regex CodePointRegex
|
||||
= new Regex(@"(\\U(?<code>[a-zA-Z0-9]{8})|\\u(?<code>[a-zA-Z0-9]{4})|\\x(?<code>[a-zA-Z0-9]{2}))",
|
||||
= new(@"(\\U(?<code>[a-zA-Z0-9]{8})|\\u(?<code>[a-zA-Z0-9]{4})|\\x(?<code>[a-zA-Z0-9]{2}))",
|
||||
RegexOptions.Compiled);
|
||||
|
||||
public YamlSeria()
|
||||
|
@@ -5,9 +5,9 @@ namespace NadekoBot.Common;
|
||||
|
||||
public class ReplacementBuilder
|
||||
{
|
||||
private static readonly Regex rngRegex = new Regex("%rng(?:(?<from>(?:-)?\\d+)-(?<to>(?:-)?\\d+))?%", RegexOptions.Compiled);
|
||||
private ConcurrentDictionary<string, Func<string>> _reps = new ConcurrentDictionary<string, Func<string>>();
|
||||
private ConcurrentDictionary<Regex, Func<Match, string>> _regex = new ConcurrentDictionary<Regex, Func<Match, string>>();
|
||||
private static readonly Regex rngRegex = new("%rng(?:(?<from>(?:-)?\\d+)-(?<to>(?:-)?\\d+))?%", RegexOptions.Compiled);
|
||||
private readonly ConcurrentDictionary<string, Func<string>> _reps = new();
|
||||
private readonly ConcurrentDictionary<Regex, Func<Match, string>> _regex = new();
|
||||
|
||||
public ReplacementBuilder()
|
||||
{
|
||||
|
@@ -21,7 +21,7 @@ public sealed record SmartEmbedText : SmartText
|
||||
!string.IsNullOrWhiteSpace(Url) ||
|
||||
!string.IsNullOrWhiteSpace(Thumbnail) ||
|
||||
!string.IsNullOrWhiteSpace(Image) ||
|
||||
Footer != null && (!string.IsNullOrWhiteSpace(Footer.Text) || !string.IsNullOrWhiteSpace(Footer.IconUrl)) ||
|
||||
(Footer != null && (!string.IsNullOrWhiteSpace(Footer.Text) || !string.IsNullOrWhiteSpace(Footer.IconUrl))) ||
|
||||
Fields is { Length: > 0 };
|
||||
|
||||
public static SmartEmbedText FromEmbed(IEmbed eb, string plainText = null)
|
||||
|
@@ -10,7 +10,7 @@ public sealed record SmartPlainText : SmartText
|
||||
}
|
||||
|
||||
public static implicit operator SmartPlainText(string input)
|
||||
=> new SmartPlainText(input);
|
||||
=> new(input);
|
||||
|
||||
public static implicit operator string(SmartPlainText input)
|
||||
=> input.Text;
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
public class PermissionAction
|
||||
{
|
||||
public static PermissionAction Enable => new PermissionAction(true);
|
||||
public static PermissionAction Disable => new PermissionAction(false);
|
||||
public static PermissionAction Enable => new(true);
|
||||
public static PermissionAction Disable => new(false);
|
||||
|
||||
public bool Value { get; }
|
||||
|
||||
|
@@ -7,7 +7,7 @@ public class StoopidTime
|
||||
public string Input { get; set; }
|
||||
public TimeSpan Time { get; set; }
|
||||
|
||||
private static readonly Regex _regex = new Regex(
|
||||
private static readonly Regex _regex = new(
|
||||
@"^(?:(?<months>\d)mo)?(?:(?<weeks>\d{1,2})w)?(?:(?<days>\d{1,2})d)?(?:(?<hours>\d{1,4})h)?(?:(?<minutes>\d{1,5})m)?(?:(?<seconds>\d{1,6})s)?$",
|
||||
RegexOptions.Compiled | RegexOptions.Multiline);
|
||||
|
||||
@@ -42,8 +42,8 @@ public class StoopidTime
|
||||
namesAndValues[groupName] = value;
|
||||
output += m.Groups[groupName].Value + " " + groupName + " ";
|
||||
}
|
||||
var ts = new TimeSpan(30 * namesAndValues["months"] +
|
||||
7 * namesAndValues["weeks"] +
|
||||
var ts = new TimeSpan((30 * namesAndValues["months"]) +
|
||||
(7 * namesAndValues["weeks"]) +
|
||||
namesAndValues["days"],
|
||||
namesAndValues["hours"],
|
||||
namesAndValues["minutes"],
|
||||
|
@@ -68,7 +68,7 @@ public sealed class ShmartNumberTypeReader : NadekoTypeReader<ShmartNumber>
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Regex percentRegex = new Regex(@"^((?<num>100|\d{1,2})%)$", RegexOptions.Compiled);
|
||||
private static readonly Regex percentRegex = new(@"^((?<num>100|\d{1,2})%)$", RegexOptions.Compiled);
|
||||
|
||||
private long Cur(ICommandContext ctx)
|
||||
{
|
||||
|
@@ -23,7 +23,7 @@ public class Rgba32Converter : IYamlTypeConverter
|
||||
public void WriteYaml(IEmitter emitter, object value, Type type)
|
||||
{
|
||||
var color = (Rgba32)value;
|
||||
var val = (uint) (color.B << 0 | color.G << 8 | color.R << 16);
|
||||
var val = (uint) ((color.B << 0) | (color.G << 8) | (color.R << 16));
|
||||
emitter.Emit(new Scalar(val.ToString("X6").ToLower()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user