Add various optimizations and cleanups (#1114)

* Change all Select(... as ...) to OfType

* Add changes according to 194a8aa427
This commit is contained in:
Still Hsu
2018-08-31 05:36:44 +08:00
committed by Christopher F
parent a2d8800115
commit 82cfdffc65
46 changed files with 131 additions and 135 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Globalization;
using System.Text;
@@ -139,22 +139,22 @@ namespace Discord
if (user != null)
return $"@{guildUser?.Nickname ?? user?.Username}";
else
return $"";
return "";
case TagHandling.NameNoPrefix:
if (user != null)
return $"{guildUser?.Nickname ?? user?.Username}";
else
return $"";
return "";
case TagHandling.FullName:
if (user != null)
return $"@{user.Username}#{user.Discriminator}";
else
return $"";
return "";
case TagHandling.FullNameNoPrefix:
if (user != null)
return $"{user.Username}#{user.Discriminator}";
else
return $"";
return "";
case TagHandling.Sanitize:
if (guildUser != null && guildUser.Nickname == null)
return MentionUser($"{SanitizeChar}{tag.Key}", false);
@@ -176,13 +176,13 @@ namespace Discord
if (channel != null)
return $"#{channel.Name}";
else
return $"";
return "";
case TagHandling.NameNoPrefix:
case TagHandling.FullNameNoPrefix:
if (channel != null)
return $"{channel.Name}";
else
return $"";
return "";
case TagHandling.Sanitize:
return MentionChannel($"{SanitizeChar}{tag.Key}");
}
@@ -201,13 +201,13 @@ namespace Discord
if (role != null)
return $"@{role.Name}";
else
return $"";
return "";
case TagHandling.NameNoPrefix:
case TagHandling.FullNameNoPrefix:
if (role != null)
return $"{role.Name}";
else
return $"";
return "";
case TagHandling.Sanitize:
return MentionRole($"{SanitizeChar}{tag.Key}");
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -60,7 +60,7 @@ namespace Discord
if (Current.Count == 0)
_info.Remaining = 0;
}
_info.PageSize = _info.Remaining != null ? (int)Math.Min(_info.Remaining.Value, _source.PageSize) : _source.PageSize;
_info.PageSize = _info.Remaining != null ? Math.Min(_info.Remaining.Value, _source.PageSize) : _source.PageSize;
if (_info.Remaining != 0)
{
@@ -74,4 +74,4 @@ namespace Discord
public void Dispose() { Current = null; }
}
}
}
}

View File

@@ -1,4 +1,4 @@
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
namespace Discord
{
@@ -119,13 +119,11 @@ namespace Discord
resolvedPermissions = mask; //Owners and administrators always have all permissions
else
{
OverwritePermissions? perms;
//Start with this user's guild permissions
resolvedPermissions = guildPermissions;
//Give/Take Everyone permissions
perms = channel.GetPermissionOverwrite(guild.EveryoneRole);
var perms = channel.GetPermissionOverwrite(guild.EveryoneRole);
if (perms != null)
resolvedPermissions = (resolvedPermissions & ~perms.Value.DenyValue) | perms.Value.AllowValue;
@@ -133,7 +131,7 @@ namespace Discord
ulong deniedPermissions = 0UL, allowedPermissions = 0UL;
foreach (var roleId in user.RoleIds)
{
IRole role = null;
IRole role;
if (roleId != guild.EveryoneRole.Id && (role = guild.GetRole(roleId)) != null)
{
perms = channel.GetPermissionOverwrite(role);
@@ -151,7 +149,7 @@ namespace Discord
if (perms != null)
resolvedPermissions = (resolvedPermissions & ~perms.Value.DenyValue) | perms.Value.AllowValue;
if (channel is ITextChannel textChannel)
if (channel is ITextChannel)
{
if (!GetValue(resolvedPermissions, ChannelPermission.ViewChannel))
{

View File

@@ -1,4 +1,4 @@
using System;
using System;
namespace Discord
{
@@ -198,7 +198,7 @@ namespace Discord
for (var i = 0; i < roles.Length; i++)
{
if (roles[i] == guildId)
throw new ArgumentException($"The everyone role cannot be assigned to a user", name);
throw new ArgumentException("The everyone role cannot be assigned to a user", name);
}
}
}