@@ -20,9 +20,9 @@ namespace Discord | |||
/// <param name="maxUses"> The max amount of times this invite may be used. Set to null to have unlimited uses. </param> | |||
/// <param name="isTemporary"> If true, a user accepting this invite will be kicked from the guild after closing their client. </param> | |||
/// <param name="withXkcd"> If true, creates a human-readable link. Not supported if maxAge is set to null. </param> | |||
Task<IGuildInvite> CreateInvite(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false, bool withXkcd = false); | |||
Task<IInviteMetadata> CreateInvite(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false, bool withXkcd = false); | |||
/// <summary> Returns a collection of all invites to this channel. </summary> | |||
Task<IEnumerable<IGuildInvite>> GetInvites(); | |||
Task<IEnumerable<IInviteMetadata>> GetInvites(); | |||
/// <summary> Gets a collection of permission overwrites for this channel. </summary> | |||
IReadOnlyDictionary<ulong, Overwrite> PermissionOverwrites { get; } | |||
@@ -70,13 +70,13 @@ namespace Discord | |||
Task<IVoiceChannel> CreateVoiceChannel(string name); | |||
/// <summary> Gets a collection of all invites to this guild. </summary> | |||
Task<IEnumerable<IGuildInvite>> GetInvites(); | |||
Task<IEnumerable<IInviteMetadata>> GetInvites(); | |||
/// <summary> Creates a new invite to this guild. </summary> | |||
/// <param name="maxAge"> The time (in seconds) until the invite expires. Set to null to never expire. </param> | |||
/// <param name="maxUses"> The max amount of times this invite may be used. Set to null to have unlimited uses. </param> | |||
/// <param name="isTemporary"> If true, a user accepting this invite will be kicked from the guild after closing their client. </param> | |||
/// <param name="withXkcd"> If true, creates a human-readable link. Not supported if maxAge is set to null. </param> | |||
Task<IGuildInvite> CreateInvite(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false, bool withXkcd = false); | |||
Task<IInviteMetadata> CreateInvite(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false, bool withXkcd = false); | |||
/// <summary> Gets a collection of all roles in this guild. </summary> | |||
Task<IEnumerable<IRole>> GetRoles(); | |||
@@ -1,6 +1,6 @@ | |||
namespace Discord | |||
{ | |||
public interface IGuildInvite : IDeletable, IInvite | |||
public interface IInviteMetadata : IDeletable, IInvite | |||
{ | |||
/// <summary> Returns true if this invite was revoked. </summary> | |||
bool IsRevoked { get; } | |||
@@ -12,8 +12,5 @@ | |||
int? MaxUses { get; } | |||
/// <summary> Gets the amount of times this invite has been used. </summary> | |||
int Uses { get; } | |||
/// <summary> Gets the guild this invite is linked to. </summary> | |||
IGuild Guild { get; } | |||
} | |||
} |
@@ -1,10 +0,0 @@ | |||
namespace Discord | |||
{ | |||
public interface IPublicInvite : IInvite | |||
{ | |||
/// <summary> Gets the name of the the channel this invite is linked to. </summary> | |||
string ChannelName { get; } | |||
/// <summary> Gets the name of the guild this invite is linked to. </summary> | |||
string GuildName { get; } | |||
} | |||
} |
@@ -3,33 +3,43 @@ using Model = Discord.API.Invite; | |||
namespace Discord | |||
{ | |||
public abstract class Invite : IInvite | |||
public class Invite : IInvite | |||
{ | |||
protected ulong _guildId, _channelId; | |||
/// <inheritdoc /> | |||
public string Code { get; } | |||
internal IDiscordClient Discord { get; } | |||
/// <inheritdoc /> | |||
public ulong GuildId { get; private set; } | |||
/// <inheritdoc /> | |||
public ulong ChannelId { get; private set; } | |||
/// <inheritdoc /> | |||
public string XkcdCode { get; private set; } | |||
/// <inheritdoc /> | |||
public string GuildName { get; private set; } | |||
/// <inheritdoc /> | |||
public string XkcdCode { get; } | |||
public string ChannelName { get; private set; } | |||
/// <inheritdoc /> | |||
public string Url => $"{DiscordConfig.InviteUrl}/{XkcdCode ?? Code}"; | |||
/// <inheritdoc /> | |||
public string XkcdUrl => XkcdCode != null ? $"{DiscordConfig.InviteUrl}/{XkcdCode}" : null; | |||
internal abstract IDiscordClient Discord { get; } | |||
internal Invite(Model model) | |||
internal Invite(IDiscordClient discord, Model model) | |||
{ | |||
Discord = discord; | |||
Code = model.Code; | |||
XkcdCode = model.XkcdPass; | |||
Update(model); | |||
} | |||
protected virtual void Update(Model model) | |||
{ | |||
_guildId = model.Guild.Id; | |||
_channelId = model.Channel.Id; | |||
XkcdCode = model.XkcdPass; | |||
GuildId = model.Guild.Id; | |||
ChannelId = model.Channel.Id; | |||
GuildName = model.Guild.Name; | |||
ChannelName = model.Channel.Name; | |||
} | |||
/// <inheritdoc /> | |||
@@ -38,11 +48,15 @@ namespace Discord | |||
await Discord.BaseClient.AcceptInvite(Code).ConfigureAwait(false); | |||
} | |||
/// <inheritdoc /> | |||
public async Task Delete() | |||
{ | |||
await Discord.BaseClient.DeleteInvite(Code).ConfigureAwait(false); | |||
} | |||
/// <inheritdoc /> | |||
public override string ToString() => XkcdUrl ?? Url; | |||
string IEntity<string>.Id => Code; | |||
ulong IInvite.GuildId => _guildId; | |||
ulong IInvite.ChannelId => _channelId; | |||
} | |||
} |
@@ -0,0 +1,32 @@ | |||
using Model = Discord.API.InviteMetadata; | |||
namespace Discord | |||
{ | |||
public class InviteMetadata : Invite, IInviteMetadata | |||
{ | |||
/// <inheritdoc /> | |||
public bool IsRevoked { get; private set; } | |||
/// <inheritdoc /> | |||
public bool IsTemporary { get; private set; } | |||
/// <inheritdoc /> | |||
public int? MaxAge { get; private set; } | |||
/// <inheritdoc /> | |||
public int? MaxUses { get; private set; } | |||
/// <inheritdoc /> | |||
public int Uses { get; private set; } | |||
internal InviteMetadata(IDiscordClient client, Model model) | |||
: base(client, model) | |||
{ | |||
Update(model); | |||
} | |||
private void Update(Model model) | |||
{ | |||
IsRevoked = model.Revoked; | |||
IsTemporary = model.Temporary; | |||
MaxAge = model.MaxAge != 0 ? model.MaxAge : (int?)null; | |||
MaxUses = model.MaxUses; | |||
Uses = model.Uses; | |||
} | |||
} | |||
} |
@@ -1,39 +0,0 @@ | |||
using System.Threading.Tasks; | |||
using Model = Discord.API.Invite; | |||
namespace Discord.Rest | |||
{ | |||
public class PublicInvite : Invite, IPublicInvite | |||
{ | |||
/// <inheritdoc /> | |||
public string GuildName { get; private set; } | |||
/// <inheritdoc /> | |||
public string ChannelName { get; private set; } | |||
/// <inheritdoc /> | |||
public ulong GuildId => _guildId; | |||
/// <inheritdoc /> | |||
public ulong ChannelId => _channelId; | |||
internal override IDiscordClient Discord { get; } | |||
internal PublicInvite(IDiscordClient discord, Model model) | |||
: base(model) | |||
{ | |||
Discord = discord; | |||
} | |||
protected override void Update(Model model) | |||
{ | |||
base.Update(model); | |||
GuildName = model.Guild.Name; | |||
ChannelName = model.Channel.Name; | |||
} | |||
/// <inheritdoc /> | |||
public async Task Update() | |||
{ | |||
var model = await Discord.BaseClient.GetInvite(Code).ConfigureAwait(false); | |||
Update(model); | |||
} | |||
} | |||
} |
@@ -118,7 +118,6 @@ | |||
<Compile Include="Common\Entities\Guilds\IGuildEmbed.cs" /> | |||
<Compile Include="Common\Entities\Users\IConnection.cs" /> | |||
<Compile Include="Common\Entities\Guilds\IGuildIntegration.cs" /> | |||
<Compile Include="Common\Entities\Invites\IPublicInvite.cs" /> | |||
<Compile Include="Common\Entities\Messages\Attachment.cs" /> | |||
<Compile Include="Common\Entities\Channels\IChannel.cs" /> | |||
<Compile Include="Common\Entities\Channels\IDMChannel.cs" /> | |||
@@ -139,7 +138,7 @@ | |||
<Compile Include="Common\Entities\Guilds\IGuild.cs" /> | |||
<Compile Include="Common\Entities\IMentionable.cs" /> | |||
<Compile Include="Common\Entities\Messages\IMessage.cs" /> | |||
<Compile Include="Common\Entities\Invites\IGuildInvite.cs" /> | |||
<Compile Include="Common\Entities\Invites\IInviteMetadata.cs" /> | |||
<Compile Include="Common\Entities\Invites\IInvite.cs" /> | |||
<Compile Include="Common\Entities\Roles\IRole.cs" /> | |||
<Compile Include="Common\Entities\ISnowflakeEntity.cs" /> | |||
@@ -168,9 +167,7 @@ | |||
<Compile Include="Common\Entities\Guilds\IntegrationAccount.cs" /> | |||
<Compile Include="Common\Entities\Users\Connection.cs" /> | |||
<Compile Include="Common\Helpers\PermissionHelper.cs" /> | |||
<Compile Include="Rest\Entities\Invites\GuildInvite.cs" /> | |||
<Compile Include="Common\Entities\Invites\Invite.cs" /> | |||
<Compile Include="Common\Entities\Invites\PublicInvite.cs" /> | |||
<Compile Include="Rest\Entities\Message.cs" /> | |||
<Compile Include="Rest\Entities\Role.cs" /> | |||
<Compile Include="Rest\Entities\Guilds\UserGuild.cs" /> | |||
@@ -217,7 +214,7 @@ | |||
<Compile Include="WebSocket\Entities\Channels\VoiceChannel.cs" /> | |||
<Compile Include="WebSocket\Entities\Guilds\Guild.cs" /> | |||
<Compile Include="WebSocket\Entities\Guilds\GuildIntegration.cs" /> | |||
<Compile Include="WebSocket\Entities\Invites\GuildInvite.cs" /> | |||
<Compile Include="Common\Entities\Invites\InviteMetadata.cs" /> | |||
<Compile Include="WebSocket\Entities\Users\DMUser.cs" /> | |||
<Compile Include="WebSocket\Entities\Users\GuildUser.cs" /> | |||
<Compile Include="WebSocket\Entities\Users\PublicUser.cs" /> | |||
@@ -27,7 +27,7 @@ namespace Discord | |||
Task<IEnumerable<IUserGuild>> GetGuilds(); | |||
Task<IGuild> CreateGuild(string name, IVoiceRegion region, Stream jpegIcon = null); | |||
Task<IPublicInvite> GetInvite(string inviteIdOrXkcd); | |||
Task<IInvite> GetInvite(string inviteIdOrXkcd); | |||
Task<IUser> GetUser(ulong id); | |||
Task<IUser> GetUser(string username, ushort discriminator); | |||
@@ -168,11 +168,11 @@ namespace Discord.Rest | |||
return models.Select(x => new DMChannel(this, x)); | |||
} | |||
public async Task<PublicInvite> GetInvite(string inviteIdOrXkcd) | |||
public async Task<Invite> GetInvite(string inviteIdOrXkcd) | |||
{ | |||
var model = await BaseClient.GetInvite(inviteIdOrXkcd).ConfigureAwait(false); | |||
if (model != null) | |||
return new PublicInvite(this, model); | |||
return new Invite(this, model); | |||
return null; | |||
} | |||
@@ -269,7 +269,7 @@ namespace Discord.Rest | |||
=> await GetDMChannels().ConfigureAwait(false); | |||
async Task<IEnumerable<IConnection>> IDiscordClient.GetConnections() | |||
=> await GetConnections().ConfigureAwait(false); | |||
async Task<IPublicInvite> IDiscordClient.GetInvite(string inviteIdOrXkcd) | |||
async Task<IInvite> IDiscordClient.GetInvite(string inviteIdOrXkcd) | |||
=> await GetInvite(inviteIdOrXkcd).ConfigureAwait(false); | |||
async Task<IGuild> IDiscordClient.GetGuild(ulong id) | |||
=> await GetGuild(id).ConfigureAwait(false); | |||
@@ -81,10 +81,10 @@ namespace Discord.Rest | |||
return null; | |||
} | |||
/// <summary> Downloads a collection of all invites to this channel. </summary> | |||
public async Task<IEnumerable<GuildInvite>> GetInvites() | |||
public async Task<IEnumerable<InviteMetadata>> GetInvites() | |||
{ | |||
var models = await Discord.BaseClient.GetChannelInvites(Id).ConfigureAwait(false); | |||
return models.Select(x => new GuildInvite(Guild, x)); | |||
return models.Select(x => new InviteMetadata(Discord, x)); | |||
} | |||
/// <inheritdoc /> | |||
@@ -123,7 +123,7 @@ namespace Discord.Rest | |||
/// <param name="maxUses"> The max amount of times this invite may be used. Set to null to have unlimited uses. </param> | |||
/// <param name="isTemporary"> If true, a user accepting this invite will be kicked from the guild after closing their client. </param> | |||
/// <param name="withXkcd"> If true, creates a human-readable link. Not supported if maxAge is set to null. </param> | |||
public async Task<GuildInvite> CreateInvite(int? maxAge = 1800, int? maxUses = null, bool isTemporary = false, bool withXkcd = false) | |||
public async Task<InviteMetadata> CreateInvite(int? maxAge = 1800, int? maxUses = null, bool isTemporary = false, bool withXkcd = false) | |||
{ | |||
var args = new CreateChannelInviteParams | |||
{ | |||
@@ -133,7 +133,7 @@ namespace Discord.Rest | |||
XkcdPass = withXkcd | |||
}; | |||
var model = await Discord.BaseClient.CreateChannelInvite(Id, args).ConfigureAwait(false); | |||
return new GuildInvite(Guild, model); | |||
return new InviteMetadata(Discord, model); | |||
} | |||
/// <inheritdoc /> | |||
@@ -149,9 +149,9 @@ namespace Discord.Rest | |||
} | |||
IGuild IGuildChannel.Guild => Guild; | |||
async Task<IGuildInvite> IGuildChannel.CreateInvite(int? maxAge, int? maxUses, bool isTemporary, bool withXkcd) | |||
async Task<IInviteMetadata> IGuildChannel.CreateInvite(int? maxAge, int? maxUses, bool isTemporary, bool withXkcd) | |||
=> await CreateInvite(maxAge, maxUses, isTemporary, withXkcd).ConfigureAwait(false); | |||
async Task<IEnumerable<IGuildInvite>> IGuildChannel.GetInvites() | |||
async Task<IEnumerable<IInviteMetadata>> IGuildChannel.GetInvites() | |||
=> await GetInvites().ConfigureAwait(false); | |||
async Task<IEnumerable<IGuildUser>> IGuildChannel.GetUsers() | |||
=> await GetUsers().ConfigureAwait(false); | |||
@@ -231,13 +231,13 @@ namespace Discord.Rest | |||
} | |||
/// <summary> Gets a collection of all invites to this guild. </summary> | |||
public async Task<IEnumerable<GuildInvite>> GetInvites() | |||
public async Task<IEnumerable<InviteMetadata>> GetInvites() | |||
{ | |||
var models = await Discord.BaseClient.GetGuildInvites(Id).ConfigureAwait(false); | |||
return models.Select(x => new GuildInvite(this, x)); | |||
return models.Select(x => new InviteMetadata(Discord, x)); | |||
} | |||
/// <summary> Creates a new invite to this guild. </summary> | |||
public async Task<GuildInvite> CreateInvite(int? maxAge = 1800, int? maxUses = null, bool isTemporary = false, bool withXkcd = false) | |||
public async Task<InviteMetadata> CreateInvite(int? maxAge = 1800, int? maxUses = null, bool isTemporary = false, bool withXkcd = false) | |||
{ | |||
if (maxAge <= 0) throw new ArgumentOutOfRangeException(nameof(maxAge)); | |||
if (maxUses <= 0) throw new ArgumentOutOfRangeException(nameof(maxUses)); | |||
@@ -250,7 +250,7 @@ namespace Discord.Rest | |||
XkcdPass = withXkcd | |||
}; | |||
var model = await Discord.BaseClient.CreateChannelInvite(DefaultChannelId, args).ConfigureAwait(false); | |||
return new GuildInvite(this, model); | |||
return new InviteMetadata(Discord, model); | |||
} | |||
/// <summary> Gets the role in this guild with the provided id, or null if not found. </summary> | |||
@@ -344,7 +344,7 @@ namespace Discord.Rest | |||
=> await GetChannel(id).ConfigureAwait(false); | |||
async Task<IEnumerable<IGuildChannel>> IGuild.GetChannels() | |||
=> await GetChannels().ConfigureAwait(false); | |||
async Task<IGuildInvite> IGuild.CreateInvite(int? maxAge, int? maxUses, bool isTemporary, bool withXkcd) | |||
async Task<IInviteMetadata> IGuild.CreateInvite(int? maxAge, int? maxUses, bool isTemporary, bool withXkcd) | |||
=> await CreateInvite(maxAge, maxUses, isTemporary, withXkcd).ConfigureAwait(false); | |||
async Task<IRole> IGuild.CreateRole(string name, GuildPermissions? permissions, Color? color, bool isHoisted) | |||
=> await CreateRole(name, permissions, color, isHoisted).ConfigureAwait(false); | |||
@@ -352,7 +352,7 @@ namespace Discord.Rest | |||
=> await CreateTextChannel(name).ConfigureAwait(false); | |||
async Task<IVoiceChannel> IGuild.CreateVoiceChannel(string name) | |||
=> await CreateVoiceChannel(name).ConfigureAwait(false); | |||
async Task<IEnumerable<IGuildInvite>> IGuild.GetInvites() | |||
async Task<IEnumerable<IInviteMetadata>> IGuild.GetInvites() | |||
=> await GetInvites().ConfigureAwait(false); | |||
Task<IRole> IGuild.GetRole(ulong id) | |||
=> Task.FromResult<IRole>(GetRole(id)); | |||
@@ -1,52 +0,0 @@ | |||
using System.Threading.Tasks; | |||
using Model = Discord.API.InviteMetadata; | |||
namespace Discord.Rest | |||
{ | |||
public class GuildInvite : Invite, IGuildInvite | |||
{ | |||
/// <summary> Gets the guild this invite is linked to. </summary> | |||
public Guild Guild { get; private set; } | |||
/// <inheritdoc /> | |||
public ulong ChannelId { get; private set; } | |||
/// <inheritdoc /> | |||
public bool IsRevoked { get; private set; } | |||
/// <inheritdoc /> | |||
public bool IsTemporary { get; private set; } | |||
/// <inheritdoc /> | |||
public int? MaxAge { get; private set; } | |||
/// <inheritdoc /> | |||
public int? MaxUses { get; private set; } | |||
/// <inheritdoc /> | |||
public int Uses { get; private set; } | |||
internal override IDiscordClient Discord => Guild.Discord; | |||
internal GuildInvite(Guild guild, Model model) | |||
: base(model) | |||
{ | |||
Guild = guild; | |||
Update(model); //Causes base.Update(Model) to be run twice, but that's fine. | |||
} | |||
private void Update(Model model) | |||
{ | |||
base.Update(model); | |||
IsRevoked = model.Revoked; | |||
IsTemporary = model.Temporary; | |||
MaxAge = model.MaxAge != 0 ? model.MaxAge : (int?)null; | |||
MaxUses = model.MaxUses; | |||
Uses = model.Uses; | |||
} | |||
/// <inheritdoc /> | |||
public async Task Delete() | |||
{ | |||
await Discord.BaseClient.DeleteInvite(Code).ConfigureAwait(false); | |||
} | |||
IGuild IGuildInvite.Guild => Guild; | |||
ulong IInvite.GuildId => Guild.Id; | |||
} | |||
} |
@@ -86,7 +86,7 @@ namespace Discord.WebSocket | |||
throw new NotImplementedException(); | |||
} | |||
public Task<IPublicInvite> GetInvite(string inviteIdOrXkcd) | |||
public Task<IInvite> GetInvite(string inviteIdOrXkcd) | |||
{ | |||
throw new NotImplementedException(); | |||
} | |||
@@ -80,10 +80,10 @@ namespace Discord.WebSocket | |||
return null; | |||
} | |||
/// <summary> Downloads a collection of all invites to this channel. </summary> | |||
public async Task<IEnumerable<GuildInvite>> GetInvites() | |||
public async Task<IEnumerable<InviteMetadata>> GetInvites() | |||
{ | |||
var models = await Discord.BaseClient.GetChannelInvites(Id).ConfigureAwait(false); | |||
return models.Select(x => new GuildInvite(Guild, x)); | |||
return models.Select(x => new InviteMetadata(Discord, x)); | |||
} | |||
/// <inheritdoc /> | |||
@@ -114,7 +114,7 @@ namespace Discord.WebSocket | |||
/// <param name="maxUses"> The max amount of times this invite may be used. Set to null to have unlimited uses. </param> | |||
/// <param name="isTemporary"> If true, a user accepting this invite will be kicked from the guild after closing their client. </param> | |||
/// <param name="withXkcd"> If true, creates a human-readable link. Not supported if maxAge is set to null. </param> | |||
public async Task<GuildInvite> CreateInvite(int? maxAge = 1800, int? maxUses = null, bool isTemporary = false, bool withXkcd = false) | |||
public async Task<InviteMetadata> CreateInvite(int? maxAge = 1800, int? maxUses = null, bool isTemporary = false, bool withXkcd = false) | |||
{ | |||
var args = new CreateChannelInviteParams | |||
{ | |||
@@ -124,7 +124,7 @@ namespace Discord.WebSocket | |||
XkcdPass = withXkcd | |||
}; | |||
var model = await Discord.BaseClient.CreateChannelInvite(Id, args).ConfigureAwait(false); | |||
return new GuildInvite(Guild, model); | |||
return new InviteMetadata(Discord, model); | |||
} | |||
/// <inheritdoc /> | |||
@@ -134,9 +134,9 @@ namespace Discord.WebSocket | |||
} | |||
IGuild IGuildChannel.Guild => Guild; | |||
async Task<IGuildInvite> IGuildChannel.CreateInvite(int? maxAge, int? maxUses, bool isTemporary, bool withXkcd) | |||
async Task<IInviteMetadata> IGuildChannel.CreateInvite(int? maxAge, int? maxUses, bool isTemporary, bool withXkcd) | |||
=> await CreateInvite(maxAge, maxUses, isTemporary, withXkcd).ConfigureAwait(false); | |||
async Task<IEnumerable<IGuildInvite>> IGuildChannel.GetInvites() | |||
async Task<IEnumerable<IInviteMetadata>> IGuildChannel.GetInvites() | |||
=> await GetInvites().ConfigureAwait(false); | |||
Task<IEnumerable<IGuildUser>> IGuildChannel.GetUsers() | |||
=> Task.FromResult<IEnumerable<IGuildUser>>(Users); | |||
@@ -224,13 +224,13 @@ namespace Discord.WebSocket | |||
} | |||
/// <summary> Gets a collection of all invites to this guild. </summary> | |||
public async Task<IEnumerable<GuildInvite>> GetInvites() | |||
public async Task<IEnumerable<InviteMetadata>> GetInvites() | |||
{ | |||
var models = await Discord.BaseClient.GetGuildInvites(Id).ConfigureAwait(false); | |||
return models.Select(x => new GuildInvite(this, x)); | |||
return models.Select(x => new InviteMetadata(Discord, x)); | |||
} | |||
/// <summary> Creates a new invite to this guild. </summary> | |||
public async Task<GuildInvite> CreateInvite(int? maxAge = 1800, int? maxUses = null, bool isTemporary = false, bool withXkcd = false) | |||
public async Task<InviteMetadata> CreateInvite(int? maxAge = 1800, int? maxUses = null, bool isTemporary = false, bool withXkcd = false) | |||
{ | |||
if (maxAge <= 0) throw new ArgumentOutOfRangeException(nameof(maxAge)); | |||
if (maxUses <= 0) throw new ArgumentOutOfRangeException(nameof(maxUses)); | |||
@@ -243,7 +243,7 @@ namespace Discord.WebSocket | |||
XkcdPass = withXkcd | |||
}; | |||
var model = await Discord.BaseClient.CreateChannelInvite(DefaultChannelId, args).ConfigureAwait(false); | |||
return new GuildInvite(this, model); | |||
return new InviteMetadata(Discord, model); | |||
} | |||
/// <summary> Gets the role in this guild with the provided id, or null if not found. </summary> | |||
@@ -337,7 +337,7 @@ namespace Discord.WebSocket | |||
=> await GetChannel(id).ConfigureAwait(false); | |||
async Task<IEnumerable<IGuildChannel>> IGuild.GetChannels() | |||
=> await GetChannels().ConfigureAwait(false); | |||
async Task<IGuildInvite> IGuild.CreateInvite(int? maxAge, int? maxUses, bool isTemporary, bool withXkcd) | |||
async Task<IInviteMetadata> IGuild.CreateInvite(int? maxAge, int? maxUses, bool isTemporary, bool withXkcd) | |||
=> await CreateInvite(maxAge, maxUses, isTemporary, withXkcd).ConfigureAwait(false); | |||
async Task<IRole> IGuild.CreateRole(string name, GuildPermissions? permissions, Color? color, bool isHoisted) | |||
=> await CreateRole(name, permissions, color, isHoisted).ConfigureAwait(false); | |||
@@ -345,7 +345,7 @@ namespace Discord.WebSocket | |||
=> await CreateTextChannel(name).ConfigureAwait(false); | |||
async Task<IVoiceChannel> IGuild.CreateVoiceChannel(string name) | |||
=> await CreateVoiceChannel(name).ConfigureAwait(false); | |||
async Task<IEnumerable<IGuildInvite>> IGuild.GetInvites() | |||
async Task<IEnumerable<IInviteMetadata>> IGuild.GetInvites() | |||
=> await GetInvites().ConfigureAwait(false); | |||
Task<IRole> IGuild.GetRole(ulong id) | |||
=> Task.FromResult<IRole>(GetRole(id)); | |||
@@ -1,52 +0,0 @@ | |||
using System.Threading.Tasks; | |||
using Model = Discord.API.InviteMetadata; | |||
namespace Discord.WebSocket | |||
{ | |||
public class GuildInvite : Invite, IGuildInvite | |||
{ | |||
/// <summary> Gets the guild this invite is linked to. </summary> | |||
public Guild Guild { get; private set; } | |||
/// <inheritdoc /> | |||
public ulong ChannelId { get; private set; } | |||
/// <inheritdoc /> | |||
public bool IsRevoked { get; private set; } | |||
/// <inheritdoc /> | |||
public bool IsTemporary { get; private set; } | |||
/// <inheritdoc /> | |||
public int? MaxAge { get; private set; } | |||
/// <inheritdoc /> | |||
public int? MaxUses { get; private set; } | |||
/// <inheritdoc /> | |||
public int Uses { get; private set; } | |||
internal override IDiscordClient Discord => Guild.Discord; | |||
internal GuildInvite(Guild guild, Model model) | |||
: base(model) | |||
{ | |||
Guild = guild; | |||
Update(model); //Causes base.Update(Model) to be run twice, but that's fine. | |||
} | |||
private void Update(Model model) | |||
{ | |||
base.Update(model); | |||
IsRevoked = model.Revoked; | |||
IsTemporary = model.Temporary; | |||
MaxAge = model.MaxAge != 0 ? model.MaxAge : (int?)null; | |||
MaxUses = model.MaxUses; | |||
Uses = model.Uses; | |||
} | |||
/// <inheritdoc /> | |||
public async Task Delete() | |||
{ | |||
await Discord.BaseClient.DeleteInvite(Code).ConfigureAwait(false); | |||
} | |||
IGuild IGuildInvite.Guild => Guild; | |||
ulong IInvite.GuildId => Guild.Id; | |||
} | |||
} |