Browse Source

Initial support for invite member count arg

pull/1023/head
Hsu Still 8 years ago
parent
commit
e0e8816489
9 changed files with 44 additions and 14 deletions
  1. +5
    -1
      src/Discord.Net.Core/Entities/Invites/IInvite.cs
  2. +1
    -1
      src/Discord.Net.Core/IDiscordClient.cs
  3. +5
    -1
      src/Discord.Net.Rest/API/Common/Invite.cs
  4. +10
    -0
      src/Discord.Net.Rest/API/Rest/GetInviteParams.cs
  5. +1
    -1
      src/Discord.Net.Rest/BaseDiscordClient.cs
  6. +6
    -2
      src/Discord.Net.Rest/ClientHelper.cs
  7. +2
    -2
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  8. +4
    -4
      src/Discord.Net.Rest/DiscordRestClient.cs
  9. +10
    -2
      src/Discord.Net.Rest/Entities/Invites/RestInvite.cs

+ 5
- 1
src/Discord.Net.Core/Entities/Invites/IInvite.cs View File

@@ -1,4 +1,4 @@
using System.Threading.Tasks;
using System.Threading.Tasks;

namespace Discord
{
@@ -22,6 +22,10 @@ namespace Discord
ulong GuildId { get; }
/// <summary> Gets the name of the guild this invite is linked to. </summary>
string GuildName { get; }
/// <summary> Gets the approximated count of online members in the guild. </summary>
int? PresenceCount { get; }
/// <summary> Gets the approximated count of total members in the guild. </summary>
int? MemberCount { get; }

/// <summary> Accepts this invite and joins the target guild. This will fail on bot accounts. </summary>
Task AcceptAsync(RequestOptions options = null);


+ 1
- 1
src/Discord.Net.Core/IDiscordClient.cs View File

@@ -27,7 +27,7 @@ namespace Discord
Task<IReadOnlyCollection<IGuild>> GetGuildsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
Task<IGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null, RequestOptions options = null);
Task<IInvite> GetInviteAsync(string inviteId, RequestOptions options = null);
Task<IInvite> GetInviteAsync(string inviteId, bool withCount = false, RequestOptions options = null);

Task<IUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
Task<IUser> GetUserAsync(string username, string discriminator, RequestOptions options = null);


+ 5
- 1
src/Discord.Net.Rest/API/Common/Invite.cs View File

@@ -1,4 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable CS1591
using Newtonsoft.Json;

namespace Discord.API
@@ -11,5 +11,9 @@ namespace Discord.API
public InviteGuild Guild { get; set; }
[JsonProperty("channel")]
public InviteChannel Channel { get; set; }
[JsonProperty("approximate_presence_count")]
public Optional<int?> PresenceCount { get; set; }
[JsonProperty("approximate_member_count")]
public Optional<int?> MemberCount { get; set; }
}
}

+ 10
- 0
src/Discord.Net.Rest/API/Rest/GetInviteParams.cs View File

@@ -0,0 +1,10 @@
using Newtonsoft.Json;

namespace Discord.API.Rest
{
internal class GetInviteParams
{
[JsonProperty("with_counts")]
public Optional<bool?> WithCounts { get; set; }
}
}

+ 1
- 1
src/Discord.Net.Rest/BaseDiscordClient.cs View File

@@ -148,7 +148,7 @@ namespace Discord.Rest
Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync(RequestOptions options)
=> Task.FromResult<IReadOnlyCollection<IConnection>>(ImmutableArray.Create<IConnection>());

Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId, RequestOptions options)
Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId, bool withCount, RequestOptions options)
=> Task.FromResult<IInvite>(null);

Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode, RequestOptions options)


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

@@ -51,9 +51,13 @@ namespace Discord.Rest
}
public static async Task<RestInvite> GetInviteAsync(BaseDiscordClient client,
string inviteId, RequestOptions options)
string inviteId, bool withCount, RequestOptions options)
{
var model = await client.ApiClient.GetInviteAsync(inviteId, options).ConfigureAwait(false);
var args = new GetInviteParams
{
WithCounts = withCount
};
var model = await client.ApiClient.GetInviteAsync(inviteId, args, options).ConfigureAwait(false);
if (model != null)
return RestInvite.Create(client, null, null, model);
return null;


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

@@ -897,7 +897,7 @@ namespace Discord.API
}

//Guild Invites
public async Task<Invite> GetInviteAsync(string inviteId, RequestOptions options = null)
public async Task<Invite> GetInviteAsync(string inviteId, GetInviteParams args, RequestOptions options = null)
{
Preconditions.NotNullOrEmpty(inviteId, nameof(inviteId));
options = RequestOptions.CreateOrClone(options);
@@ -912,7 +912,7 @@ namespace Discord.API

try
{
return await SendAsync<Invite>("GET", () => $"invites/{inviteId}", new BucketIds(), options: options).ConfigureAwait(false);
return await SendJsonAsync<Invite>("GET", () => $"invites/{inviteId}", args, new BucketIds(), options: options).ConfigureAwait(false);
}
catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; }
}


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

@@ -56,8 +56,8 @@ namespace Discord.Rest
=> ClientHelper.GetConnectionsAsync(this, options);

/// <inheritdoc />
public Task<RestInvite> GetInviteAsync(string inviteId, RequestOptions options = null)
=> ClientHelper.GetInviteAsync(this, inviteId, options);
public Task<RestInvite> GetInviteAsync(string inviteId, bool withCount = false, RequestOptions options = null)
=> ClientHelper.GetInviteAsync(this, inviteId, withCount, options);

/// <inheritdoc />
public Task<RestGuild> GetGuildAsync(ulong id, RequestOptions options = null)
@@ -131,8 +131,8 @@ namespace Discord.Rest
async Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync(RequestOptions options)
=> await GetConnectionsAsync(options).ConfigureAwait(false);

async Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId, RequestOptions options)
=> await GetInviteAsync(inviteId, options).ConfigureAwait(false);
async Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId, bool withCount, RequestOptions options)
=> await GetInviteAsync(inviteId, withCount, options).ConfigureAwait(false);

async Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode, RequestOptions options)
{


+ 10
- 2
src/Discord.Net.Rest/Entities/Invites/RestInvite.cs View File

@@ -1,6 +1,7 @@
using System;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Discord.API.Rest;
using Model = Discord.API.Invite;

namespace Discord.Rest
@@ -10,6 +11,8 @@ namespace Discord.Rest
{
public string ChannelName { get; private set; }
public string GuildName { get; private set; }
public int? PresenceCount { get; private set; }
public int? MemberCount { get; private set; }
public ulong ChannelId { get; private set; }
public ulong GuildId { get; private set; }
internal IChannel Channel { get; private set; }
@@ -36,11 +39,16 @@ namespace Discord.Rest
ChannelId = model.Channel.Id;
GuildName = model.Guild.Name;
ChannelName = model.Channel.Name;
MemberCount = model.MemberCount.IsSpecified ? model.MemberCount.Value : null;
PresenceCount = model.PresenceCount.IsSpecified ? model.PresenceCount.Value : null;
}
public async Task UpdateAsync(RequestOptions options = null)
{
var model = await Discord.ApiClient.GetInviteAsync(Code, options).ConfigureAwait(false);
var args = new GetInviteParams();
if (MemberCount != null || PresenceCount != null)
args.WithCounts = true;
var model = await Discord.ApiClient.GetInviteAsync(Code, args, options).ConfigureAwait(false);
Update(model);
}
public Task DeleteAsync(RequestOptions options = null)


Loading…
Cancel
Save