Browse Source

Add vanity invite support

pull/1094/head
Still Hsu 7 years ago
parent
commit
0bf126088f
No known key found for this signature in database GPG Key ID: 8601A145FDA95209
5 changed files with 47 additions and 0 deletions
  1. +9
    -0
      src/Discord.Net.Core/Entities/Guilds/IGuild.cs
  2. +8
    -0
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  3. +6
    -0
      src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
  4. +12
    -0
      src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
  5. +12
    -0
      src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs

+ 9
- 0
src/Discord.Net.Core/Entities/Guilds/IGuild.cs View File

@@ -120,6 +120,15 @@ namespace Discord

/// <summary> Gets a collection of all invites to this guild. </summary>
Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null);
/// <summary>
/// Gets the vanity invite URL of this guild.
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable <see cref="Task"/> containing the partial metadata of the vanity invite found within
/// this guild.
/// </returns>
Task<IInviteMetadata> GetVanityInviteAsync(RequestOptions options = null);

/// <summary> Gets the role in this guild with the provided id, or null if not found. </summary>
IRole GetRole(ulong id);


+ 8
- 0
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -925,6 +925,14 @@ namespace Discord.API
}
catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; }
}
public async Task<InviteMetadata> GetVanityInviteAsync(ulong guildId, RequestOptions options = null)
{
Preconditions.NotEqual(guildId, 0, nameof(guildId));
options = RequestOptions.CreateOrClone(options);

var ids = new BucketIds(guildId: guildId);
return await SendAsync<InviteMetadata>("GET", () => $"guilds/{guildId}/vanity-url", ids, options: options).ConfigureAwait(false);
}
public async Task<IReadOnlyCollection<InviteMetadata>> GetGuildInvitesAsync(ulong guildId, RequestOptions options = null)
{
Preconditions.NotEqual(guildId, 0, nameof(guildId));


+ 6
- 0
src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs View File

@@ -210,6 +210,12 @@ namespace Discord.Rest
var models = await client.ApiClient.GetGuildInvitesAsync(guild.Id, options).ConfigureAwait(false);
return models.Select(x => RestInviteMetadata.Create(client, guild, null, x)).ToImmutableArray();
}
public static async Task<RestInviteMetadata> GetVanityInviteAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
var model = await client.ApiClient.GetVanityInviteAsync(guild.Id, options).ConfigureAwait(false);
return RestInviteMetadata.Create(client, guild, null, model);
}

//Roles
public static async Task<RestRole> CreateRoleAsync(IGuild guild, BaseDiscordClient client,


+ 12
- 0
src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs View File

@@ -238,6 +238,15 @@ namespace Discord.Rest
//Invites
public Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
=> GuildHelper.GetInvitesAsync(this, Discord, options);
/// <summary>
/// Gets the vanity invite URL of this guild.
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A partial metadata of the vanity invite found within this guild.
/// </returns>
public Task<RestInviteMetadata> GetVanityInviteAsync(RequestOptions options = null)
=> GuildHelper.GetVanityInviteAsync(this, Discord, options);

//Roles
public RestRole GetRole(ulong id)
@@ -397,6 +406,9 @@ namespace Discord.Rest

async Task<IReadOnlyCollection<IInviteMetadata>> IGuild.GetInvitesAsync(RequestOptions options)
=> await GetInvitesAsync(options).ConfigureAwait(false);
/// <inheritdoc />
async Task<IInviteMetadata> IGuild.GetVanityInviteAsync(RequestOptions options)
=> await GetVanityInviteAsync(options).ConfigureAwait(false);

IRole IGuild.GetRole(ulong id)
=> GetRole(id);


+ 12
- 0
src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs View File

@@ -345,6 +345,15 @@ namespace Discord.WebSocket
//Invites
public Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
=> GuildHelper.GetInvitesAsync(this, Discord, options);
/// <summary>
/// Gets the vanity invite URL of this guild.
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A partial metadata of the vanity invite found within this guild.
/// </returns>
public Task<RestInviteMetadata> GetVanityInviteAsync(RequestOptions options = null)
=> GuildHelper.GetVanityInviteAsync(this, Discord, options);

//Roles
public SocketRole GetRole(ulong id)
@@ -700,6 +709,9 @@ namespace Discord.WebSocket

async Task<IReadOnlyCollection<IInviteMetadata>> IGuild.GetInvitesAsync(RequestOptions options)
=> await GetInvitesAsync(options).ConfigureAwait(false);
/// <inheritdoc />
async Task<IInviteMetadata> IGuild.GetVanityInviteAsync(RequestOptions options)
=> await GetVanityInviteAsync(options).ConfigureAwait(false);

IRole IGuild.GetRole(ulong id)
=> GetRole(id);


Loading…
Cancel
Save