(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:
@@ -17,7 +17,7 @@ namespace Discord.Rest
|
||||
return RestApplication.Create(client, model);
|
||||
}
|
||||
|
||||
public static async Task<RestChannel> GetChannelAsync(BaseDiscordClient client,
|
||||
public static async Task<RestChannel> GetChannelAsync(BaseDiscordClient client,
|
||||
ulong id, RequestOptions options)
|
||||
{
|
||||
var model = await client.ApiClient.GetChannelAsync(id, options).ConfigureAwait(false);
|
||||
@@ -45,13 +45,13 @@ namespace Discord.Rest
|
||||
.Where(x => x.Type == ChannelType.Group)
|
||||
.Select(x => RestGroupChannel.Create(client, x)).ToImmutableArray();
|
||||
}
|
||||
|
||||
|
||||
public static async Task<IReadOnlyCollection<RestConnection>> GetConnectionsAsync(BaseDiscordClient client, RequestOptions options)
|
||||
{
|
||||
var models = await client.ApiClient.GetMyConnectionsAsync(options).ConfigureAwait(false);
|
||||
return models.Select(RestConnection.Create).ToImmutableArray();
|
||||
}
|
||||
|
||||
|
||||
public static async Task<RestInviteMetadata> GetInviteAsync(BaseDiscordClient client,
|
||||
string inviteId, RequestOptions options)
|
||||
{
|
||||
@@ -60,7 +60,7 @@ namespace Discord.Rest
|
||||
return RestInviteMetadata.Create(client, null, null, model);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static async Task<RestGuild> GetGuildAsync(BaseDiscordClient client,
|
||||
ulong id, bool withCounts, RequestOptions options)
|
||||
{
|
||||
@@ -85,7 +85,7 @@ namespace Discord.Rest
|
||||
return RestGuildWidget.Create(model);
|
||||
return null;
|
||||
}
|
||||
public static IAsyncEnumerable<IReadOnlyCollection<RestUserGuild>> GetGuildSummariesAsync(BaseDiscordClient client,
|
||||
public static IAsyncEnumerable<IReadOnlyCollection<RestUserGuild>> GetGuildSummariesAsync(BaseDiscordClient client,
|
||||
ulong? fromGuildId, int? limit, RequestOptions options)
|
||||
{
|
||||
return new PagedAsyncEnumerable<RestUserGuild>(
|
||||
@@ -136,7 +136,7 @@ namespace Discord.Rest
|
||||
var model = await client.ApiClient.CreateGuildAsync(args, options).ConfigureAwait(false);
|
||||
return RestGuild.Create(client, model);
|
||||
}
|
||||
|
||||
|
||||
public static async Task<RestUser> GetUserAsync(BaseDiscordClient client,
|
||||
ulong id, RequestOptions options)
|
||||
{
|
||||
@@ -201,5 +201,9 @@ namespace Discord.Rest
|
||||
}
|
||||
};
|
||||
}
|
||||
public static Task AddRoleAsync(BaseDiscordClient client, ulong guildId, ulong userId, ulong roleId, RequestOptions options = null)
|
||||
=> client.ApiClient.AddRoleAsync(guildId, userId, roleId, options);
|
||||
public static Task RemoveRoleAsync(BaseDiscordClient client, ulong guildId, ulong userId, ulong roleId, RequestOptions options = null)
|
||||
=> client.ApiClient.RemoveRoleAsync(guildId, userId, roleId, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +107,10 @@ namespace Discord.Rest
|
||||
=> ClientHelper.GetVoiceRegionAsync(this, id, options);
|
||||
public Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null)
|
||||
=> ClientHelper.GetWebhookAsync(this, id, options);
|
||||
public Task AddRoleAsync(ulong guildId, ulong userId, ulong roleId)
|
||||
=> ClientHelper.AddRoleAsync(this, guildId, userId, roleId);
|
||||
public Task RemoveRoleAsync(ulong guildId, ulong userId, ulong roleId)
|
||||
=> ClientHelper.RemoveRoleAsync(this, guildId, userId, roleId);
|
||||
|
||||
public Task AddReactionAsync(ulong channelId, ulong messageId, IEmote emote, RequestOptions options = null)
|
||||
=> MessageHelper.AddReactionAsync(channelId, messageId, emote, this, options);
|
||||
|
||||
@@ -112,17 +112,29 @@ 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)
|
||||
=> 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 />
|
||||
/// <exception cref="InvalidOperationException">Resolving permissions requires the parent guild to be downloaded.</exception>
|
||||
|
||||
@@ -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.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 />
|
||||
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) =>
|
||||
throw new NotSupportedException("Roles are not supported on webhook users.");
|
||||
|
||||
//IVoiceState
|
||||
|
||||
@@ -73,16 +73,16 @@ namespace Discord.Rest
|
||||
return RestDMChannel.Create(client, await client.ApiClient.CreateDMChannelAsync(args, options).ConfigureAwait(false));
|
||||
}
|
||||
|
||||
public static async Task AddRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable<IRole> roles, RequestOptions options)
|
||||
public static async Task AddRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable<ulong> roleIds, RequestOptions options)
|
||||
{
|
||||
foreach (var role in roles)
|
||||
await client.ApiClient.AddRoleAsync(user.Guild.Id, user.Id, role.Id, options).ConfigureAwait(false);
|
||||
foreach (var roleId in roleIds)
|
||||
await client.ApiClient.AddRoleAsync(user.Guild.Id, user.Id, roleId, options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public static async Task RemoveRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable<IRole> roles, RequestOptions options)
|
||||
public static async Task RemoveRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable<ulong> roleIds, RequestOptions options)
|
||||
{
|
||||
foreach (var role in roles)
|
||||
await client.ApiClient.RemoveRoleAsync(user.Guild.Id, user.Id, role.Id, options).ConfigureAwait(false);
|
||||
foreach (var roleId in roleIds)
|
||||
await client.ApiClient.RemoveRoleAsync(user.Guild.Id, user.Id, roleId, options).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user