Browse Source

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

pull/1757/head
Zack Broderson 4 years ago
parent
commit
6f71039c9e
5 changed files with 72 additions and 19 deletions
  1. +8
    -1
      src/Discord.Net.Core/Entities/Users/IGuildUser.cs
  2. +12
    -0
      src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs
  3. +18
    -10
      src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs
  4. +7
    -1
      src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs
  5. +27
    -7
      src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs

+ 8
- 1
src/Discord.Net.Core/Entities/Users/IGuildUser.cs View File

@@ -113,7 +113,8 @@ namespace Discord
/// A task that represents the asynchronous modification operation.
/// </returns>
Task ModifyAsync(Action<GuildUserProperties> func, RequestOptions options = null);

//TODO add docs
Task AddRoleAsync(ulong id, RequestOptions options = null);
/// <summary>
/// Adds the specified role to this user in the guild.
/// </summary>
@@ -123,6 +124,8 @@ namespace Discord
/// A task that represents the asynchronous role addition operation.
/// </returns>
Task AddRoleAsync(IRole role, RequestOptions options = null);
//TODO: Add docs
Task AddRolesAsync(IEnumerable<ulong> roleIds, RequestOptions options = null);
/// <summary>
/// Adds the specified <paramref name="roles"/> to this user in the guild.
/// </summary>
@@ -132,6 +135,8 @@ namespace Discord
/// A task that represents the asynchronous role addition operation.
/// </returns>
Task AddRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null);
//TODO add docs
Task RemoveRoleAsync(ulong id, RequestOptions options = null);
/// <summary>
/// Removes the specified <paramref name="role"/> from this user in the guild.
/// </summary>
@@ -141,6 +146,8 @@ namespace Discord
/// A task that represents the asynchronous role removal operation.
/// </returns>
Task RemoveRoleAsync(IRole role, RequestOptions options = null);
//TODO: Add docs
Task RemoveRolesAsync(IEnumerable<ulong> roleIds, RequestOptions options = null);
/// <summary>
/// Removes the specified <paramref name="roles"/> from this user in the guild.
/// </summary>


+ 12
- 0
src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs View File

@@ -112,15 +112,27 @@ namespace Discord.Rest
public Task KickAsync(string reason = null, RequestOptions options = null)
=> UserHelper.KickAsync(this, Discord, reason, options);
/// <inheritdoc />
public Task AddRoleAsync(ulong roleId, RequestOptions options = null)
=> throw new NotImplementedException();
/// <inheritdoc />
public Task AddRoleAsync(IRole role, RequestOptions options = null)
=> AddRolesAsync(new[] { role }, options);
/// <inheritdoc />
public Task AddRolesAsync(IEnumerable<ulong> roleIds, RequestOptions options = null)
=> throw new NotImplementedException();
/// <inheritdoc />
public Task AddRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null)
=> UserHelper.AddRolesAsync(this, Discord, roles, options);
/// <inheritdoc />
public Task RemoveRoleAsync(ulong roleId, RequestOptions options = null)
=> throw new NotImplementedException();
/// <inheritdoc />
public Task RemoveRoleAsync(IRole role, RequestOptions options = null)
=> RemoveRolesAsync(new[] { role }, options);
/// <inheritdoc />
public Task RemoveRolesAsync(IEnumerable<ulong> roleIds, RequestOptions options = null)
=> throw new NotImplementedException();
/// <inheritdoc />
public Task RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null)
=> UserHelper.RemoveRolesAsync(this, Discord, roles, options);



+ 18
- 10
src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs View File

@@ -59,27 +59,35 @@ namespace Discord.Rest
/// <inheritdoc />
ChannelPermissions IGuildUser.GetPermissions(IGuildChannel channel) => Permissions.ToChannelPerms(channel, GuildPermissions.Webhook.RawValue);
/// <inheritdoc />
Task IGuildUser.KickAsync(string reason, RequestOptions options) =>
Task IGuildUser.KickAsync(string reason, RequestOptions options) =>
throw new NotSupportedException("Webhook users cannot be kicked.");

/// <inheritdoc />
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 />
Task IGuildUser.AddRoleAsync(IRole role, RequestOptions options) =>
Task IGuildUser.AddRoleAsync(ulong role, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");

/// <inheritdoc />
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 />
Task IGuildUser.RemoveRoleAsync(IRole role, RequestOptions options) =>
Task IGuildUser.AddRolesAsync(IEnumerable<ulong> roles, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");
/// <inheritdoc />
Task IGuildUser.AddRolesAsync(IEnumerable<IRole> roles, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");
/// <inheritdoc />
Task IGuildUser.RemoveRoleAsync(ulong role, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");
/// <inheritdoc />
Task IGuildUser.RemoveRoleAsync(IRole role, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");
/// <inheritdoc />
Task IGuildUser.RemoveRolesAsync(IEnumerable<ulong> roles, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");

/// <inheritdoc />
Task IGuildUser.RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options) =>
Task IGuildUser.RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options) =>
throw new NotSupportedException("Roles are not supported on webhook users.");

//IVoiceState


+ 7
- 1
src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs 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,9 +177,15 @@ 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)
=> throw new NotImplementedException();
/// <inheritdoc />
public Task AddRoleAsync(IRole role, RequestOptions options = null)
=> AddRolesAsync(new[] { role }, options);
/// <inheritdoc />
public Task AddRolesAsync(IEnumerable<ulong> roleIds, RequestOptions options = null)
=> throw new NotImplementedException();
/// <inheritdoc />
public Task AddRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null)
=> UserHelper.AddRolesAsync(this, Discord, roles, options);
/// <inheritdoc />


+ 27
- 7
src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs 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


Loading…
Cancel
Save