(ifcbrk) feature: Add ability to add/remove roles by id (#1757)

* Scaffold Add/Remove roles by id. (needs impl & docs)

* Add docs

* Add implementation

* Expose Add/Remove role endpoints

* Formatting

* Fix wrong method call
This commit is contained in:
Zack Broderson
2021-04-29 10:34:52 -04:00
committed by GitHub
parent 365a848f7a
commit 4c9910cf71
8 changed files with 134 additions and 39 deletions

View File

@@ -63,7 +63,7 @@ namespace Discord.WebSocket
/// <summary>
/// Returns a collection of roles that the user possesses.
/// </summary>
public IReadOnlyCollection<SocketRole> Roles
public IReadOnlyCollection<SocketRole> Roles
=> _roleIds.Select(id => Guild.GetRole(id)).Where(x => x != null).ToReadOnlyCollection(() => _roleIds.Length);
/// <summary>
/// Returns the voice channel the user is in, or <c>null</c> if none.
@@ -177,17 +177,29 @@ namespace Discord.WebSocket
public Task KickAsync(string reason = null, RequestOptions options = null)
=> UserHelper.KickAsync(this, Discord, reason, options);
/// <inheritdoc />
public Task AddRoleAsync(ulong roleId, RequestOptions options = null)
=> AddRolesAsync(new[] { roleId }, options);
/// <inheritdoc />
public Task AddRoleAsync(IRole role, RequestOptions options = null)
=> AddRolesAsync(new[] { role }, options);
=> AddRoleAsync(role.Id, options);
/// <inheritdoc />
public Task AddRolesAsync(IEnumerable<ulong> roleIds, RequestOptions options = null)
=> UserHelper.AddRolesAsync(this, Discord, roleIds, options);
/// <inheritdoc />
public Task AddRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null)
=> UserHelper.AddRolesAsync(this, Discord, roles, options);
=> AddRolesAsync(roles.Select(x => x.Id), options);
/// <inheritdoc />
public Task RemoveRoleAsync(ulong roleId, RequestOptions options = null)
=> RemoveRolesAsync(new[] { roleId }, options);
/// <inheritdoc />
public Task RemoveRoleAsync(IRole role, RequestOptions options = null)
=> RemoveRolesAsync(new[] { role }, options);
=> RemoveRoleAsync(role.Id, options);
/// <inheritdoc />
public Task RemoveRolesAsync(IEnumerable<ulong> roleIds, RequestOptions options = null)
=> UserHelper.RemoveRolesAsync(this, Discord, roleIds, options);
/// <inheritdoc />
public Task RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null)
=> UserHelper.RemoveRolesAsync(this, Discord, roles, options);
=> RemoveRolesAsync(roles.Select(x => x.Id));
/// <inheritdoc />
public ChannelPermissions GetPermissions(IGuildChannel channel)

View File

@@ -31,7 +31,7 @@ namespace Discord.WebSocket
public override bool IsWebhook => true;
/// <inheritdoc />
internal override SocketPresence Presence { get { return new SocketPresence(UserStatus.Offline, null, null, null); } set { } }
internal override SocketGlobalUser GlobalUser =>
internal override SocketGlobalUser GlobalUser =>
throw new NotSupportedException();
internal SocketWebhookUser(SocketGuild guild, ulong id, ulong webhookId)
@@ -73,32 +73,52 @@ namespace Discord.WebSocket
ChannelPermissions IGuildUser.GetPermissions(IGuildChannel channel) => Permissions.ToChannelPerms(channel, GuildPermissions.Webhook.RawValue);
/// <inheritdoc />
/// <exception cref="NotSupportedException">Webhook users cannot be kicked.</exception>
Task IGuildUser.KickAsync(string reason, RequestOptions options) =>
Task IGuildUser.KickAsync(string reason, RequestOptions options) =>
throw new NotSupportedException("Webhook users cannot be kicked.");
/// <inheritdoc />
/// <exception cref="NotSupportedException">Webhook users cannot be modified.</exception>
Task IGuildUser.ModifyAsync(Action<GuildUserProperties> func, RequestOptions options) =>
Task IGuildUser.ModifyAsync(Action<GuildUserProperties> func, RequestOptions options) =>
throw new NotSupportedException("Webhook users cannot be modified.");
/// <inheritdoc />
/// <exception cref="NotSupportedException">Roles are not supported on webhook users.</exception>
Task IGuildUser.AddRoleAsync(IRole role, RequestOptions options) =>
Task IGuildUser.AddRoleAsync(ulong roleId, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");
/// <inheritdoc />
/// <exception cref="NotSupportedException">Roles are not supported on webhook users.</exception>
Task IGuildUser.AddRolesAsync(IEnumerable<IRole> roles, RequestOptions options) =>
Task IGuildUser.AddRoleAsync(IRole role, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");
/// <inheritdoc />
/// <exception cref="NotSupportedException">Roles are not supported on webhook users.</exception>
Task IGuildUser.RemoveRoleAsync(IRole role, RequestOptions options) =>
Task IGuildUser.AddRolesAsync(IEnumerable<ulong> roleIds, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");
/// <inheritdoc />
/// <exception cref="NotSupportedException">Roles are not supported on webhook users.</exception>
Task IGuildUser.RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options) =>
Task IGuildUser.AddRolesAsync(IEnumerable<IRole> roles, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");
/// <inheritdoc />
/// <exception cref="NotSupportedException">Roles are not supported on webhook users.</exception>
Task IGuildUser.RemoveRoleAsync(ulong roleId, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");
/// <inheritdoc />
/// <exception cref="NotSupportedException">Roles are not supported on webhook users.</exception>
Task IGuildUser.RemoveRoleAsync(IRole role, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");
/// <inheritdoc />
/// <exception cref="NotSupportedException">Roles are not supported on webhook users.</exception>
Task IGuildUser.RemoveRolesAsync(IEnumerable<ulong> roles, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");
/// <inheritdoc />
/// <exception cref="NotSupportedException">Roles are not supported on webhook users.</exception>
Task IGuildUser.RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");
//IVoiceState