@@ -1,4 +1,5 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Model = Discord.API.Invite;
using Model = Discord.API.Invite;
@@ -11,17 +12,21 @@ namespace Discord.Rest
public string GuildName { get; private set; }
public string GuildName { get; private set; }
public ulong ChannelId { get; private set; }
public ulong ChannelId { get; private set; }
public ulong GuildId { get; private set; }
public ulong GuildId { get; private set; }
internal IChannel Channel { get; private set; }
internal IGuild Guild { get; private set; }
public string Code => Id;
public string Code => Id;
public string Url => $"{DiscordConfig.InviteUrl}/{Code}";
public string Url => $"{DiscordConfig.InviteUrl}/{Code}";
internal RestInvite(BaseDiscordClient discord, string id)
internal RestInvite(BaseDiscordClient discord, IGuild guild, IChannel channel, string id)
: base(discord, id)
: base(discord, id)
{
{
Guild = guild;
Channel = channel;
}
}
internal static RestInvite Create(BaseDiscordClient discord, Model model)
internal static RestInvite Create(BaseDiscordClient discord, IGuild guild, IChannel channel, Model model)
{
{
var entity = new RestInvite(discord, model.Code);
var entity = new RestInvite(discord, guild, channel, model.Code);
entity.Update(model);
entity.Update(model);
return entity;
return entity;
}
}
@@ -46,7 +51,27 @@ namespace Discord.Rest
public override string ToString() => Url;
public override string ToString() => Url;
private string DebuggerDisplay => $"{Url} ({GuildName} / {ChannelName})";
private string DebuggerDisplay => $"{Url} ({GuildName} / {ChannelName})";
string IEntity<string>.Id => Code;
IGuild IInvite.Guild
{
get
{
if (Guild != null)
return Guild;
var guildChannel = Channel as IGuildChannel;
if (guildChannel != null)
return guildChannel.Guild; //If it fails, it'll still return this exception
throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object.");
}
}
IChannel IInvite.Channel
{
get
{
if (Channel != null)
return Channel;
throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object.");
}
}
}
}
}
}