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

@@ -299,7 +299,7 @@ public partial class Administration : NadekoModule<AdministrationService>
[RequireContext(ContextType.Guild)]
public async Task Delete(ITextChannel channel, ulong messageId, StoopidTime time = null)
{
await InternalMessageAction(channel, messageId, time, (msg) => msg.DeleteAsync());
await InternalMessageAction(channel, messageId, time, msg => msg.DeleteAsync());
}
private async Task InternalMessageAction(ITextChannel channel, ulong messageId, StoopidTime time,

View File

@@ -14,7 +14,7 @@ public sealed class UserSpamStats : IDisposable
public UserSpamStats(IUserMessage msg)
{
LastMessage = msg.Content.ToUpperInvariant();
timers = new ConcurrentQueue<Timer>();
timers = new();
ApplyNextMessage(msg);
}
@@ -31,7 +31,7 @@ public sealed class UserSpamStats : IDisposable
while (timers.TryDequeue(out var old))
old.Change(Timeout.Infinite, Timeout.Infinite);
}
var t = new Timer((_) => {
var t = new Timer(_ => {
if (timers.TryDequeue(out var old))
old.Change(Timeout.Infinite, Timeout.Infinite);
}, null, TimeSpan.FromMinutes(30), TimeSpan.FromMinutes(30));

View File

@@ -44,7 +44,7 @@ namespace NadekoBot.Modules.Administration
{
var result = _service.SelectSql(sql);
return ctx.SendPaginatedConfirmAsync(0, (cur) =>
return ctx.SendPaginatedConfirmAsync(0, cur =>
{
var items = result.Results.Skip(cur * 20).Take(20);

View File

@@ -69,7 +69,7 @@ public partial class Administration
}
else
{
ci = new CultureInfo(name);
ci = new(name);
Localization.SetGuildCulture(ctx.Guild, ci);
}
@@ -103,7 +103,7 @@ public partial class Administration
}
else
{
ci = new CultureInfo(name);
ci = new(name);
Localization.SetDefaultCulture(ci);
}

View File

@@ -23,9 +23,9 @@ public partial class Administration
var user = await ctx.Guild.GetCurrentUserAsync().ConfigureAwait(false);
if (parameter == "-s" || parameter == "--safe")
await _service.PruneWhere((ITextChannel)ctx.Channel, 100, (x) => x.Author.Id == user.Id && !x.IsPinned).ConfigureAwait(false);
await _service.PruneWhere((ITextChannel)ctx.Channel, 100, x => x.Author.Id == user.Id && !x.IsPinned).ConfigureAwait(false);
else
await _service.PruneWhere((ITextChannel)ctx.Channel, 100, (x) => x.Author.Id == user.Id).ConfigureAwait(false);
await _service.PruneWhere((ITextChannel)ctx.Channel, 100, x => x.Author.Id == user.Id).ConfigureAwait(false);
ctx.Message.DeleteAfter(3);
}
// prune x
@@ -43,7 +43,7 @@ public partial class Administration
count = 1000;
if (parameter == "-s" || parameter == "--safe")
await _service.PruneWhere((ITextChannel)ctx.Channel, count, (x) => !x.IsPinned).ConfigureAwait(false);
await _service.PruneWhere((ITextChannel)ctx.Channel, count, x => !x.IsPinned).ConfigureAwait(false);
else
await _service.PruneWhere((ITextChannel)ctx.Channel, count, x => true).ConfigureAwait(false);
}

View File

@@ -26,7 +26,7 @@ public partial class Administration
public async Task InternalReactionRoles(bool exclusive, ulong? messageId, params string[] input)
{
var target = messageId is ulong msgId
var target = messageId is { } msgId
? await ctx.Channel.GetMessageAsync(msgId).ConfigureAwait(false)
: (await ctx.Channel.GetMessagesAsync(2).FlattenAsync().ConfigureAwait(false))
.Skip(1)
@@ -66,7 +66,7 @@ public partial class Administration
{
try
{
await target.AddReactionAsync(x.emote, new RequestOptions()
await target.AddReactionAsync(x.emote, new()
{
RetryMode = RetryMode.Retry502 | RetryMode.RetryRatelimit
}).ConfigureAwait(false);
@@ -80,7 +80,7 @@ public partial class Administration
await Task.Delay(500).ConfigureAwait(false);
}
if (_service.Add(ctx.Guild.Id, new ReactionRoleMessage()
if (_service.Add(ctx.Guild.Id, new()
{
Exclusive = exclusive,
MessageId = target.Id,

View File

@@ -112,7 +112,7 @@ public partial class Administration
var (exclusive, roles, groups) = _service.GetRoles(ctx.Guild);
await ctx.SendPaginatedConfirmAsync(page, (cur) =>
await ctx.SendPaginatedConfirmAsync(page, cur =>
{
var rolesStr = new StringBuilder();
var roleGroups = roles

View File

@@ -264,7 +264,7 @@ public partial class Administration
$"| {st.GuildCount.ToString().PadBoth(maxGuildCountLength)} `";
})
.ToArray();
await ctx.SendPaginatedConfirmAsync(page, (curPage) =>
await ctx.SendPaginatedConfirmAsync(page, curPage =>
{
var str = string.Join("\n", allShardStrings.Skip(25 * curPage).Take(25));

View File

@@ -26,11 +26,11 @@ public class AdministrationService : INService
_db = db;
_logService = logService;
DeleteMessagesOnCommand = new ConcurrentHashSet<ulong>(bot.AllGuildConfigs
DeleteMessagesOnCommand = new(bot.AllGuildConfigs
.Where(g => g.DeleteMessageOnCommand)
.Select(g => g.GuildId));
DeleteMessagesOnCommandChannels = new ConcurrentDictionary<ulong, bool>(bot.AllGuildConfigs
DeleteMessagesOnCommandChannels = new(bot.AllGuildConfigs
.SelectMany(x => x.DelMsgOnCmdChannels)
.ToDictionary(x => x.ChannelId, x => x.State)
.ToConcurrent());
@@ -108,7 +108,7 @@ public class AdministrationService : INService
{
if (old is null)
{
old = new DelMsgOnCmdChannel { ChannelId = chId };
old = new() { ChannelId = chId };
conf.DelMsgOnCmdChannels.Add(old);
}

View File

@@ -128,7 +128,7 @@ public sealed class AutoAssignRoleService : INService
.GuildConfigs
.AsNoTracking()
.Where(x => x.GuildId == guildId)
.UpdateAsync(_ => new GuildConfig(){ AutoAssignRoleIds = null});
.UpdateAsync(_ => new(){ AutoAssignRoleIds = null});
_autoAssignableRoles.TryRemove(guildId, out _);
@@ -154,7 +154,7 @@ public static class GuildConfigExtensions
public static List<ulong> GetAutoAssignableRoles(this GuildConfig gc)
{
if (string.IsNullOrWhiteSpace(gc.AutoAssignRoleIds))
return new List<ulong>();
return new();
return gc.AutoAssignRoleIds.Split(',').Select(ulong.Parse).ToList();
}

View File

@@ -59,8 +59,8 @@ DELETE FROM Clubs;";
{
var result = new SelectResult()
{
ColumnNames = new List<string>(),
Results = new List<string[]>(),
ColumnNames = new(),
Results = new(),
};
using (var uow = _db.GetDbContext())
@@ -116,14 +116,14 @@ DELETE FROM Clubs;";
.Set<WaifuInfo>()
.AsQueryable()
.Where(x => x.Claimer.UserId == userId)
.UpdateAsync(x => new WaifuInfo() {ClaimerId = null});
.UpdateAsync(x => new() {ClaimerId = null});
// all affinities set to this waifu are reset
await uow
.Set<WaifuInfo>()
.AsQueryable()
.Where(x => x.Affinity.UserId == userId)
.UpdateAsync(x => new WaifuInfo() {AffinityId = null});
.UpdateAsync(x => new() {AffinityId = null});
}
// delete guild xp

View File

@@ -64,7 +64,7 @@ public class DiscordPermOverrideService : INService, ILateBlocker
if (over is null)
{
uow.Set<DiscordPermOverride>()
.Add(over = new DiscordPermOverride()
.Add(over = new()
{
Command = commandName,
Perm = perm,

View File

@@ -19,7 +19,7 @@ public class GameVoiceChannelService : INService
_db = db;
_client = client;
GameVoiceChannels = new ConcurrentHashSet<ulong>(
GameVoiceChannels = new(
bot.AllGuildConfigs.Where(gc => gc.GameVoiceChannel != null)
.Select(gc => gc.GameVoiceChannel.Value));
@@ -40,8 +40,7 @@ public class GameVoiceChannelService : INService
//if the activity has changed, and is a playing activity
if (before.Activity != after.Activity
&& after.Activity != null
&& after.Activity.Type == Discord.ActivityType.Playing)
&& after.Activity is { Type: Discord.ActivityType.Playing })
{
//trigger gvc
await TriggerGvc(after, after.Activity.Name);

View File

@@ -102,7 +102,7 @@ public sealed class LogCommandService : ILogCommandService
.ToConcurrent();
}
_timerReference = new Timer(async (state) =>
_timerReference = new(async state =>
{
var keys = PresenceUpdates.Keys.ToList();
@@ -143,7 +143,7 @@ public sealed class LogCommandService : ILogCommandService
_prot.OnAntiProtectionTriggered += TriggeredAntiProtection;
_clearTimer = new Timer(_ =>
_clearTimer = new(_ =>
{
_ignoreMessageIds.Clear();
}, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1));
@@ -228,7 +228,7 @@ public sealed class LogCommandService : ILogCommandService
(value ? channelId : (ulong?) null);
;
await uow.SaveChangesAsync();
GuildLogSettings.AddOrUpdate(guildId, (id) => logSetting, (id, old) => logSetting);
GuildLogSettings.AddOrUpdate(guildId, id => logSetting, (id, old) => logSetting);
}
}
@@ -299,7 +299,7 @@ public sealed class LogCommandService : ILogCommandService
using (var uow = _db.GetDbContext())
{
var logSetting = uow.LogSettingsFor(gid);
GuildLogSettings.AddOrUpdate(gid, (id) => logSetting, (id, old) => logSetting);
GuildLogSettings.AddOrUpdate(gid, id => logSetting, (id, old) => logSetting);
switch (type)
{
case LogType.Other:

View File

@@ -60,7 +60,7 @@ public class MuteService : INService
.ToDictionary(c => c.GuildId, c => c.MuteRoleName)
.ToConcurrent();
MutedUsers = new ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>>(configs
MutedUsers = new(configs
.ToDictionary(
k => k.GuildId,
v => new ConcurrentHashSet<ulong>(v.MutedUsers.Select(m => m.UserId))
@@ -194,7 +194,7 @@ public class MuteService : INService
var config = uow.GuildConfigsForId(usr.Guild.Id,
set => set.Include(gc => gc.MutedUsers)
.Include(gc => gc.UnmuteTimers));
config.MutedUsers.Add(new MutedUserId()
config.MutedUsers.Add(new()
{
UserId = usr.Id
});
@@ -327,7 +327,7 @@ public class MuteService : INService
using (var uow = _db.GetDbContext())
{
var config = uow.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnmuteTimers));
config.UnmuteTimers.Add(new UnmuteTimer()
config.UnmuteTimers.Add(new()
{
UserId = user.Id,
UnmuteAt = DateTime.UtcNow + after,
@@ -344,7 +344,7 @@ public class MuteService : INService
using (var uow = _db.GetDbContext())
{
var config = uow.GuildConfigsForId(guild.Id, set => set.Include(x => x.UnbanTimer));
config.UnbanTimer.Add(new UnbanTimer()
config.UnbanTimer.Add(new()
{
UserId = user.Id,
UnbanAt = DateTime.UtcNow + after,
@@ -361,7 +361,7 @@ public class MuteService : INService
using (var uow = _db.GetDbContext())
{
var config = uow.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnroleTimer));
config.UnroleTimer.Add(new UnroleTimer()
config.UnroleTimer.Add(new()
{
UserId = user.Id,
UnbanAt = DateTime.UtcNow + after,
@@ -433,7 +433,7 @@ public class MuteService : INService
}, null, after, Timeout.InfiniteTimeSpan);
//add it, or stop the old one and add this one
userUnTimers.AddOrUpdate((userId, type), (key) => toAdd, (key, old) =>
userUnTimers.AddOrUpdate((userId, type), key => toAdd, (key, old) =>
{
old.Change(Timeout.Infinite, Timeout.Infinite);
return toAdd;

View File

@@ -39,7 +39,7 @@ public sealed class PlayingRotateService : INService
.WithProviders(phProviders)
.Build();
_t = new Timer(RotatingStatuses, new TimerState(), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
_t = new(RotatingStatuses, new TimerState(), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
}
}

View File

@@ -32,7 +32,7 @@ public class ProtectionService : INService
private readonly UserPunishService _punishService;
private readonly Channel<PunishQueueItem> PunishUserQueue =
System.Threading.Channels.Channel.CreateUnbounded<PunishQueueItem>(new UnboundedChannelOptions()
System.Threading.Channels.Channel.CreateUnbounded<PunishQueueItem>(new()
{
SingleReader = true,
SingleWriter = false
@@ -134,11 +134,11 @@ public class ProtectionService : INService
}
if (spam != null)
_antiSpamGuilds[gc.GuildId] = new AntiSpamStats() { AntiSpamSettings = spam };
_antiSpamGuilds[gc.GuildId] = new() { AntiSpamSettings = spam };
var alt = gc.AntiAltSetting;
if (alt is not null)
_antiAltGuilds[gc.GuildId] = new AntiAltStats(alt);
_antiAltGuilds[gc.GuildId] = new(alt);
}
private Task HandleUserJoined(SocketGuildUser user)
@@ -154,7 +154,7 @@ public class ProtectionService : INService
_ = Task.Run(async () =>
{
if (maybeAlts is AntiAltStats alts)
if (maybeAlts is { } alts)
{
if (user.CreatedAt != default)
{
@@ -177,7 +177,7 @@ public class ProtectionService : INService
try
{
if (!(maybeStats is AntiRaidStats stats) || !stats.RaidUsers.Add(user))
if (!(maybeStats is { } stats) || !stats.RaidUsers.Add(user))
return;
++stats.UsersCount;
@@ -217,13 +217,13 @@ public class ProtectionService : INService
try
{
if (!_antiSpamGuilds.TryGetValue(channel.Guild.Id, out var spamSettings) ||
spamSettings.AntiSpamSettings.IgnoredChannels.Contains(new AntiSpamIgnore()
spamSettings.AntiSpamSettings.IgnoredChannels.Contains(new()
{
ChannelId = channel.Id
}))
return;
var stats = spamSettings.UserStats.AddOrUpdate(msg.Author.Id, (id) => new UserSpamStats(msg),
var stats = spamSettings.UserStats.AddOrUpdate(msg.Author.Id, id => new(msg),
(id, old) =>
{
old.ApplyNextMessage(msg); return old;
@@ -261,7 +261,7 @@ public class ProtectionService : INService
foreach (var gu in gus)
{
await PunishUserQueue.Writer.WriteAsync(new PunishQueueItem()
await PunishUserQueue.Writer.WriteAsync(new()
{
Action = action,
Type = pt,
@@ -288,7 +288,7 @@ public class ProtectionService : INService
var stats = new AntiRaidStats()
{
AntiRaidSettings = new AntiRaidSetting()
AntiRaidSettings = new()
{
Action = action,
Seconds = seconds,
@@ -355,7 +355,7 @@ public class ProtectionService : INService
var stats = new AntiSpamStats
{
AntiSpamSettings = new AntiSpamSetting()
AntiSpamSettings = new()
{
Action = action,
MessageThreshold = messageCount,
@@ -457,7 +457,7 @@ public class ProtectionService : INService
{
using var uow = _db.GetDbContext();
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiAltSetting));
gc.AntiAltSetting = new AntiAltSetting()
gc.AntiAltSetting = new()
{
Action = action,
ActionDurationMinutes = actionDurationMinutes,
@@ -466,7 +466,7 @@ public class ProtectionService : INService
};
await uow.SaveChangesAsync();
_antiAltGuilds[guildId] = new AntiAltStats(gc.AntiAltSetting);
_antiAltGuilds[guildId] = new(gc.AntiAltSetting);
}
public async Task<bool> TryStopAntiAlt(ulong guildId)

View File

@@ -88,7 +88,7 @@ public class RoleCommandsService : INService
{
var dl = await msg.GetOrDownloadAsync().ConfigureAwait(false);
await dl.RemoveReactionAsync(reaction.Emote, dl.Author,
new RequestOptions()
new()
{
RetryMode = RetryMode.RetryRatelimit | RetryMode.Retry502
}).ConfigureAwait(false);

View File

@@ -44,7 +44,7 @@ public class SelfAssignedRolesService : INService
return false;
}
uow.SelfAssignableRoles.Add(new SelfAssignedRole
uow.SelfAssignableRoles.Add(new()
{
Group = group,
RoleId = role.Id,
@@ -73,7 +73,7 @@ public class SelfAssignedRolesService : INService
using (var uow = _db.GetDbContext())
{
var stats = uow.GetOrCreateUserXpStats(guildUser.Guild.Id, guildUser.Id);
userLevelData = new LevelStats(stats.Xp + stats.AwardedXp);
userLevelData = new(stats.Xp + stats.AwardedXp);
}
var (autoDelete, exclusive, roles) = GetAdAndRoles(guildUser.Guild.Id);
@@ -144,7 +144,7 @@ public class SelfAssignedRolesService : INService
}
else if (toUpdate is null)
{
gc.SelfAssignableRoleGroupNames.Add(new GroupName
gc.SelfAssignableRoleGroupNames.Add(new()
{
Name = name,
Number = group,

View File

@@ -134,7 +134,7 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
private Timer TimerFromAutoCommand(AutoCommand x)
{
return new Timer(async (obj) => await ExecuteCommand((AutoCommand) obj).ConfigureAwait(false),
return new(async obj => await ExecuteCommand((AutoCommand) obj).ConfigureAwait(false),
x,
x.Interval * 1000,
x.Interval * 1000);

View File

@@ -30,7 +30,7 @@ public class UserPunishService : INService
_blacklistService = blacklistService;
_bcs = bcs;
_warnExpiryTimer = new Timer(async _ =>
_warnExpiryTimer = new(async _ =>
{
await CheckAllWarnExpiresAsync();
}, null, TimeSpan.FromSeconds(0), TimeSpan.FromHours(12));
@@ -330,7 +330,7 @@ WHERE GuildId={guildId}
uow.RemoveRange(toDelete);
ps.Add(new WarningPunishment()
ps.Add(new()
{
Count = number,
Punishment = punish,
@@ -437,7 +437,7 @@ WHERE GuildId={guildId}
}
else if (template is null)
{
uow.BanTemplates.Add(new BanTemplate()
uow.BanTemplates.Add(new()
{
GuildId = guildId,
Text = text,

View File

@@ -23,8 +23,8 @@ public class VcRoleService : INService
_client = client;
_client.UserVoiceStateUpdated += ClientOnUserVoiceStateUpdated;
VcRoles = new ConcurrentDictionary<ulong, ConcurrentDictionary<ulong, IRole>>();
ToAssign = new ConcurrentDictionary<ulong, ConcurrentQueue<(bool, IGuildUser, IRole)>>();
VcRoles = new();
ToAssign = new();
var missingRoles = new ConcurrentBag<VcRoleInfo>();
using (var uow = db.GetDbContext())
@@ -147,7 +147,7 @@ public class VcRoleService : INService
{
uow.Remove(toDelete);
}
conf.VcRoleInfos.Add(new VcRoleInfo()
conf.VcRoleInfos.Add(new()
{
VoiceChannelId = vcId,
RoleId = role.Id,

View File

@@ -49,7 +49,7 @@ public partial class Administration
await ctx.SendPaginatedConfirmAsync(page,
(curPage) => _eb.Create()
curPage => _eb.Create()
.WithOkColor()
.WithTitle(GetText(strs.timezones_available))
.WithDescription(string.Join("\n", timezoneStrings

View File

@@ -273,7 +273,7 @@ public partial class Administration
return;
var warnings = _service.WarnlogAll(ctx.Guild.Id);
await ctx.SendPaginatedConfirmAsync(page, (curPage) =>
await ctx.SendPaginatedConfirmAsync(page, curPage =>
{
var ws = warnings.Skip(curPage * 15)
.Take(15)
@@ -885,7 +885,7 @@ public partial class Administration
//do the banning
await Task.WhenAll(bans
.Where(x => x.Id.HasValue)
.Select(x => ctx.Guild.AddBanAsync(x.Id.Value, 7, x.Reason, new RequestOptions()
.Select(x => ctx.Guild.AddBanAsync(x.Id.Value, 7, x.Reason, new()
{
RetryMode = RetryMode.AlwaysRetry,
})))