Fix/Implement various invite-related behaviors (#1023)
* Initial support for invite member count arg * Fix IDiscordClient#GetInviteAsync behavior - Previously, the GetInviteAsync method would return null since it couldn't be parsed as a simple RestInvite object. The object should be a RestInviteMetadata instead. * Fix methods that didn't comply with the interface * Change with_counts REST behaviour * Remove unnecessary JSON prop * Remove AcceptAsync
This commit is contained in:
@@ -1,14 +1,9 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord.Rest
|
||||
{
|
||||
internal static class InviteHelper
|
||||
{
|
||||
public static async Task AcceptAsync(IInvite invite, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.AcceptInviteAsync(invite.Code, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task DeleteAsync(IInvite invite, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
|
||||
@@ -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,19 +39,21 @@ 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)
|
||||
=> InviteHelper.DeleteAsync(this, Discord, options);
|
||||
|
||||
public Task AcceptAsync(RequestOptions options = null)
|
||||
=> InviteHelper.AcceptAsync(this, Discord, options);
|
||||
|
||||
public override string ToString() => Url;
|
||||
private string DebuggerDisplay => $"{Url} ({GuildName} / {ChannelName})";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user