mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
More target-typed new and redundant paranthesis cleanup
This commit is contained in:
@@ -12,12 +12,12 @@ public class UserPermAttribute : PreconditionAttribute
|
||||
|
||||
public UserPermAttribute(GuildPerm permission)
|
||||
{
|
||||
UserPermissionAttribute = new RequireUserPermissionAttribute((GuildPermission)permission);
|
||||
UserPermissionAttribute = new((GuildPermission)permission);
|
||||
}
|
||||
|
||||
public UserPermAttribute(ChannelPerm permission)
|
||||
{
|
||||
UserPermissionAttribute = new RequireUserPermissionAttribute((ChannelPermission)permission);
|
||||
UserPermissionAttribute = new((ChannelPermission)permission);
|
||||
}
|
||||
|
||||
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
|
||||
|
@@ -245,12 +245,12 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
var locks = new object[concurrencyLevel];
|
||||
for (var i = 0; i < locks.Length; i++)
|
||||
{
|
||||
locks[i] = new object();
|
||||
locks[i] = new();
|
||||
}
|
||||
|
||||
var countPerLock = new int[locks.Length];
|
||||
var buckets = new Node[capacity];
|
||||
_tables = new Tables(buckets, locks, countPerLock);
|
||||
_tables = new(buckets, locks, countPerLock);
|
||||
|
||||
_growLockArray = growLockArray;
|
||||
_budget = buckets.Length / locks.Length;
|
||||
@@ -480,7 +480,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
}
|
||||
|
||||
// The item was not found in the bucket. Insert the new item.
|
||||
Volatile.Write(ref tables.Buckets[bucketNo], new Node(item, hashcode, tables.Buckets[bucketNo]));
|
||||
Volatile.Write(ref tables.Buckets[bucketNo], new(item, hashcode, tables.Buckets[bucketNo]));
|
||||
checked
|
||||
{
|
||||
tables.CountPerLock[lockNo]++;
|
||||
@@ -628,7 +628,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
Array.Copy(tables.Locks, 0, newLocks, 0, tables.Locks.Length);
|
||||
for (var i = tables.Locks.Length; i < newLocks.Length; i++)
|
||||
{
|
||||
newLocks[i] = new object();
|
||||
newLocks[i] = new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -644,7 +644,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
var next = current.Next;
|
||||
GetBucketAndLockNo(current.Hashcode, out var newBucketNo, out var newLockNo, newBuckets.Length, newLocks.Length);
|
||||
|
||||
newBuckets[newBucketNo] = new Node(current.Item, current.Hashcode, newBuckets[newBucketNo]);
|
||||
newBuckets[newBucketNo] = new(current.Item, current.Hashcode, newBuckets[newBucketNo]);
|
||||
|
||||
checked
|
||||
{
|
||||
@@ -659,7 +659,7 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
|
||||
_budget = Math.Max(1, newBuckets.Length / newLocks.Length);
|
||||
|
||||
// Replace tables with the new versions
|
||||
_tables = new Tables(newBuckets, newLocks, newCountPerLock);
|
||||
_tables = new(newBuckets, newLocks, newCountPerLock);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@@ -14,7 +14,7 @@ public class IndexedCollection<T> : IList<T> where T : class, IIndexed
|
||||
|
||||
public IndexedCollection()
|
||||
{
|
||||
Source = new List<T>();
|
||||
Source = new();
|
||||
}
|
||||
|
||||
public IndexedCollection(IEnumerable<T> source)
|
||||
|
@@ -95,7 +95,7 @@ See RotatingStatuses submodule in Administration.")]
|
||||
{
|
||||
var color = new ColorConfig();
|
||||
Color = color;
|
||||
DefaultLocale = new CultureInfo("en-US");
|
||||
DefaultLocale = new("en-US");
|
||||
ConsoleOutputType = ConsoleOutputType.Normal;
|
||||
ForwardMessages = false;
|
||||
ForwardToAllOwners = false;
|
||||
@@ -130,7 +130,7 @@ See RotatingStatuses submodule in Administration.")]
|
||||
Prefix = ".";
|
||||
RotateStatuses = false;
|
||||
GroupGreets = false;
|
||||
DmHelpTextKeywords = new List<string>()
|
||||
DmHelpTextKeywords = new()
|
||||
{
|
||||
"help",
|
||||
"commands",
|
||||
@@ -149,8 +149,8 @@ public sealed partial class BlockedConfig
|
||||
|
||||
public BlockedConfig()
|
||||
{
|
||||
Modules = new HashSet<string>();
|
||||
Commands = new HashSet<string>();
|
||||
Modules = new();
|
||||
Commands = new();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ public class CultureInfoConverter : JsonConverter<CultureInfo>
|
||||
{
|
||||
public override CultureInfo Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
return new CultureInfo(reader.GetString());
|
||||
return new(reader.GetString());
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, CultureInfo value, JsonSerializerOptions options)
|
||||
|
@@ -44,7 +44,7 @@ public readonly struct kwum : IEquatable<kwum>
|
||||
if (!IsValidChar(c))
|
||||
return false;
|
||||
|
||||
value = new kwum(input);
|
||||
value = new(input);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public readonly struct kwum : IEquatable<kwum>
|
||||
chars[--arrSize] = ValidCharacters[(int)rem];
|
||||
}
|
||||
|
||||
return new string(chars);
|
||||
return new(chars);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
|
@@ -16,14 +16,14 @@ public class EventPubSub : IPubSub
|
||||
Dictionary<Delegate, List<Func<object, ValueTask>>> keyActions;
|
||||
if (!_actions.TryGetValue(key.Key, out keyActions))
|
||||
{
|
||||
keyActions = new Dictionary<Delegate, List<Func<object, ValueTask>>>();
|
||||
keyActions = new();
|
||||
_actions[key.Key] = keyActions;
|
||||
}
|
||||
|
||||
List<Func<object, ValueTask>> sameActions;
|
||||
if (!keyActions.TryGetValue(action, out sameActions))
|
||||
{
|
||||
sameActions = new List<Func<object, ValueTask>>();
|
||||
sameActions = new();
|
||||
keyActions[action] = sameActions;
|
||||
}
|
||||
|
||||
|
@@ -66,7 +66,7 @@ public class ReplacementBuilder
|
||||
/*OBSOLETE*/
|
||||
_reps.TryAdd("%sid%", () => g is null ? "DM" : g.Id.ToString());
|
||||
_reps.TryAdd("%server%", () => g is null ? "DM" : g.Name);
|
||||
_reps.TryAdd("%members%", () => g != null && g is SocketGuild sg ? sg.MemberCount.ToString() : "?");
|
||||
_reps.TryAdd("%members%", () => g is { } sg ? sg.MemberCount.ToString() : "?");
|
||||
_reps.TryAdd("%server_time%", () =>
|
||||
{
|
||||
var to = TimeZoneInfo.Local;
|
||||
@@ -83,7 +83,7 @@ public class ReplacementBuilder
|
||||
/*NEW*/
|
||||
_reps.TryAdd("%server.id%", () => g is null ? "DM" : g.Id.ToString());
|
||||
_reps.TryAdd("%server.name%", () => g is null ? "DM" : g.Name);
|
||||
_reps.TryAdd("%server.members%", () => g != null && g is SocketGuild sg ? sg.MemberCount.ToString() : "?");
|
||||
_reps.TryAdd("%server.members%", () => g is { } sg ? sg.MemberCount.ToString() : "?");
|
||||
_reps.TryAdd("%server.boosters%", () => g.PremiumSubscriptionCount.ToString());
|
||||
_reps.TryAdd("%server.boost_level%", () => ((int)g.PremiumTier).ToString());
|
||||
_reps.TryAdd("%server.time%", () =>
|
||||
@@ -120,25 +120,6 @@ public class ReplacementBuilder
|
||||
|
||||
public ReplacementBuilder WithUser(IUser user)
|
||||
{
|
||||
// /*OBSOLETE*/
|
||||
// _reps.TryAdd("%user%", () => user.Mention);
|
||||
// _reps.TryAdd("%userfull%", () => user.ToString());
|
||||
// _reps.TryAdd("%username%", () => user.Username);
|
||||
// _reps.TryAdd("%userdiscrim%", () => user.Discriminator);
|
||||
// _reps.TryAdd("%useravatar%", () => user.RealAvatarUrl()?.ToString());
|
||||
// _reps.TryAdd("%id%", () => user.Id.ToString());
|
||||
// _reps.TryAdd("%uid%", () => user.Id.ToString());
|
||||
// /*NEW*/
|
||||
// _reps.TryAdd("%user.mention%", () => user.Mention);
|
||||
// _reps.TryAdd("%user.fullname%", () => user.ToString());
|
||||
// _reps.TryAdd("%user.name%", () => user.Username);
|
||||
// _reps.TryAdd("%user.discrim%", () => user.Discriminator);
|
||||
// _reps.TryAdd("%user.avatar%", () => user.RealAvatarUrl()?.ToString());
|
||||
// _reps.TryAdd("%user.id%", () => user.Id.ToString());
|
||||
// _reps.TryAdd("%user.created_time%", () => user.CreatedAt.ToString("HH:mm"));
|
||||
// _reps.TryAdd("%user.created_date%", () => user.CreatedAt.ToString("dd.MM.yyyy"));
|
||||
// _reps.TryAdd("%user.joined_time%", () => (user as IGuildUser)?.JoinedAt?.ToString("HH:mm") ?? "-");
|
||||
// _reps.TryAdd("%user.joined_date%", () => (user as IGuildUser)?.JoinedAt?.ToString("dd.MM.yyyy") ?? "-");
|
||||
WithManyUsers(new[] {user});
|
||||
return this;
|
||||
}
|
||||
@@ -171,15 +152,11 @@ public class ReplacementBuilder
|
||||
{
|
||||
/*OBSOLETE*/
|
||||
_reps.TryAdd("%servers%", () => c.Guilds.Count.ToString());
|
||||
#if !GLOBAL_NADEKO
|
||||
_reps.TryAdd("%users%", () => c.Guilds.Sum(g => g.MemberCount).ToString());
|
||||
#endif
|
||||
|
||||
/*NEW*/
|
||||
_reps.TryAdd("%shard.servercount%", () => c.Guilds.Count.ToString());
|
||||
#if !GLOBAL_NADEKO
|
||||
_reps.TryAdd("%shard.servercount%", () => c.Guilds.Count.ToString());S
|
||||
_reps.TryAdd("%shard.usercount%", () => c.Guilds.Sum(g => g.MemberCount).ToString());
|
||||
#endif
|
||||
_reps.TryAdd("%shard.id%", () => c.ShardId.ToString());
|
||||
return this;
|
||||
}
|
||||
@@ -187,7 +164,7 @@ public class ReplacementBuilder
|
||||
public ReplacementBuilder WithRngRegex()
|
||||
{
|
||||
var rng = new NadekoRandom();
|
||||
_regex.TryAdd(rngRegex, (match) =>
|
||||
_regex.TryAdd(rngRegex, match =>
|
||||
{
|
||||
if (!int.TryParse(match.Groups["from"].ToString(), out var from))
|
||||
from = 0;
|
||||
@@ -213,7 +190,7 @@ public class ReplacementBuilder
|
||||
|
||||
public Replacer Build()
|
||||
{
|
||||
return new Replacer(_reps.Select(x => (x.Key, x.Value)).ToArray(), _regex.Select(x => (x.Key, x.Value)).ToArray());
|
||||
return new(_reps.Select(x => (x.Key, x.Value)).ToArray(), _regex.Select(x => (x.Key, x.Value)).ToArray());
|
||||
}
|
||||
|
||||
public ReplacementBuilder WithProviders(IEnumerable<IPlaceholderProvider> phProviders)
|
||||
|
@@ -26,7 +26,7 @@ public class Replacer
|
||||
|
||||
foreach (var item in _regex)
|
||||
{
|
||||
input = item.Regex.Replace(input, (m) => item.Replacement(m));
|
||||
input = item.Regex.Replace(input, m => item.Replacement(m));
|
||||
}
|
||||
|
||||
return input;
|
||||
@@ -45,18 +45,22 @@ public class Replacer
|
||||
|
||||
public SmartEmbedText Replace(SmartEmbedText embedData)
|
||||
{
|
||||
var newEmbedData = new SmartEmbedText();
|
||||
newEmbedData.PlainText = Replace(embedData.PlainText);
|
||||
newEmbedData.Description = Replace(embedData.Description);
|
||||
newEmbedData.Title = Replace(embedData.Title);
|
||||
newEmbedData.Thumbnail = Replace(embedData.Thumbnail);
|
||||
newEmbedData.Image = Replace(embedData.Image);
|
||||
newEmbedData.Url = Replace(embedData.Url);
|
||||
var newEmbedData = new SmartEmbedText
|
||||
{
|
||||
PlainText = Replace(embedData.PlainText),
|
||||
Description = Replace(embedData.Description),
|
||||
Title = Replace(embedData.Title),
|
||||
Thumbnail = Replace(embedData.Thumbnail),
|
||||
Image = Replace(embedData.Image),
|
||||
Url = Replace(embedData.Url)
|
||||
};
|
||||
if (embedData.Author != null)
|
||||
{
|
||||
newEmbedData.Author = new SmartTextEmbedAuthor();
|
||||
newEmbedData.Author.Name = Replace(embedData.Author.Name);
|
||||
newEmbedData.Author.IconUrl = Replace(embedData.Author.IconUrl);
|
||||
newEmbedData.Author = new()
|
||||
{
|
||||
Name = Replace(embedData.Author.Name),
|
||||
IconUrl = Replace(embedData.Author.IconUrl)
|
||||
};
|
||||
}
|
||||
|
||||
if (embedData.Fields != null)
|
||||
@@ -64,10 +68,12 @@ public class Replacer
|
||||
var fields = new List<SmartTextEmbedField>();
|
||||
foreach (var f in embedData.Fields)
|
||||
{
|
||||
var newF = new SmartTextEmbedField();
|
||||
newF.Name = Replace(f.Name);
|
||||
newF.Value = Replace(f.Value);
|
||||
newF.Inline = f.Inline;
|
||||
var newF = new SmartTextEmbedField
|
||||
{
|
||||
Name = Replace(f.Name),
|
||||
Value = Replace(f.Value),
|
||||
Inline = f.Inline
|
||||
};
|
||||
fields.Add(newF);
|
||||
}
|
||||
|
||||
@@ -76,9 +82,11 @@ public class Replacer
|
||||
|
||||
if (embedData.Footer != null)
|
||||
{
|
||||
newEmbedData.Footer = new SmartTextEmbedFooter();
|
||||
newEmbedData.Footer.Text = Replace(embedData.Footer.Text);
|
||||
newEmbedData.Footer.IconUrl = Replace(embedData.Footer.IconUrl);
|
||||
newEmbedData.Footer = new()
|
||||
{
|
||||
Text = Replace(embedData.Footer.Text),
|
||||
IconUrl = Replace(embedData.Footer.IconUrl)
|
||||
};
|
||||
}
|
||||
|
||||
newEmbedData.Color = embedData.Color;
|
||||
|
@@ -13,7 +13,7 @@ public struct ShmartNumber : IEquatable<ShmartNumber>
|
||||
|
||||
public static implicit operator ShmartNumber(long num)
|
||||
{
|
||||
return new ShmartNumber(num);
|
||||
return new(num);
|
||||
}
|
||||
|
||||
public static implicit operator long(ShmartNumber num)
|
||||
@@ -23,7 +23,7 @@ public struct ShmartNumber : IEquatable<ShmartNumber>
|
||||
|
||||
public static implicit operator ShmartNumber(int num)
|
||||
{
|
||||
return new ShmartNumber(num);
|
||||
return new(num);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
@@ -25,33 +25,34 @@ public sealed record SmartEmbedText : SmartText
|
||||
!string.IsNullOrWhiteSpace(Thumbnail) ||
|
||||
!string.IsNullOrWhiteSpace(Image) ||
|
||||
(Footer != null && (!string.IsNullOrWhiteSpace(Footer.Text) || !string.IsNullOrWhiteSpace(Footer.IconUrl))) ||
|
||||
(Fields != null && Fields.Length > 0);
|
||||
Fields is { Length: > 0 };
|
||||
|
||||
public static SmartEmbedText FromEmbed(IEmbed eb, string plainText = null)
|
||||
{
|
||||
var set = new SmartEmbedText();
|
||||
|
||||
set.PlainText = plainText;
|
||||
set.Title = eb.Title;
|
||||
set.Description = eb.Description;
|
||||
set.Url = eb.Url;
|
||||
set.Thumbnail = eb.Thumbnail?.Url;
|
||||
set.Image = eb.Image?.Url;
|
||||
set.Author = eb.Author is EmbedAuthor ea
|
||||
? new()
|
||||
{
|
||||
Name = ea.Name,
|
||||
Url = ea.Url,
|
||||
IconUrl = ea.IconUrl
|
||||
}
|
||||
: null;
|
||||
set.Footer = eb.Footer is EmbedFooter ef
|
||||
? new()
|
||||
{
|
||||
Text = ef.Text,
|
||||
IconUrl = ef.IconUrl
|
||||
}
|
||||
: null;
|
||||
var set = new SmartEmbedText
|
||||
{
|
||||
PlainText = plainText,
|
||||
Title = eb.Title,
|
||||
Description = eb.Description,
|
||||
Url = eb.Url,
|
||||
Thumbnail = eb.Thumbnail?.Url,
|
||||
Image = eb.Image?.Url,
|
||||
Author = eb.Author is { } ea
|
||||
? new()
|
||||
{
|
||||
Name = ea.Name,
|
||||
Url = ea.Url,
|
||||
IconUrl = ea.IconUrl
|
||||
}
|
||||
: null,
|
||||
Footer = eb.Footer is { } ef
|
||||
? new()
|
||||
{
|
||||
Text = ef.Text,
|
||||
IconUrl = ef.IconUrl
|
||||
}
|
||||
: null
|
||||
};
|
||||
|
||||
if (eb.Fields.Length > 0)
|
||||
set.Fields = eb
|
||||
@@ -122,7 +123,7 @@ public sealed record SmartEmbedText : SmartText
|
||||
|
||||
public void NormalizeFields()
|
||||
{
|
||||
if (Fields != null && Fields.Length > 0)
|
||||
if (Fields is { Length: > 0 })
|
||||
{
|
||||
foreach (var f in Fields)
|
||||
{
|
||||
|
@@ -53,7 +53,7 @@ public class StoopidTime
|
||||
throw new ArgumentException("Time is too long.");
|
||||
}
|
||||
|
||||
return new StoopidTime()
|
||||
return new()
|
||||
{
|
||||
Input = input,
|
||||
Time = ts,
|
||||
|
@@ -19,7 +19,7 @@ public class MultilineScalarFlowStyleEmitter : ChainedEventEmitter
|
||||
{
|
||||
var isMultiLine = value.IndexOfAny(new char[] { '\r', '\n', '\x85', '\x2028', '\x2029' }) >= 0;
|
||||
if (isMultiLine)
|
||||
eventInfo = new ScalarEventInfo(eventInfo.Source)
|
||||
eventInfo = new(eventInfo.Source)
|
||||
{
|
||||
Style = ScalarStyle.Literal,
|
||||
};
|
||||
|
@@ -26,7 +26,7 @@ public class YamlHelper
|
||||
|
||||
// Check the value and write the character.
|
||||
|
||||
if (character >= 0xD800 && character <= 0xDFFF || character > 0x10FFFF)
|
||||
if (character is >= 0xD800 and <= 0xDFFF || character > 0x10FFFF)
|
||||
{
|
||||
return point;
|
||||
}
|
||||
@@ -37,9 +37,9 @@ public class YamlHelper
|
||||
public static bool IsHex(char c)
|
||||
{
|
||||
return
|
||||
(c >= '0' && c <= '9') ||
|
||||
(c >= 'A' && c <= 'F') ||
|
||||
(c >= 'a' && c <= 'f');
|
||||
c is >= '0' and <= '9' ||
|
||||
c is >= 'A' and <= 'F' ||
|
||||
c is >= 'a' and <= 'f';
|
||||
}
|
||||
|
||||
public static int AsHex(char c)
|
||||
|
Reference in New Issue
Block a user