Applied codestyle to all .cs files

This commit is contained in:
Kwoth
2021-12-29 06:07:16 +01:00
parent 723447c7d4
commit 82000c97a4
543 changed files with 13221 additions and 14059 deletions

View File

@@ -8,4 +8,4 @@ public class PermissionCache
public string PermRole { get; set; }
public bool Verbose { get; set; } = true;
public PermissionsCollection<Permissionv2> Permissions { get; set; }
}
}

View File

@@ -5,8 +5,12 @@ namespace NadekoBot.Modules.Permissions.Common;
public static class PermissionExtensions
{
public static bool CheckPermissions(this IEnumerable<Permissionv2> permsEnumerable, IUserMessage message,
string commandName, string moduleName, out int permIndex)
public static bool CheckPermissions(
this IEnumerable<Permissionv2> permsEnumerable,
IUserMessage message,
string commandName,
string moduleName,
out int permIndex)
{
var perms = permsEnumerable as List<Permissionv2> ?? permsEnumerable.ToList();
@@ -16,13 +20,11 @@ public static class PermissionExtensions
var result = perm.CheckPermission(message, commandName, moduleName);
if (result is null)
{
continue;
}
if (result is null) continue;
permIndex = i;
return result.Value;
}
permIndex = -1; //defaut behaviour
return true;
}
@@ -30,13 +32,17 @@ public static class PermissionExtensions
//null = not applicable
//true = applicable, allowed
//false = applicable, not allowed
public static bool? CheckPermission(this Permissionv2 perm, IUserMessage message, string commandName, string moduleName)
public static bool? CheckPermission(
this Permissionv2 perm,
IUserMessage message,
string commandName,
string moduleName)
{
if (!((perm.SecondaryTarget == SecondaryPermissionType.Command &&
perm.SecondaryTargetName.ToLowerInvariant() == commandName.ToLowerInvariant()) ||
(perm.SecondaryTarget == SecondaryPermissionType.Module &&
perm.SecondaryTargetName.ToLowerInvariant() == moduleName.ToLowerInvariant()) ||
perm.SecondaryTarget == SecondaryPermissionType.AllModules))
if (!((perm.SecondaryTarget == SecondaryPermissionType.Command
&& perm.SecondaryTargetName.ToLowerInvariant() == commandName.ToLowerInvariant())
|| (perm.SecondaryTarget == SecondaryPermissionType.Module
&& perm.SecondaryTargetName.ToLowerInvariant() == moduleName.ToLowerInvariant())
|| perm.SecondaryTarget == SecondaryPermissionType.AllModules))
return null;
var guildUser = message.Author as IGuildUser;
@@ -51,7 +57,7 @@ public static class PermissionExtensions
if (perm.PrimaryTargetId == message.Channel.Id)
return perm.State;
break;
case PrimaryPermissionType.Role:
case PrimaryPermissionType.Role:
if (guildUser is null)
break;
if (guildUser.RoleIds.Contains(perm.PrimaryTargetId))
@@ -62,6 +68,7 @@ public static class PermissionExtensions
break;
return perm.State;
}
return null;
}
@@ -97,8 +104,9 @@ public static class PermissionExtensions
break;
}
var secName = perm.SecondaryTarget == SecondaryPermissionType.Command && !perm.IsCustomCommand ?
prefix + perm.SecondaryTargetName : perm.SecondaryTargetName;
var secName = perm.SecondaryTarget == SecondaryPermissionType.Command && !perm.IsCustomCommand
? prefix + perm.SecondaryTargetName
: perm.SecondaryTargetName;
com += " " + (perm.SecondaryTargetName != "*" ? secName + " " : "") + (perm.State ? "enable" : "disable") + " ";
switch (perm.PrimaryTarget)
@@ -118,4 +126,4 @@ public static class PermissionExtensions
return prefix + com;
}
}
}

View File

@@ -4,15 +4,32 @@ using NadekoBot.Services.Database.Models;
namespace NadekoBot.Modules.Permissions.Common;
public class PermissionsCollection<T> : IndexedCollection<T> where T : class, IIndexed
public class PermissionsCollection<T> : IndexedCollection<T>
where T : class, IIndexed
{
public override T this[int index]
{
get => Source[index];
set
{
lock (_localLocker)
{
if (index == 0) // can't set first element. It's always allow all
throw new IndexOutOfRangeException(nameof(index));
base[index] = value;
}
}
}
private readonly object _localLocker = new();
public PermissionsCollection(IEnumerable<T> source) : base(source)
public PermissionsCollection(IEnumerable<T> source)
: base(source)
{
}
public static implicit operator List<T>(PermissionsCollection<T> x) =>
x.Source;
public static implicit operator List<T>(PermissionsCollection<T> x)
=> x.Source;
public override void Clear()
{
@@ -29,10 +46,11 @@ public class PermissionsCollection<T> : IndexedCollection<T> where T : class, II
bool removed;
lock (_localLocker)
{
if(Source.IndexOf(item) == 0)
if (Source.IndexOf(item) == 0)
throw new ArgumentException("You can't remove first permsission (allow all)");
removed = base.Remove(item);
}
return removed;
}
@@ -40,7 +58,7 @@ public class PermissionsCollection<T> : IndexedCollection<T> where T : class, II
{
lock (_localLocker)
{
if(index == 0) // can't insert on first place. Last item is always allow all.
if (index == 0) // can't insert on first place. Last item is always allow all.
throw new IndexOutOfRangeException(nameof(index));
base.Insert(index, item);
}
@@ -50,22 +68,10 @@ public class PermissionsCollection<T> : IndexedCollection<T> where T : class, II
{
lock (_localLocker)
{
if(index == 0) // you can't remove first permission (allow all)
if (index == 0) // you can't remove first permission (allow all)
throw new IndexOutOfRangeException(nameof(index));
base.RemoveAt(index);
}
}
public override T this[int index] {
get => Source[index];
set {
lock (_localLocker)
{
if(index == 0) // can't set first element. It's always allow all
throw new IndexOutOfRangeException(nameof(index));
base[index] = value;
}
}
}
}
}