Throw when attempting to add or remove a member's EveryoneRole (#781)
* Throw when attempting to add or remove a member's EveryoneRole This resolves #780 * Removed braces
This commit is contained in:
committed by
RogueException
parent
f997089174
commit
506a6c96c9
@@ -192,5 +192,13 @@ namespace Discord
|
|||||||
throw new ArgumentOutOfRangeException(name, "Messages must be younger than two weeks old.");
|
throw new ArgumentOutOfRangeException(name, "Messages must be younger than two weeks old.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static void NotEveryoneRole(ulong[] roles, ulong guildId, string name)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -392,6 +392,7 @@ namespace Discord.API
|
|||||||
Preconditions.NotEqual(guildId, 0, nameof(guildId));
|
Preconditions.NotEqual(guildId, 0, nameof(guildId));
|
||||||
Preconditions.NotEqual(userId, 0, nameof(userId));
|
Preconditions.NotEqual(userId, 0, nameof(userId));
|
||||||
Preconditions.NotEqual(roleId, 0, nameof(roleId));
|
Preconditions.NotEqual(roleId, 0, nameof(roleId));
|
||||||
|
Preconditions.NotEqual(roleId, guildId, nameof(roleId), "The Everyone role cannot be added to a user.");
|
||||||
options = RequestOptions.CreateOrClone(options);
|
options = RequestOptions.CreateOrClone(options);
|
||||||
|
|
||||||
var ids = new BucketIds(guildId: guildId);
|
var ids = new BucketIds(guildId: guildId);
|
||||||
@@ -402,6 +403,7 @@ namespace Discord.API
|
|||||||
Preconditions.NotEqual(guildId, 0, nameof(guildId));
|
Preconditions.NotEqual(guildId, 0, nameof(guildId));
|
||||||
Preconditions.NotEqual(userId, 0, nameof(userId));
|
Preconditions.NotEqual(userId, 0, nameof(userId));
|
||||||
Preconditions.NotEqual(roleId, 0, nameof(roleId));
|
Preconditions.NotEqual(roleId, 0, nameof(roleId));
|
||||||
|
Preconditions.NotEqual(roleId, guildId, nameof(roleId), "The Everyone role cannot be removed from a user.");
|
||||||
options = RequestOptions.CreateOrClone(options);
|
options = RequestOptions.CreateOrClone(options);
|
||||||
|
|
||||||
var ids = new BucketIds(guildId: guildId);
|
var ids = new BucketIds(guildId: guildId);
|
||||||
@@ -1000,6 +1002,8 @@ namespace Discord.API
|
|||||||
|
|
||||||
bool isCurrentUser = userId == CurrentUserId;
|
bool isCurrentUser = userId == CurrentUserId;
|
||||||
|
|
||||||
|
if (args.RoleIds.IsSpecified)
|
||||||
|
Preconditions.NotEveryoneRole(args.RoleIds.Value, guildId, nameof(args.RoleIds));
|
||||||
if (isCurrentUser && args.Nickname.IsSpecified)
|
if (isCurrentUser && args.Nickname.IsSpecified)
|
||||||
{
|
{
|
||||||
var nickArgs = new Rest.ModifyCurrentUserNickParams(args.Nickname.Value ?? "");
|
var nickArgs = new Rest.ModifyCurrentUserNickParams(args.Nickname.Value ?? "");
|
||||||
|
|||||||
Reference in New Issue
Block a user