mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
- 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:
@@ -12,5 +12,6 @@ public class AsyncLazy<T> : Lazy<Task<T>>
|
||||
base(() => Task.Run(taskFactory))
|
||||
{ }
|
||||
|
||||
public TaskAwaiter<T> GetAwaiter() { return Value.GetAwaiter(); }
|
||||
public TaskAwaiter<T> GetAwaiter()
|
||||
=> Value.GetAwaiter();
|
||||
}
|
@@ -7,9 +7,7 @@ public sealed class NadekoCommandAttribute : CommandAttribute
|
||||
{
|
||||
public NadekoCommandAttribute([CallerMemberName] string memberName="")
|
||||
: base(CommandNameLoadHelper.GetCommandNameFor(memberName))
|
||||
{
|
||||
this.MethodName = memberName.ToLowerInvariant();
|
||||
}
|
||||
=> this.MethodName = memberName.ToLowerInvariant();
|
||||
|
||||
public string MethodName { get; }
|
||||
}
|
@@ -6,7 +6,5 @@ public sealed class NadekoOptionsAttribute : Attribute
|
||||
public Type OptionType { get; set; }
|
||||
|
||||
public NadekoOptionsAttribute(Type t)
|
||||
{
|
||||
this.OptionType = t;
|
||||
}
|
||||
=> this.OptionType = t;
|
||||
}
|
@@ -1,10 +1,9 @@
|
||||
// License MIT
|
||||
// Source: https://github.com/i3arnon/ConcurrentHashSet
|
||||
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace NadekoBot.Common.Collections;
|
||||
namespace System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a thread-safe hash-based unique collection.
|
||||
@@ -26,7 +25,8 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
private int _budget;
|
||||
private volatile Tables _tables;
|
||||
|
||||
private static int DefaultConcurrencyLevel => PlatformHelper.ProcessorCount;
|
||||
private static int DefaultConcurrencyLevel
|
||||
=> PlatformHelper.ProcessorCount;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of items contained in the <see
|
||||
@@ -99,7 +99,10 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
/// uses the default comparer for the item type.
|
||||
/// </summary>
|
||||
public ConcurrentHashSet()
|
||||
: this(DefaultConcurrencyLevel, DefaultCapacity, true, EqualityComparer<T>.Default)
|
||||
: this(DefaultConcurrencyLevel,
|
||||
DefaultCapacity,
|
||||
true,
|
||||
EqualityComparer<T>.Default)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -119,7 +122,10 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
/// <exception cref="T:System.ArgumentOutOfRangeException"> <paramref name="capacity"/> is less than
|
||||
/// 0.</exception>
|
||||
public ConcurrentHashSet(int concurrencyLevel, int capacity)
|
||||
: this(concurrencyLevel, capacity, false, EqualityComparer<T>.Default)
|
||||
: this(concurrencyLevel,
|
||||
capacity,
|
||||
false,
|
||||
EqualityComparer<T>.Default)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -148,7 +154,10 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
/// implementation to use when comparing items.</param>
|
||||
/// <exception cref="T:System.ArgumentNullException"><paramref name="comparer"/> is a null reference.</exception>
|
||||
public ConcurrentHashSet(IEqualityComparer<T> comparer)
|
||||
: this(DefaultConcurrencyLevel, DefaultCapacity, true, comparer)
|
||||
: this(DefaultConcurrencyLevel,
|
||||
DefaultCapacity,
|
||||
true,
|
||||
comparer)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -199,7 +208,10 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
/// <paramref name="concurrencyLevel"/> is less than 1.
|
||||
/// </exception>
|
||||
public ConcurrentHashSet(int concurrencyLevel, IEnumerable<T> collection, IEqualityComparer<T> comparer)
|
||||
: this(concurrencyLevel, DefaultCapacity, false, comparer)
|
||||
: this(concurrencyLevel,
|
||||
DefaultCapacity,
|
||||
false,
|
||||
comparer)
|
||||
{
|
||||
if (collection is null) throw new ArgumentNullException(nameof(collection));
|
||||
if (comparer is null) throw new ArgumentNullException(nameof(comparer));
|
||||
@@ -225,7 +237,10 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
/// </exception>
|
||||
/// <exception cref="T:System.ArgumentNullException"><paramref name="comparer"/> is a null reference.</exception>
|
||||
public ConcurrentHashSet(int concurrencyLevel, int capacity, IEqualityComparer<T> comparer)
|
||||
: this(concurrencyLevel, capacity, false, comparer)
|
||||
: this(concurrencyLevel,
|
||||
capacity,
|
||||
false,
|
||||
comparer)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -264,8 +279,8 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
/// successfully; false if it already exists.</returns>
|
||||
/// <exception cref="T:System.OverflowException">The <see cref="ConcurrentHashSet{T}"/>
|
||||
/// contains too many items.</exception>
|
||||
public bool Add(T item) =>
|
||||
AddInternal(item, _comparer.GetHashCode(item), true);
|
||||
public bool Add(T item)
|
||||
=> AddInternal(item, _comparer.GetHashCode(item), true);
|
||||
|
||||
/// <summary>
|
||||
/// Removes all items from the <see cref="ConcurrentHashSet{T}"/>.
|
||||
@@ -308,10 +323,12 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
|
||||
while (current != null)
|
||||
{
|
||||
if (hashcode == current.Hashcode && _comparer.Equals(current.Item, item))
|
||||
if (hashcode == current.Hashcode &&
|
||||
_comparer.Equals(current.Item, item))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
current = current.Next;
|
||||
}
|
||||
|
||||
@@ -330,7 +347,11 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
{
|
||||
var tables = _tables;
|
||||
|
||||
GetBucketAndLockNo(hashcode, out var bucketNo, out var lockNo, tables.Buckets.Length, tables.Locks.Length);
|
||||
GetBucketAndLockNo(hashcode,
|
||||
out var bucketNo,
|
||||
out var lockNo,
|
||||
tables.Buckets.Length,
|
||||
tables.Locks.Length);
|
||||
|
||||
lock (tables.Locks[lockNo])
|
||||
{
|
||||
@@ -346,7 +367,8 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
{
|
||||
Debug.Assert((previous is null && current == tables.Buckets[bucketNo]) || previous.Next == current);
|
||||
|
||||
if (hashcode == current.Hashcode && _comparer.Equals(current.Item, item))
|
||||
if (hashcode == current.Hashcode &&
|
||||
_comparer.Equals(current.Item, item))
|
||||
{
|
||||
if (previous is null)
|
||||
{
|
||||
@@ -360,6 +382,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
tables.CountPerLock[lockNo]--;
|
||||
return true;
|
||||
}
|
||||
|
||||
previous = current;
|
||||
}
|
||||
}
|
||||
@@ -368,7 +391,8 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
=> GetEnumerator();
|
||||
|
||||
/// <summary>Returns an enumerator that iterates through the <see
|
||||
/// cref="ConcurrentHashSet{T}"/>.</summary>
|
||||
@@ -396,9 +420,11 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
}
|
||||
}
|
||||
|
||||
void ICollection<T>.Add(T item) => Add(item);
|
||||
void ICollection<T>.Add(T item)
|
||||
=> Add(item);
|
||||
|
||||
bool ICollection<T>.IsReadOnly => false;
|
||||
bool ICollection<T>.IsReadOnly
|
||||
=> false;
|
||||
|
||||
void ICollection<T>.CopyTo(T[] array, int arrayIndex)
|
||||
{
|
||||
@@ -417,9 +443,11 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
count += _tables.CountPerLock[i];
|
||||
}
|
||||
|
||||
if (array.Length - count < arrayIndex || count < 0) //"count" itself or "count + arrayIndex" can overflow
|
||||
if (array.Length - count < arrayIndex ||
|
||||
count < 0) //"count" itself or "count + arrayIndex" can overflow
|
||||
{
|
||||
throw new ArgumentException("The index is equal to or greater than the length of the array, or the number of elements in the set is greater than the available space from index to the end of the destination array.");
|
||||
throw new ArgumentException(
|
||||
"The index is equal to or greater than the length of the array, or the number of elements in the set is greater than the available space from index to the end of the destination array.");
|
||||
}
|
||||
|
||||
CopyToItems(array, arrayIndex);
|
||||
@@ -430,7 +458,8 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
}
|
||||
}
|
||||
|
||||
bool ICollection<T>.Remove(T item) => TryRemove(item);
|
||||
bool ICollection<T>.Remove(T item)
|
||||
=> TryRemove(item);
|
||||
|
||||
private void InitializeFromCollection(IEnumerable<T> collection)
|
||||
{
|
||||
@@ -450,7 +479,11 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
while (true)
|
||||
{
|
||||
var tables = _tables;
|
||||
GetBucketAndLockNo(hashcode, out var bucketNo, out var lockNo, tables.Buckets.Length, tables.Locks.Length);
|
||||
GetBucketAndLockNo(hashcode,
|
||||
out var bucketNo,
|
||||
out var lockNo,
|
||||
tables.Buckets.Length,
|
||||
tables.Locks.Length);
|
||||
|
||||
var resizeDesired = false;
|
||||
var lockTaken = false;
|
||||
@@ -471,10 +504,12 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
for (var current = tables.Buckets[bucketNo]; current != null; current = current.Next)
|
||||
{
|
||||
Debug.Assert((previous is null && current == tables.Buckets[bucketNo]) || previous.Next == current);
|
||||
if (hashcode == current.Hashcode && _comparer.Equals(current.Item, item))
|
||||
if (hashcode == current.Hashcode &&
|
||||
_comparer.Equals(current.Item, item))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
previous = current;
|
||||
}
|
||||
|
||||
@@ -525,7 +560,8 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
return bucketNo;
|
||||
}
|
||||
|
||||
private static void GetBucketAndLockNo(int hashcode, out int bucketNo, out int lockNo, int bucketCount, int lockCount)
|
||||
private static void GetBucketAndLockNo(int hashcode, out int bucketNo, out int lockNo, int bucketCount,
|
||||
int lockCount)
|
||||
{
|
||||
bucketNo = (hashcode & 0x7fffffff) % bucketCount;
|
||||
lockNo = bucketNo % lockCount;
|
||||
@@ -569,6 +605,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
{
|
||||
_budget = int.MaxValue;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -624,7 +661,11 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
if (_growLockArray && tables.Locks.Length < MaxLockNumber)
|
||||
{
|
||||
newLocks = new object[tables.Locks.Length * 2];
|
||||
Array.Copy(tables.Locks, 0, newLocks, 0, tables.Locks.Length);
|
||||
Array.Copy(tables.Locks,
|
||||
0,
|
||||
newLocks,
|
||||
0,
|
||||
tables.Locks.Length);
|
||||
for (var i = tables.Locks.Length; i < newLocks.Length; i++)
|
||||
{
|
||||
newLocks[i] = new();
|
||||
@@ -641,7 +682,11 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
while (current != null)
|
||||
{
|
||||
var next = current.Next;
|
||||
GetBucketAndLockNo(current.Hashcode, out var newBucketNo, out var newLockNo, newBuckets.Length, newLocks.Length);
|
||||
GetBucketAndLockNo(current.Hashcode,
|
||||
out var newBucketNo,
|
||||
out var newLockNo,
|
||||
newBuckets.Length,
|
||||
newLocks.Length);
|
||||
|
||||
newBuckets[newBucketNo] = new(current.Item, current.Hashcode, newBuckets[newBucketNo]);
|
||||
|
||||
@@ -676,6 +721,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
if (this.TryRemove(elem))
|
||||
removed++;
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
|
@@ -13,10 +13,8 @@ public class IndexedCollection<T> : IList<T> where T : class, IIndexed
|
||||
public int IndexOf(T item) => item.Index;
|
||||
|
||||
public IndexedCollection()
|
||||
{
|
||||
Source = new();
|
||||
}
|
||||
|
||||
=> Source = new();
|
||||
|
||||
public IndexedCollection(IEnumerable<T> source)
|
||||
{
|
||||
lock (_locker)
|
||||
@@ -125,7 +123,7 @@ public class IndexedCollection<T> : IList<T> where T : class, IIndexed
|
||||
|
||||
public virtual T this[int index]
|
||||
{
|
||||
get { return Source[index]; }
|
||||
get => Source[index];
|
||||
set
|
||||
{
|
||||
lock (_locker)
|
||||
|
@@ -8,25 +8,17 @@ namespace NadekoBot.Common.JsonConverters;
|
||||
public class Rgba32Converter : JsonConverter<Rgba32>
|
||||
{
|
||||
public override Rgba32 Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
return Rgba32.ParseHex(reader.GetString());
|
||||
}
|
||||
=> Rgba32.ParseHex(reader.GetString());
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Rgba32 value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.ToHex());
|
||||
}
|
||||
=> writer.WriteStringValue(value.ToHex());
|
||||
}
|
||||
|
||||
public class CultureInfoConverter : JsonConverter<CultureInfo>
|
||||
{
|
||||
public override CultureInfo Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
return new(reader.GetString());
|
||||
}
|
||||
=> new(reader.GetString());
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, CultureInfo value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.Name);
|
||||
}
|
||||
=> writer.WriteStringValue(value.Name);
|
||||
}
|
@@ -90,7 +90,5 @@ public readonly struct kwum : IEquatable<kwum>
|
||||
=> other == this;
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return _value.GetHashCode();
|
||||
}
|
||||
=> _value.GetHashCode();
|
||||
}
|
@@ -7,10 +7,8 @@ public class LoginErrorHandler
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Handle(Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "A fatal error has occurred while attempting to connect to Discord");
|
||||
}
|
||||
|
||||
=> Log.Fatal(ex, "A fatal error has occurred while attempting to connect to Discord");
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Handle(HttpException ex)
|
||||
{
|
||||
|
@@ -22,10 +22,8 @@ public abstract class NadekoModule : ModuleBase
|
||||
}
|
||||
|
||||
protected override void BeforeExecute(CommandInfo cmd)
|
||||
{
|
||||
_cultureInfo = Localization.GetCultureInfo(ctx.Guild?.Id);
|
||||
}
|
||||
|
||||
=> _cultureInfo = Localization.GetCultureInfo(ctx.Guild?.Id);
|
||||
|
||||
protected string GetText(in LocStr data) =>
|
||||
Strings.GetText(data, _cultureInfo);
|
||||
|
||||
|
@@ -7,9 +7,7 @@ public class NadekoRandom : Random
|
||||
private readonly RandomNumberGenerator _rng;
|
||||
|
||||
public NadekoRandom() : base()
|
||||
{
|
||||
_rng = RandomNumberGenerator.Create();
|
||||
}
|
||||
=> _rng = RandomNumberGenerator.Create();
|
||||
|
||||
public override int Next()
|
||||
{
|
||||
@@ -52,9 +50,7 @@ public class NadekoRandom : Random
|
||||
}
|
||||
|
||||
public override void NextBytes(byte[] buffer)
|
||||
{
|
||||
_rng.GetBytes(buffer);
|
||||
}
|
||||
=> _rng.GetBytes(buffer);
|
||||
|
||||
protected override double Sample()
|
||||
{
|
||||
|
@@ -5,9 +5,7 @@ public readonly struct TypedKey<TData>
|
||||
public readonly string Key;
|
||||
|
||||
public TypedKey(in string key)
|
||||
{
|
||||
Key = key;
|
||||
}
|
||||
=> Key = key;
|
||||
|
||||
public static implicit operator TypedKey<TData>(in string input)
|
||||
=> new(input);
|
||||
|
@@ -10,17 +10,13 @@ public class ReplacementBuilder
|
||||
private readonly ConcurrentDictionary<Regex, Func<Match, string>> _regex = new();
|
||||
|
||||
public ReplacementBuilder()
|
||||
{
|
||||
WithRngRegex();
|
||||
}
|
||||
=> WithRngRegex();
|
||||
|
||||
public ReplacementBuilder WithDefault(IUser usr, IMessageChannel ch, SocketGuild g, DiscordSocketClient client)
|
||||
{
|
||||
return this.WithUser(usr)
|
||||
=> this.WithUser(usr)
|
||||
.WithChannel(ch)
|
||||
.WithServer(client, g)
|
||||
.WithClient(client);
|
||||
}
|
||||
|
||||
public ReplacementBuilder WithDefault(ICommandContext ctx) =>
|
||||
WithDefault(ctx.User, ctx.Channel, ctx.Guild as SocketGuild, (DiscordSocketClient)ctx.Client);
|
||||
@@ -139,9 +135,7 @@ public class ReplacementBuilder
|
||||
}
|
||||
|
||||
public Replacer Build()
|
||||
{
|
||||
return new(_reps.Select(x => (x.Key, x.Value)).ToArray(), _regex.Select(x => (x.Key, x.Value)).ToArray());
|
||||
}
|
||||
=> new(_reps.Select(x => (x.Key, x.Value)).ToArray(), _regex.Select(x => (x.Key, x.Value)).ToArray());
|
||||
|
||||
public ReplacementBuilder WithProviders(IEnumerable<IPlaceholderProvider> phProviders)
|
||||
{
|
||||
|
@@ -12,49 +12,31 @@ public struct ShmartNumber : IEquatable<ShmartNumber>
|
||||
}
|
||||
|
||||
public static implicit operator ShmartNumber(long num)
|
||||
{
|
||||
return new(num);
|
||||
}
|
||||
=> new(num);
|
||||
|
||||
public static implicit operator long(ShmartNumber num)
|
||||
{
|
||||
return num.Value;
|
||||
}
|
||||
=> num.Value;
|
||||
|
||||
public static implicit operator ShmartNumber(int num)
|
||||
{
|
||||
return new(num);
|
||||
}
|
||||
=> new(num);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value.ToString();
|
||||
}
|
||||
=> Value.ToString();
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is ShmartNumber sn
|
||||
=> obj is ShmartNumber sn
|
||||
? Equals(sn)
|
||||
: false;
|
||||
}
|
||||
|
||||
public bool Equals(ShmartNumber other)
|
||||
{
|
||||
return other.Value == Value;
|
||||
}
|
||||
=> other.Value == Value;
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Value.GetHashCode() ^ Input.GetHashCode(StringComparison.InvariantCulture);
|
||||
}
|
||||
=> Value.GetHashCode() ^ Input.GetHashCode(StringComparison.InvariantCulture);
|
||||
|
||||
public static bool operator ==(ShmartNumber left, ShmartNumber right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
=> left.Equals(right);
|
||||
|
||||
public static bool operator !=(ShmartNumber left, ShmartNumber right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
=> !(left == right);
|
||||
}
|
@@ -5,9 +5,7 @@ public sealed record SmartPlainText : SmartText
|
||||
public string Text { get; init; }
|
||||
|
||||
public SmartPlainText(string text)
|
||||
{
|
||||
Text = text;
|
||||
}
|
||||
=> Text = text;
|
||||
|
||||
public static implicit operator SmartPlainText(string input)
|
||||
=> new(input);
|
||||
@@ -16,7 +14,5 @@ public sealed record SmartPlainText : SmartText
|
||||
=> input.Text;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Text;
|
||||
}
|
||||
=> Text;
|
||||
}
|
@@ -20,7 +20,7 @@ public sealed class CommandTypeReader : NadekoTypeReader<CommandInfo>
|
||||
if (!input.StartsWith(prefix.ToUpperInvariant(), StringComparison.InvariantCulture))
|
||||
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "No such command found."));
|
||||
|
||||
input = input.Substring(prefix.Length);
|
||||
input = input[prefix.Length..];
|
||||
|
||||
var cmd = _cmds.Commands.FirstOrDefault(c => c.Aliases.Select(a => a.ToUpperInvariant()).Contains(input));
|
||||
if (cmd is null)
|
||||
|
@@ -7,10 +7,8 @@ public sealed class GuildDateTimeTypeReader : NadekoTypeReader<GuildDateTime>
|
||||
private readonly GuildTimezoneService _gts;
|
||||
|
||||
public GuildDateTimeTypeReader(GuildTimezoneService gts)
|
||||
{
|
||||
_gts = gts;
|
||||
}
|
||||
|
||||
=> _gts = gts;
|
||||
|
||||
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input)
|
||||
{
|
||||
var gdt = Parse(context.Guild.Id, input);
|
||||
|
@@ -5,9 +5,7 @@ public sealed class GuildTypeReader : NadekoTypeReader<IGuild>
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
public GuildTypeReader(DiscordSocketClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
=> _client = client;
|
||||
|
||||
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input)
|
||||
{
|
||||
|
@@ -14,7 +14,5 @@ public sealed class KwumTypeReader : NadekoTypeReader<kwum>
|
||||
public sealed class SmartTextTypeReader : NadekoTypeReader<SmartText>
|
||||
{
|
||||
public override Task<TypeReaderResult> ReadAsync(ICommandContext ctx, string input)
|
||||
{
|
||||
return Task.FromResult(TypeReaderResult.FromSuccess(SmartText.CreateFrom(input)));
|
||||
}
|
||||
=> Task.FromResult(TypeReaderResult.FromSuccess(SmartText.CreateFrom(input)));
|
||||
}
|
@@ -8,9 +8,7 @@ public class PermissionAction
|
||||
public bool Value { get; }
|
||||
|
||||
public PermissionAction(bool value)
|
||||
{
|
||||
this.Value = value;
|
||||
}
|
||||
=> this.Value = value;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
|
@@ -5,9 +5,7 @@ public sealed class ModuleTypeReader : NadekoTypeReader<ModuleInfo>
|
||||
private readonly CommandService _cmds;
|
||||
|
||||
public ModuleTypeReader(CommandService cmds)
|
||||
{
|
||||
_cmds = cmds;
|
||||
}
|
||||
=> _cmds = cmds;
|
||||
|
||||
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input)
|
||||
{
|
||||
@@ -25,9 +23,7 @@ public sealed class ModuleOrCrTypeReader : NadekoTypeReader<ModuleOrCrInfo>
|
||||
private readonly CommandService _cmds;
|
||||
|
||||
public ModuleOrCrTypeReader(CommandService cmds)
|
||||
{
|
||||
_cmds = cmds;
|
||||
}
|
||||
=> _cmds = cmds;
|
||||
|
||||
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input)
|
||||
{
|
||||
|
@@ -5,7 +5,5 @@ public class CommentAttribute : Attribute
|
||||
public string Comment { get; }
|
||||
|
||||
public CommentAttribute(string comment)
|
||||
{
|
||||
Comment = comment;
|
||||
}
|
||||
=> Comment = comment;
|
||||
}
|
@@ -9,16 +9,12 @@ public class CommentGatheringTypeInspector : TypeInspectorSkeleton
|
||||
private readonly ITypeInspector innerTypeDescriptor;
|
||||
|
||||
public CommentGatheringTypeInspector(ITypeInspector innerTypeDescriptor)
|
||||
{
|
||||
this.innerTypeDescriptor = innerTypeDescriptor ?? throw new ArgumentNullException("innerTypeDescriptor");
|
||||
}
|
||||
=> this.innerTypeDescriptor = innerTypeDescriptor ?? throw new ArgumentNullException("innerTypeDescriptor");
|
||||
|
||||
public override IEnumerable<IPropertyDescriptor> GetProperties(Type type, object container)
|
||||
{
|
||||
return innerTypeDescriptor
|
||||
=> innerTypeDescriptor
|
||||
.GetProperties(type, container)
|
||||
.Select(d => new CommentsPropertyDescriptor(d));
|
||||
}
|
||||
|
||||
private sealed class CommentsPropertyDescriptor : IPropertyDescriptor
|
||||
{
|
||||
@@ -32,31 +28,29 @@ public class CommentGatheringTypeInspector : TypeInspectorSkeleton
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public Type Type { get { return baseDescriptor.Type; } }
|
||||
public Type Type
|
||||
=> baseDescriptor.Type;
|
||||
|
||||
public Type TypeOverride {
|
||||
get { return baseDescriptor.TypeOverride; }
|
||||
set { baseDescriptor.TypeOverride = value; }
|
||||
get => baseDescriptor.TypeOverride;
|
||||
set => baseDescriptor.TypeOverride = value;
|
||||
}
|
||||
|
||||
public int Order { get; set; }
|
||||
|
||||
public ScalarStyle ScalarStyle {
|
||||
get { return baseDescriptor.ScalarStyle; }
|
||||
set { baseDescriptor.ScalarStyle = value; }
|
||||
get => baseDescriptor.ScalarStyle;
|
||||
set => baseDescriptor.ScalarStyle = value;
|
||||
}
|
||||
|
||||
public bool CanWrite { get { return baseDescriptor.CanWrite; } }
|
||||
public bool CanWrite
|
||||
=> baseDescriptor.CanWrite;
|
||||
|
||||
public void Write(object target, object value)
|
||||
{
|
||||
baseDescriptor.Write(target, value);
|
||||
}
|
||||
=> baseDescriptor.Write(target, value);
|
||||
|
||||
public T GetCustomAttribute<T>() where T : Attribute
|
||||
{
|
||||
return baseDescriptor.GetCustomAttribute<T>();
|
||||
}
|
||||
=> baseDescriptor.GetCustomAttribute<T>();
|
||||
|
||||
public IObjectDescriptor Read(object target)
|
||||
{
|
||||
|
@@ -15,8 +15,15 @@ public sealed class CommentsObjectDescriptor : IObjectDescriptor
|
||||
|
||||
public string Comment { get; private set; }
|
||||
|
||||
public object Value { get { return innerDescriptor.Value; } }
|
||||
public Type Type { get { return innerDescriptor.Type; } }
|
||||
public Type StaticType { get { return innerDescriptor.StaticType; } }
|
||||
public ScalarStyle ScalarStyle { get { return innerDescriptor.ScalarStyle; } }
|
||||
public object Value
|
||||
=> innerDescriptor.Value;
|
||||
|
||||
public Type Type
|
||||
=> innerDescriptor.Type;
|
||||
|
||||
public Type StaticType
|
||||
=> innerDescriptor.StaticType;
|
||||
|
||||
public ScalarStyle ScalarStyle
|
||||
=> innerDescriptor.ScalarStyle;
|
||||
}
|
@@ -9,9 +9,7 @@ namespace NadekoBot.Common.Yml;
|
||||
public class Rgba32Converter : IYamlTypeConverter
|
||||
{
|
||||
public bool Accepts(Type type)
|
||||
{
|
||||
return type == typeof(Rgba32);
|
||||
}
|
||||
=> type == typeof(Rgba32);
|
||||
|
||||
public object ReadYaml(IParser parser, Type type)
|
||||
{
|
||||
@@ -31,9 +29,7 @@ public class Rgba32Converter : IYamlTypeConverter
|
||||
public class CultureInfoConverter : IYamlTypeConverter
|
||||
{
|
||||
public bool Accepts(Type type)
|
||||
{
|
||||
return type == typeof(CultureInfo);
|
||||
}
|
||||
=> type == typeof(CultureInfo);
|
||||
|
||||
public object ReadYaml(IParser parser, Type type)
|
||||
{
|
||||
|
@@ -7,9 +7,7 @@ namespace NadekoBot.Common.Yml;
|
||||
public class UriConverter : IYamlTypeConverter
|
||||
{
|
||||
public bool Accepts(Type type)
|
||||
{
|
||||
return type == typeof(Uri);
|
||||
}
|
||||
=> type == typeof(Uri);
|
||||
|
||||
public object ReadYaml(IParser parser, Type type)
|
||||
{
|
||||
|
@@ -26,7 +26,7 @@ public class YamlHelper
|
||||
|
||||
// Check the value and write the character.
|
||||
|
||||
if (character is >= 0xD800 and <= 0xDFFF || character > 0x10FFFF)
|
||||
if (character is >= 0xD800 and <= 0xDFFF or > 0x10FFFF)
|
||||
{
|
||||
return point;
|
||||
}
|
||||
@@ -35,13 +35,8 @@ public class YamlHelper
|
||||
}
|
||||
|
||||
public static bool IsHex(char c)
|
||||
{
|
||||
return
|
||||
c is >= '0' and <= '9' ||
|
||||
c is >= 'A' and <= 'F' ||
|
||||
c is >= 'a' and <= 'f';
|
||||
}
|
||||
|
||||
=> c is >= '0' and <= '9' or >= 'A' and <= 'F' or >= 'a' and <= 'f';
|
||||
|
||||
public static int AsHex(char c)
|
||||
{
|
||||
if (c <= '9')
|
||||
|
Reference in New Issue
Block a user