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

@@ -247,7 +247,7 @@ public partial class Permissions
removed = config.FilteredWords.FirstOrDefault(fw => fw.Word.Trim().ToLowerInvariant() == word);
if (removed is null)
config.FilteredWords.Add(new FilteredWord() { Word = word });
config.FilteredWords.Add(new() { Word = word });
else
{
uow.Remove(removed);
@@ -285,7 +285,7 @@ public partial class Permissions
var fws = fwHash.ToArray();
await ctx.SendPaginatedConfirmAsync(page,
(curPage) => _eb.Create()
curPage => _eb.Create()
.WithTitle(GetText(strs.filter_word_list))
.WithDescription(string.Join("\n", fws.Skip(curPage * 10).Take(10)))
.WithOkColor()

View File

@@ -29,7 +29,7 @@ public partial class Permissions : NadekoModule<PermissionService>
using (var uow = _db.GetDbContext())
{
var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
if (action is null) action = new PermissionAction(!config.VerbosePermissions); // New behaviour, can toggle.
if (action is null) action = new(!config.VerbosePermissions); // New behaviour, can toggle.
config.VerbosePermissions = action.Value;
await uow.SaveChangesAsync();
_service.UpdateCache(config);

View File

@@ -18,7 +18,7 @@ public class CmdCdService : ILateBlocker, INService
public CmdCdService(Bot bot)
{
CommandCooldowns = new ConcurrentDictionary<ulong, ConcurrentHashSet<CommandCooldown>>(
CommandCooldowns = new(
bot.AllGuildConfigs.ToDictionary(k => k.GuildId,
v => new ConcurrentHashSet<CommandCooldown>(v.CommandCooldowns)));
}
@@ -38,7 +38,7 @@ public class CmdCdService : ILateBlocker, INService
return Task.FromResult(true);
}
activeCdsForGuild.Add(new ActiveCooldown()
activeCdsForGuild.Add(new()
{
UserId = user.Id,
Command = commandName,

View File

@@ -87,19 +87,19 @@ public sealed class FilterService : IEarlyBehavior
.Where(gc => ids.Contains(gc.GuildId))
.ToList();
InviteFilteringServers = new ConcurrentHashSet<ulong>(configs.Where(gc => gc.FilterInvites).Select(gc => gc.GuildId));
InviteFilteringChannels = new ConcurrentHashSet<ulong>(configs.SelectMany(gc => gc.FilterInvitesChannelIds.Select(fci => fci.ChannelId)));
InviteFilteringServers = new(configs.Where(gc => gc.FilterInvites).Select(gc => gc.GuildId));
InviteFilteringChannels = new(configs.SelectMany(gc => gc.FilterInvitesChannelIds.Select(fci => fci.ChannelId)));
LinkFilteringServers = new ConcurrentHashSet<ulong>(configs.Where(gc => gc.FilterLinks).Select(gc => gc.GuildId));
LinkFilteringChannels = new ConcurrentHashSet<ulong>(configs.SelectMany(gc => gc.FilterLinksChannelIds.Select(fci => fci.ChannelId)));
LinkFilteringServers = new(configs.Where(gc => gc.FilterLinks).Select(gc => gc.GuildId));
LinkFilteringChannels = new(configs.SelectMany(gc => gc.FilterLinksChannelIds.Select(fci => fci.ChannelId)));
var dict = configs.ToDictionary(gc => gc.GuildId, gc => new ConcurrentHashSet<string>(gc.FilteredWords.Select(fw => fw.Word)));
ServerFilteredWords = new ConcurrentDictionary<ulong, ConcurrentHashSet<string>>(dict);
ServerFilteredWords = new(dict);
var serverFiltering = configs.Where(gc => gc.FilterWords);
WordFilteringServers = new ConcurrentHashSet<ulong>(serverFiltering.Select(gc => gc.GuildId));
WordFilteringChannels = new ConcurrentHashSet<ulong>(configs.SelectMany(gc => gc.FilterWordsChannelIds.Select(fwci => fwci.ChannelId)));
WordFilteringServers = new(serverFiltering.Select(gc => gc.GuildId));
WordFilteringChannels = new(configs.SelectMany(gc => gc.FilterWordsChannelIds.Select(fwci => fwci.ChannelId)));
}
client.MessageUpdated += (oldData, newMsg, channel) =>

View File

@@ -42,11 +42,11 @@ public class PermissionService : ILateBlocker, INService
foreach (var x in uow.GuildConfigs.Permissionsv2ForAll(client.Guilds.ToArray().Select(x => x.Id)
.ToList()))
{
Cache.TryAdd(x.GuildId, new PermissionCache()
Cache.TryAdd(x.GuildId, new()
{
Verbose = x.VerbosePermissions,
PermRole = x.PermissionRole,
Permissions = new PermissionsCollection<Permissionv2>(x.Permissions)
Permissions = new(x.Permissions)
});
}
}
@@ -64,7 +64,7 @@ public class PermissionService : ILateBlocker, INService
}
Cache.TryGetValue(guildId, out pc);
if (pc is null)
throw new Exception("Cache is null.");
throw new("Cache is null.");
}
return pc;
}
@@ -90,12 +90,12 @@ public class PermissionService : ILateBlocker, INService
{
Cache.AddOrUpdate(config.GuildId, new PermissionCache()
{
Permissions = new PermissionsCollection<Permissionv2>(config.Permissions),
Permissions = new(config.Permissions),
PermRole = config.PermissionRole,
Verbose = config.VerbosePermissions
}, (id, old) =>
{
old.Permissions = new PermissionsCollection<Permissionv2>(config.Permissions);
old.Permissions = new(config.Permissions);
old.PermRole = config.PermissionRole;
old.Verbose = config.VerbosePermissions;
return old;