More target-typed new and redundant paranthesis cleanup

This commit is contained in:
Kwoth
2021-12-20 00:33:11 +01:00
parent 345a9e9524
commit 1b2017024c
152 changed files with 573 additions and 580 deletions

View File

@@ -74,19 +74,19 @@ public partial class Utility
await ReplyConfirmLocalizedAsync(strs.alias_removed(Format.Code(trigger))).ConfigureAwait(false);
return;
}
_service.AliasMaps.AddOrUpdate(ctx.Guild.Id, (_) =>
_service.AliasMaps.AddOrUpdate(ctx.Guild.Id, _ =>
{
using (var uow = _db.GetDbContext())
{
var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
config.CommandAliases.Add(new CommandAlias()
config.CommandAliases.Add(new()
{
Mapping = mapping,
Trigger = trigger
});
uow.SaveChanges();
}
return new ConcurrentDictionary<string, string>(new Dictionary<string, string>() {
return new(new Dictionary<string, string>() {
{trigger.Trim().ToLowerInvariant(), mapping.ToLowerInvariant() },
});
}, (_, map) =>
@@ -131,7 +131,7 @@ public partial class Utility
var arr = maps.ToArray();
await ctx.SendPaginatedConfirmAsync(page, (curPage) =>
await ctx.SendPaginatedConfirmAsync(page, curPage =>
{
return _eb.Create().WithOkColor()
.WithTitle(GetText(strs.alias_list))

View File

@@ -42,7 +42,7 @@ public partial class Utility
var invites = await channel.GetInvitesAsync().ConfigureAwait(false);
await ctx.SendPaginatedConfirmAsync(page, (cur) =>
await ctx.SendPaginatedConfirmAsync(page, cur =>
{
var i = 1;
var invs = invites

View File

@@ -188,7 +188,7 @@ public partial class Utility
Quote q;
using (var uow = _db.GetDbContext())
{
uow.Quotes.Add(q = new Quote
uow.Quotes.Add(q = new()
{
AuthorId = ctx.Message.Author.Id,
AuthorName = ctx.Message.Author.Username,

View File

@@ -32,7 +32,7 @@ public class CommandMapService : IInputTransformer, INService
.Where(x => guildIds.Contains(x.GuildId))
.ToList();
AliasMaps = new ConcurrentDictionary<ulong, ConcurrentDictionary<string, string>>(configs
AliasMaps = new(configs
.ToDictionary(
x => x.GuildId,
x => new ConcurrentDictionary<string, string>(x.CommandAliases
@@ -88,7 +88,7 @@ public class CommandMapService : IInputTransformer, INService
var _ = Task.Run(async () =>
{
await Task.Delay(1500).ConfigureAwait(false);
await toDelete.DeleteAsync(new RequestOptions()
await toDelete.DeleteAsync(new()
{
RetryMode = RetryMode.AlwaysRetry
}).ConfigureAwait(false);

View File

@@ -33,7 +33,7 @@ public class ConverterService : INService
if (client.ShardId == 0)
{
_currencyUpdater = new Timer(async (shouldLoad) => await UpdateCurrency((bool)shouldLoad).ConfigureAwait(false),
_currencyUpdater = new(async shouldLoad => await UpdateCurrency((bool)shouldLoad).ConfigureAwait(false),
client.ShardId == 0,
TimeSpan.Zero,
_updateInterval);

View File

@@ -55,7 +55,7 @@ public class PatreonRewardsService : INService
_client = client;
if (client.ShardId == 0)
_updater = new Timer(async _ => await RefreshPledges(_credsProvider.GetCreds()).ConfigureAwait(false),
_updater = new(async _ => await RefreshPledges(_credsProvider.GetCreds()).ConfigureAwait(false),
null, TimeSpan.Zero, Interval);
}
@@ -188,8 +188,8 @@ public class PatreonRewardsService : INService
}
var userData = members.Join(users,
(m) => m.Relationships.User.Data.Id,
(u) => u.Id,
m => m.Relationships.User.Data.Id,
u => u.Id,
(m, u) => new
{
PatreonUserId = m.Relationships.User.Data.Id,
@@ -238,7 +238,7 @@ public class PatreonRewardsService : INService
if (usr is null)
{
users.Add(new RewardedUser()
users.Add(new()
{
PatreonUserId = patreonUserId,
LastReward = now,

View File

@@ -137,7 +137,7 @@ public class RemindService : INService
0
);
obj = new RemindObject()
obj = new()
{
Time = ts,
What = what

View File

@@ -42,11 +42,11 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
.AsNoTracking()
.ToList();
_noRedundant = new ConcurrentHashSet<int>(shardRepeaters
_noRedundant = new(shardRepeaters
.Where(x => x.NoRedundant)
.Select(x => x.Id));
_repeaterQueue = new LinkedList<RunningRepeater>(shardRepeaters
_repeaterQueue = new(shardRepeaters
.Select(rep => new RunningRepeater(rep))
.OrderBy(x => x.NextTime));
}
@@ -245,7 +245,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
}
}
if (repeater.LastMessageId is ulong lastMessageId)
if (repeater.LastMessageId is { } lastMessageId)
{
try
{
@@ -318,7 +318,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
await uow.Repeaters
.AsQueryable()
.Where(x => x.Id == repeaterId)
.UpdateAsync(rep => new Repeater()
.UpdateAsync(rep => new()
{
LastMessageId = lastMsgId
});

View File

@@ -26,7 +26,7 @@ public class StreamRoleService : INService
guildSettings = bot.AllGuildConfigs
.ToDictionary(x => x.GuildId, x => x.StreamRole)
.Where(x => x.Value != null && x.Value.Enabled)
.Where(x => x.Value is { Enabled: true })
.ToConcurrent();
_client.GuildMemberUpdated += Client_GuildMemberUpdated;
@@ -197,7 +197,7 @@ public class StreamRoleService : INService
foreach (var usr in await fromRole.GetMembersAsync().ConfigureAwait(false))
{
if (usr is IGuildUser x)
if (usr is { } x)
await RescanUser(x, setting, addRole).ConfigureAwait(false);
}
}
@@ -304,7 +304,7 @@ public class StreamRoleService : INService
var users = await guild.GetUsersAsync(CacheMode.CacheOnly).ConfigureAwait(false);
foreach (var usr in users.Where(x => x.RoleIds.Contains(setting.FromRoleId) || x.RoleIds.Contains(addRole.Id)))
{
if (usr is IGuildUser x)
if (usr is { } x)
await RescanUser(x, setting, addRole).ConfigureAwait(false);
}
}
@@ -312,6 +312,6 @@ public class StreamRoleService : INService
private void UpdateCache(ulong guildId, StreamRoleSettings setting)
{
guildSettings.AddOrUpdate(guildId, (key) => setting, (key, old) => setting);
guildSettings.AddOrUpdate(guildId, key => setting, (key, old) => setting);
}
}

View File

@@ -24,7 +24,7 @@ public class VerboseErrorsService : INService
_ch.CommandErrored += LogVerboseError;
guildsEnabled = new ConcurrentHashSet<ulong>(bot
guildsEnabled = new(bot
.AllGuildConfigs
.Where(x => x.VerboseErrors)
.Select(x => x.GuildId));

View File

@@ -113,7 +113,7 @@ public partial class Utility : NadekoModule
.Select(u => $"`{u.Id, 18}` {u}")
.ToArray();
await ctx.SendPaginatedConfirmAsync(page, (cur) =>
await ctx.SendPaginatedConfirmAsync(page, cur =>
{
var pageUsers = roleUsers.Skip(cur * 20)
.Take(20)