@@ -56,13 +56,11 @@ namespace Discord | |||||
/// <summary> | /// <summary> | ||||
/// Gets the guild this invite is linked to. | /// Gets the guild this invite is linked to. | ||||
/// </summary> | /// </summary> | ||||
/// <remarks> | |||||
/// The guild may be partially populated. | |||||
/// </remarks> | |||||
/// <returns> | /// <returns> | ||||
/// A guild object representing the guild that the invite points to. | /// A guild object representing the guild that the invite points to. | ||||
/// </returns> | /// </returns> | ||||
IGuild Guild { get; } | IGuild Guild { get; } | ||||
/// <summary> | /// <summary> | ||||
/// Gets the ID of the guild this invite is linked to. | /// Gets the ID of the guild this invite is linked to. | ||||
/// </summary> | /// </summary> | ||||
@@ -0,0 +1,143 @@ | |||||
using System; | |||||
namespace Discord; | |||||
public class InviteGuild : ISnowflakeEntity | |||||
{ | |||||
/// <inheritdoc /> | |||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); | |||||
/// <inheritdoc/> | |||||
public ulong Id { get; private set; } | |||||
/// <summary> | |||||
/// Gets the name of this guild. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// A string containing the name of this guild. | |||||
/// </returns> | |||||
public string Name { get; private set; } | |||||
/// <summary> | |||||
/// Gets the description for the guild. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// The description for the guild; <see langword="null" /> if none is set. | |||||
/// </returns> | |||||
public string Description { get; private set; } | |||||
/// <summary> | |||||
/// Gets the ID of this guild's splash image. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// An identifier for the splash image; <see langword="null" /> if none is set. | |||||
/// </returns> | |||||
public string SplashId { get; private set; } | |||||
/// <summary> | |||||
/// Gets the URL of this guild's splash image. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// A URL pointing to the guild's splash image; <see langword="null" /> if none is set. | |||||
/// </returns> | |||||
public string SplashUrl => CDN.GetGuildSplashUrl(Id, SplashId); | |||||
/// <summary> | |||||
/// Gets the identifier for this guilds banner image. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// An identifier for the banner image; <see langword="null" /> if none is set. | |||||
/// </returns> | |||||
public string BannerId { get; private set; } | |||||
/// <summary> | |||||
/// Gets the URL of this guild's banner image. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// A URL pointing to the guild's banner image; <see langword="null" /> if none is set. | |||||
/// </returns> | |||||
public string BannerUrl => CDN.GetGuildBannerUrl(Id, BannerId, ImageFormat.Auto); | |||||
/// <summary> | |||||
/// Gets the features for this guild. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// A flags enum containing all the features for the guild. | |||||
/// </returns> | |||||
public GuildFeatures Features { get; private set; } | |||||
/// <summary> | |||||
/// Gets the ID of this guild's icon. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// An identifier for the splash image; <see langword="null" /> if none is set. | |||||
/// </returns> | |||||
public string IconId { get; private set; } | |||||
/// <summary> | |||||
/// Gets the URL of this guild's icon. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// A URL pointing to the guild's icon; <see langword="null" /> if none is set. | |||||
/// </returns> | |||||
public string IconUrl => CDN.GetGuildIconUrl(Id, IconId);/// <summary> | |||||
/// | |||||
/// Gets the level of requirements a user must fulfill before being allowed to post messages in this guild. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// The level of requirements. | |||||
/// </returns> | |||||
public VerificationLevel VerificationLevel { get; private set; } | |||||
/// <summary> | |||||
/// Gets the code for this guild's vanity invite URL. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// A string containing the vanity invite code for this guild; <see langword="null" /> if none is set. | |||||
/// </returns> | |||||
public string VanityURLCode { get; private set; } | |||||
/// <summary> | |||||
/// Gets the number of premium subscribers of this guild. | |||||
/// </summary> | |||||
/// <remarks> | |||||
/// This is the number of users who have boosted this guild. | |||||
/// </remarks> | |||||
/// <returns> | |||||
/// The number of premium subscribers of this guild; | |||||
/// </returns> | |||||
public int PremiumSubscriptionCount { get; private set; } | |||||
/// <summary> | |||||
/// Gets the NSFW level of this guild. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// The NSFW level of this guild. | |||||
/// </returns> | |||||
public NsfwLevel NsfwLevel { get; private set; } | |||||
/// <summary> | |||||
/// Gets the Welcome Screen of this guild | |||||
/// </summary> | |||||
/// <returns> | |||||
/// The welcome screen of this guild. <see langword="null" /> if none is set. | |||||
/// The welcome screen of this guild. <see langword="null" /> if none is set. | |||||
/// </returns> | |||||
public WelcomeScreen WelcomeScreen { get; private set; } | |||||
internal InviteGuild(ulong id, string name, string description, string splashId, string bannerId, GuildFeatures features, string iconId, VerificationLevel verificationLevel, string vanityURLCode, int premiumSubscriptionCount, NsfwLevel nsfwLevel, WelcomeScreen welcomeScreen) | |||||
{ | |||||
Id = id; | |||||
Name = name; | |||||
Description = description; | |||||
SplashId = splashId; | |||||
BannerId = bannerId; | |||||
Features = features; | |||||
IconId = iconId; | |||||
VerificationLevel = verificationLevel; | |||||
VanityURLCode = vanityURLCode; | |||||
PremiumSubscriptionCount = premiumSubscriptionCount; | |||||
NsfwLevel = nsfwLevel; | |||||
WelcomeScreen = welcomeScreen; | |||||
} | |||||
} |
@@ -7,7 +7,7 @@ namespace Discord.API | |||||
[JsonProperty("code")] | [JsonProperty("code")] | ||||
public string Code { get; set; } | public string Code { get; set; } | ||||
[JsonProperty("guild")] | [JsonProperty("guild")] | ||||
public Optional<Guild> Guild { get; set; } | |||||
public Optional<InviteGuild> Guild { get; set; } | |||||
[JsonProperty("channel")] | [JsonProperty("channel")] | ||||
public InviteChannel Channel { get; set; } | public InviteChannel Channel { get; set; } | ||||
[JsonProperty("inviter")] | [JsonProperty("inviter")] | ||||
@@ -0,0 +1,47 @@ | |||||
using Newtonsoft.Json; | |||||
using System.Collections.Generic; | |||||
namespace Discord.API | |||||
{ | |||||
internal class InviteGuild | |||||
{ | |||||
[JsonProperty("id")] | |||||
public ulong Id { get; set; } | |||||
[JsonProperty("name")] | |||||
public string Name { get; set; } | |||||
[JsonProperty("splash")] | |||||
public Optional<string> Splash { get; set; } | |||||
[JsonProperty("banner")] | |||||
public Optional<string> BannerHash { get; set; } | |||||
[JsonProperty("description")] | |||||
public Optional<string> Description { get; set; } | |||||
[JsonProperty("icon")] | |||||
public Optional<string> IconHash { get; set; } | |||||
[JsonProperty("features")] | |||||
public GuildFeatures Features { get; set; } | |||||
[JsonProperty("verification_level")] | |||||
public VerificationLevel VerificationLevel { get; set; } | |||||
[JsonProperty("vanity_url_code")] | |||||
public Optional<string> VanityUrlCode { get; set; } | |||||
[JsonProperty("premium_subscription_count")] | |||||
public Optional<int> PremiumSubscriptionCount { get; set; } | |||||
[JsonProperty("nsfw")] | |||||
public Optional<bool?> Nsfw { get; set; } | |||||
[JsonProperty("nsfw_level")] | |||||
public NsfwLevel NsfwLevel { get; set; } | |||||
[JsonProperty("welcome_screen")] | |||||
public Optional<WelcomeScreen> WelcomeScreen { get; set; } | |||||
} | |||||
} |
@@ -57,7 +57,7 @@ namespace Discord.Rest | |||||
{ | { | ||||
var model = await client.ApiClient.GetInviteAsync(inviteId, options).ConfigureAwait(false); | var model = await client.ApiClient.GetInviteAsync(inviteId, options).ConfigureAwait(false); | ||||
if (model != null) | if (model != null) | ||||
return RestInviteMetadata.Create(client, RestGuild.Create(client, model.Guild.IsSpecified ? model.Guild.Value : null), null, model); | |||||
return RestInviteMetadata.Create(client, null, null, model); | |||||
return null; | return null; | ||||
} | } | ||||
@@ -182,7 +182,7 @@ namespace Discord.Rest | |||||
if (model.MaxVideoChannelUsers.IsSpecified) | if (model.MaxVideoChannelUsers.IsSpecified) | ||||
MaxVideoChannelUsers = model.MaxVideoChannelUsers.Value; | MaxVideoChannelUsers = model.MaxVideoChannelUsers.Value; | ||||
PreferredLocale = model.PreferredLocale; | PreferredLocale = model.PreferredLocale; | ||||
PreferredCulture = model.PreferredLocale is null ? null : new CultureInfo(PreferredLocale); | |||||
PreferredCulture = new CultureInfo(PreferredLocale); | |||||
if (model.ApproximateMemberCount.IsSpecified) | if (model.ApproximateMemberCount.IsSpecified) | ||||
ApproximateMemberCount = model.ApproximateMemberCount.Value; | ApproximateMemberCount = model.ApproximateMemberCount.Value; | ||||
if (model.ApproximatePresenceCount.IsSpecified) | if (model.ApproximatePresenceCount.IsSpecified) | ||||
@@ -1,5 +1,7 @@ | |||||
using System; | using System; | ||||
using System.Collections.Immutable; | |||||
using System.Diagnostics; | using System.Diagnostics; | ||||
using System.Linq; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using Model = Discord.API.Invite; | using Model = Discord.API.Invite; | ||||
@@ -27,10 +29,18 @@ namespace Discord.Rest | |||||
public IUser TargetUser { get; private set; } | public IUser TargetUser { get; private set; } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public TargetUserType TargetUserType { get; private set; } | public TargetUserType TargetUserType { get; private set; } | ||||
internal IChannel Channel { get; } | |||||
/// <inheritdoc cref="IInvite.Guild"/> | |||||
public IGuild Guild { get; } | |||||
/// <summary> | |||||
/// Gets the guild this invite is linked to. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// A partial guild object representing the guild that the invite points to. | |||||
/// </returns> | |||||
public InviteGuild InviteGuild { get; private set; } | |||||
internal IChannel Channel { get; } | |||||
internal IGuild Guild { get; } | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public string Code => Id; | public string Code => Id; | ||||
@@ -61,6 +71,32 @@ namespace Discord.Rest | |||||
Inviter = model.Inviter.IsSpecified ? RestUser.Create(Discord, model.Inviter.Value) : null; | Inviter = model.Inviter.IsSpecified ? RestUser.Create(Discord, model.Inviter.Value) : null; | ||||
TargetUser = model.TargetUser.IsSpecified ? RestUser.Create(Discord, model.TargetUser.Value) : null; | TargetUser = model.TargetUser.IsSpecified ? RestUser.Create(Discord, model.TargetUser.Value) : null; | ||||
TargetUserType = model.TargetUserType.IsSpecified ? model.TargetUserType.Value : TargetUserType.Undefined; | TargetUserType = model.TargetUserType.IsSpecified ? model.TargetUserType.Value : TargetUserType.Undefined; | ||||
if (model.Guild.IsSpecified) | |||||
{ | |||||
InviteGuild = new InviteGuild | |||||
(model.Guild.Value.Id, | |||||
model.Guild.Value.Name, | |||||
model.Guild.Value.Description.IsSpecified ? model.Guild.Value.Description.Value : null, | |||||
model.Guild.Value.Splash.IsSpecified ? model.Guild.Value.Splash.Value : null, | |||||
model.Guild.Value.BannerHash.IsSpecified ? model.Guild.Value.BannerHash.Value : null, | |||||
model.Guild.Value.Features, | |||||
model.Guild.Value.IconHash.IsSpecified ? model.Guild.Value.IconHash.Value : null, | |||||
model.Guild.Value.VerificationLevel, | |||||
model.Guild.Value.VanityUrlCode.IsSpecified ? model.Guild.Value.VanityUrlCode.Value : null, | |||||
model.Guild.Value.PremiumSubscriptionCount.GetValueOrDefault(0), | |||||
model.Guild.Value.NsfwLevel, | |||||
model.Guild.Value.WelcomeScreen.IsSpecified | |||||
? new WelcomeScreen( | |||||
model.Guild.Value.WelcomeScreen.Value.Description.IsSpecified ? model.Guild.Value.WelcomeScreen.Value.Description.Value : null, | |||||
model.Guild.Value.WelcomeScreen.Value.WelcomeChannels.Select(ch => | |||||
new WelcomeScreenChannel( | |||||
ch.ChannelId, | |||||
ch.Description, | |||||
ch.EmojiName.IsSpecified ? ch.EmojiName.Value : null, | |||||
ch.EmojiId.IsSpecified ? ch.EmojiId.Value : null)).ToImmutableArray()) | |||||
: null); | |||||
} | |||||
} | } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||