Browse Source

Expose Add/Remove role endpoints

pull/1757/head
Zack Broderson 4 years ago
parent
commit
d4bb4b7ba9
2 changed files with 16 additions and 6 deletions
  1. +11
    -6
      src/Discord.Net.Rest/ClientHelper.cs
  2. +5
    -0
      src/Discord.Net.Rest/DiscordRestClient.cs

+ 11
- 6
src/Discord.Net.Rest/ClientHelper.cs View File

@@ -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,10 @@ 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);
}
}

+ 5
- 0
src/Discord.Net.Rest/DiscordRestClient.cs View File

@@ -107,6 +107,11 @@ 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.AddRoleAsync(this, guildId, userId, roleId);

//IDiscordClient
/// <inheritdoc />


Loading…
Cancel
Save