- 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:
Kwoth
2021-12-26 17:28:39 +01:00
parent b85ba177cd
commit d5fd6aae8e
217 changed files with 1017 additions and 1494 deletions

View File

@@ -12,10 +12,8 @@ public partial class Permissions
private readonly DiscordSocketClient _client;
public BlacklistCommands(DiscordSocketClient client)
{
_client = client;
}
=> _client = client;
private async Task ListBlacklistInternal(string title, BlacklistType type, int page = 0)
{
if (page < 0)
@@ -65,7 +63,7 @@ public partial class Permissions
return _eb.Create()
.WithTitle(title)
.WithDescription(pageItems.JoinWith('\n'))
.WithDescription(pageItems.Join('\n'))
.WithOkColor();
}, items.Length, 10);
}

View File

@@ -1,6 +1,5 @@
using Microsoft.EntityFrameworkCore;
using NadekoBot.Services.Database.Models;
using NadekoBot.Common.Collections;
using NadekoBot.Common.TypeReaders;
using NadekoBot.Db;
using NadekoBot.Modules.Permissions.Services;
@@ -31,7 +30,7 @@ public partial class Permissions
public async Task CmdCooldown(CommandOrCrInfo command, int secs)
{
var channel = (ITextChannel)ctx.Channel;
if (secs < 0 || secs > 3600)
if (secs is < 0 or > 3600)
{
await ReplyErrorLocalizedAsync(strs.invalid_second_param_between(0, 3600));
return;

View File

@@ -1,5 +1,4 @@
using Microsoft.EntityFrameworkCore;
using NadekoBot.Common.Collections;
using NadekoBot.Modules.Permissions.Services;
using NadekoBot.Services.Database.Models;
using NadekoBot.Db;
@@ -14,9 +13,7 @@ public partial class Permissions
private readonly DbService _db;
public FilterCommands(DbService db)
{
_db = db;
}
=> _db = db;
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]

View File

@@ -12,9 +12,7 @@ public partial class Permissions : NadekoModule<PermissionService>
private readonly DbService _db;
public Permissions(DbService db)
{
_db = db;
}
=> _db = db;
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
@@ -203,7 +201,7 @@ public partial class Permissions : NadekoModule<PermissionService>
return;
}
catch (Exception e) when (e is ArgumentOutOfRangeException || e is IndexOutOfRangeException)
catch (Exception e) when (e is ArgumentOutOfRangeException or IndexOutOfRangeException)
{
}
}

View File

@@ -1,5 +1,4 @@
using NadekoBot.Common.Collections;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Modules.Permissions.Services;
@@ -12,11 +11,9 @@ public class CmdCdService : ILateBlocker, INService
public int Priority { get; } = 0;
public CmdCdService(Bot bot)
{
CommandCooldowns = new(
=> CommandCooldowns = new(
bot.AllGuildConfigs.ToDictionary(k => k.GuildId,
v => new ConcurrentHashSet<CommandCooldown>(v.CommandCooldowns)));
}
public Task<bool> TryBlock(IGuild guild, IUser user, string commandName)
{

View File

@@ -1,5 +1,4 @@
using NadekoBot.Common.Collections;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Common.ModuleBehaviors;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Services.Database.Models;
using NadekoBot.Db;

View File

@@ -11,9 +11,7 @@ public class GlobalPermissionService : ILateBlocker, INService
public HashSet<string> BlockedModules => _bss.Data.Blocked.Modules;
public GlobalPermissionService(BotConfigService bss)
{
_bss = bss;
}
=> _bss = bss;
public Task<bool> TryBlockLate(ICommandContext ctx, string moduleName, CommandInfo command)

View File

@@ -75,8 +75,7 @@ public class PermissionService : ILateBlocker, INService
}
public void UpdateCache(GuildConfig config)
{
Cache.AddOrUpdate(config.GuildId, new PermissionCache()
=> Cache.AddOrUpdate(config.GuildId, new PermissionCache()
{
Permissions = new(config.Permissions),
PermRole = config.PermissionRole,
@@ -88,7 +87,6 @@ public class PermissionService : ILateBlocker, INService
old.Verbose = config.VerbosePermissions;
return old;
});
}
public async Task<bool> TryBlockLate(ICommandContext ctx, string moduleName, CommandInfo command)
{