From ec212b175dc17c2341afacfa2f269a08427c3b43 Mon Sep 17 00:00:00 2001 From: Paulo Date: Tue, 17 Nov 2020 05:23:45 -0300 Subject: [PATCH] feature: Add missing properties to Guild and deprecate GuildEmbed (#1573) * Add missing properties to Guild, related methods, and deprecate GuildEmbed endpoints - Add missing guild properties: `discovery_splash`, `widget_enabled`, `widget_channel_id`, `rules_channel_id`, `max_presences`, `max_presences`, `max_members`, `public_updates_channel_id`, `max_video_channel_users`, `approximate_member_count`, `approximate_presence_count` - Update guild properties: `embed_enabled`, `embed_channel_id` - Add `GetGuildDiscoverySplashUrl` to `CDN` - Add classes related to the guild widget - Add `withCounts` parameter to `GetGuild(s)Async` - Make GuildEmbed related methods obsolete with a message redirecting to widget ones * Change xml docs and PremiumSubscriptionCount type * Changed some xml docs --- src/Discord.Net.Core/CDN.cs | 12 +- .../Entities/Guilds/GuildWidgetProperties.cs | 21 ++ .../Entities/Guilds/IGuild.cs | 199 +++++++++++++---- src/Discord.Net.Core/Entities/IUpdateable.cs | 1 + src/Discord.Net.Rest/API/Common/Guild.cs | 26 ++- .../API/Common/GuildWidget.cs | 13 ++ .../API/Rest/ModifyGuildWidgetParams.cs | 14 ++ src/Discord.Net.Rest/ClientHelper.cs | 18 +- src/Discord.Net.Rest/DiscordRestApiClient.cs | 30 ++- src/Discord.Net.Rest/DiscordRestClient.cs | 12 +- .../Entities/Guilds/GuildHelper.cs | 22 ++ .../Entities/Guilds/RestGuild.cs | 200 +++++++++++++++--- .../Entities/Guilds/RestGuildWidget.cs | 25 +++ .../Entities/Guilds/SocketGuild.cs | 147 +++++++++++-- 14 files changed, 644 insertions(+), 96 deletions(-) create mode 100644 src/Discord.Net.Core/Entities/Guilds/GuildWidgetProperties.cs create mode 100644 src/Discord.Net.Rest/API/Common/GuildWidget.cs create mode 100644 src/Discord.Net.Rest/API/Rest/ModifyGuildWidgetParams.cs create mode 100644 src/Discord.Net.Rest/Entities/Guilds/RestGuildWidget.cs diff --git a/src/Discord.Net.Core/CDN.cs b/src/Discord.Net.Core/CDN.cs index 799b037ed..e1e8e5e1a 100644 --- a/src/Discord.Net.Core/CDN.cs +++ b/src/Discord.Net.Core/CDN.cs @@ -73,11 +73,21 @@ namespace Discord /// The guild snowflake identifier. /// The splash icon identifier. /// - /// A URL pointing to the guild's icon. + /// A URL pointing to the guild's splash. /// public static string GetGuildSplashUrl(ulong guildId, string splashId) => splashId != null ? $"{DiscordConfig.CDNUrl}splashes/{guildId}/{splashId}.jpg" : null; /// + /// Returns a guild discovery splash URL. + /// + /// The guild snowflake identifier. + /// The discovery splash icon identifier. + /// + /// A URL pointing to the guild's discovery splash. + /// + public static string GetGuildDiscoverySplashUrl(ulong guildId, string discoverySplashId) + => discoverySplashId != null ? $"{DiscordConfig.CDNUrl}discovery-splashes/{guildId}/{discoverySplashId}.jpg" : null; + /// /// Returns a channel icon URL. /// /// The channel snowflake identifier. diff --git a/src/Discord.Net.Core/Entities/Guilds/GuildWidgetProperties.cs b/src/Discord.Net.Core/Entities/Guilds/GuildWidgetProperties.cs new file mode 100644 index 000000000..842bb7f3e --- /dev/null +++ b/src/Discord.Net.Core/Entities/Guilds/GuildWidgetProperties.cs @@ -0,0 +1,21 @@ +namespace Discord +{ + /// + /// Provides properties that are used to modify the widget of an with the specified changes. + /// + public class GuildWidgetProperties + { + /// + /// Sets whether the widget should be enabled. + /// + public Optional Enabled { get; set; } + /// + /// Sets the channel that the invite should place its users in, if not . + /// + public Optional Channel { get; set; } + /// + /// Sets the channel that the invite should place its users in, if not . + /// + public Optional ChannelId { get; set; } + } +} diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index 8392bcd58..6283508e5 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -23,7 +23,7 @@ namespace Discord /// automatically moved to the AFK voice channel. /// /// - /// An representing the amount of time in seconds for a user to be marked as inactive + /// An representing the amount of time in seconds for a user to be marked as inactive /// and moved into the AFK voice channel. /// int AFKTimeout { get; } @@ -31,10 +31,17 @@ namespace Discord /// Gets a value that indicates whether this guild is embeddable (i.e. can use widget). /// /// - /// true if this guild can be embedded via widgets; otherwise false. + /// if this guild has a widget enabled; otherwise . /// bool IsEmbeddable { get; } /// + /// Gets a value that indicates whether this guild has the widget enabled. + /// + /// + /// if this guild has a widget enabled; otherwise . + /// + bool IsWidgetEnabled { get; } + /// /// Gets the default message notifications for users who haven't explicitly set their notification settings. /// DefaultMessageNotifications DefaultMessageNotifications { get; } @@ -64,31 +71,45 @@ namespace Discord /// Gets the ID of this guild's icon. /// /// - /// An identifier for the splash image; null if none is set. + /// An identifier for the splash image; if none is set. /// string IconId { get; } /// /// Gets the URL of this guild's icon. /// /// - /// A URL pointing to the guild's icon; null if none is set. + /// A URL pointing to the guild's icon; if none is set. /// string IconUrl { get; } /// /// Gets the ID of this guild's splash image. /// /// - /// An identifier for the splash image; null if none is set. + /// An identifier for the splash image; if none is set. /// string SplashId { get; } /// /// Gets the URL of this guild's splash image. /// /// - /// A URL pointing to the guild's splash image; null if none is set. + /// A URL pointing to the guild's splash image; if none is set. /// string SplashUrl { get; } /// + /// Gets the ID of this guild's discovery splash image. + /// + /// + /// An identifier for the discovery splash image; if none is set. + /// + string DiscoverySplashId { get; } + /// + /// Gets the URL of this guild's discovery splash image. + /// + /// + /// A URL pointing to the guild's discovery splash image; if none is set. + /// + string DiscoverySplashUrl { get; } + /// /// Determines if this guild is currently connected and ready to be used. /// /// @@ -98,7 +119,7 @@ namespace Discord /// This boolean is used to determine if the guild is currently connected to the WebSocket and is ready to be used/accessed. /// /// - /// true if this guild is currently connected and ready to be used; otherwise false. + /// true if this guild is currently connected and ready to be used; otherwise . /// bool Available { get; } @@ -106,7 +127,7 @@ namespace Discord /// Gets the ID of the AFK voice channel for this guild. /// /// - /// A representing the snowflake identifier of the AFK voice channel; null if + /// A representing the snowflake identifier of the AFK voice channel; if /// none is set. /// ulong? AFKChannelId { get; } @@ -121,7 +142,7 @@ namespace Discord /// /// /// - /// A representing the snowflake identifier of the default text channel; 0 if + /// A representing the snowflake identifier of the default text channel; 0 if /// none can be found. /// ulong DefaultChannelId { get; } @@ -129,30 +150,54 @@ namespace Discord /// Gets the ID of the widget embed channel of this guild. /// /// - /// A representing the snowflake identifier of the embedded channel found within the - /// widget settings of this guild; null if none is set. + /// A representing the snowflake identifier of the embedded channel found within the + /// widget settings of this guild; if none is set. /// ulong? EmbedChannelId { get; } /// + /// Gets the ID of the channel assigned to the widget of this guild. + /// + /// + /// A representing the snowflake identifier of the channel assigned to the widget found + /// within the widget settings of this guild; if none is set. + /// + ulong? WidgetChannelId { get; } + /// /// Gets the ID of the channel where randomized welcome messages are sent. /// /// - /// A representing the snowflake identifier of the system channel where randomized - /// welcome messages are sent; null if none is set. + /// A representing the snowflake identifier of the system channel where randomized + /// welcome messages are sent; if none is set. /// ulong? SystemChannelId { get; } /// + /// Gets the ID of the channel with the rules. + /// + /// + /// A representing the snowflake identifier of the channel that contains the rules; + /// if none is set. + /// + ulong? RulesChannelId { get; } + /// + /// Gets the ID of the channel where admins and moderators of Community guilds receive notices from Discord. + /// + /// + /// A representing the snowflake identifier of the channel where admins and moderators + /// of Community guilds receive notices from Discord; if none is set. + /// + ulong? PublicUpdatesChannelId { get; } + /// /// Gets the ID of the user that owns this guild. /// /// - /// A representing the snowflake identifier of the user that owns this guild. + /// A representing the snowflake identifier of the user that owns this guild. /// ulong OwnerId { get; } /// /// Gets the application ID of the guild creator if it is bot-created. /// /// - /// A representing the snowflake identifier of the application ID that created this guild, or null if it was not bot-created. + /// A representing the snowflake identifier of the application ID that created this guild, or if it was not bot-created. /// ulong? ApplicationId { get; } /// @@ -208,21 +253,21 @@ namespace Discord /// Gets the identifier for this guilds banner image. /// /// - /// An identifier for the banner image; null if none is set. + /// An identifier for the banner image; if none is set. /// string BannerId { get; } /// /// Gets the URL of this guild's banner image. /// /// - /// A URL pointing to the guild's banner image; null if none is set. + /// A URL pointing to the guild's banner image; if none is set. /// string BannerUrl { get; } /// /// Gets the code for this guild's vanity invite URL. /// /// - /// A string containing the vanity invite code for this guild; null if none is set. + /// A string containing the vanity invite code for this guild; if none is set. /// string VanityURLCode { get; } /// @@ -236,7 +281,7 @@ namespace Discord /// Gets the description for the guild. /// /// - /// The description for the guild; null if none is set. + /// The description for the guild; if none is set. /// string Description { get; } /// @@ -246,9 +291,50 @@ namespace Discord /// This is the number of users who have boosted this guild. /// /// - /// The number of premium subscribers of this guild. + /// The number of premium subscribers of this guild; if not available. /// int PremiumSubscriptionCount { get; } + /// + /// Gets the maximum number of presences for the guild. + /// + /// + /// The maximum number of presences for the guild. + /// + int? MaxPresences { get; } + /// + /// Gets the maximum number of members for the guild. + /// + /// + /// The maximum number of members for the guild. + /// + int? MaxMembers { get; } + /// + /// Gets the maximum amount of users in a video channel. + /// + /// + /// The maximum amount of users in a video channel. + /// + int? MaxVideoChannelUsers { get; } + /// + /// Gets the approximate number of members in this guild. + /// + /// + /// Only available when getting a guild via REST when `with_counts` is true. + /// + /// + /// The approximate number of members in this guild. + /// + int? ApproximateMemberCount { get; } + /// + /// Gets the approximate number of non-offline members in this guild. + /// + /// + /// Only available when getting a guild via REST when `with_counts` is true. + /// + /// + /// The approximate number of non-offline members in this guild. + /// + int? ApproximatePresenceCount { get; } /// /// Gets the preferred locale of this guild in IETF BCP 47 @@ -285,8 +371,18 @@ namespace Discord /// /// A task that represents the asynchronous modification operation. /// + [Obsolete("This endpoint is deprecated, use ModifyWidgetAsync instead.")] Task ModifyEmbedAsync(Action func, RequestOptions options = null); /// + /// Modifies this guild's widget. + /// + /// The delegate containing the properties to modify the guild widget with. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + Task ModifyWidgetAsync(Action func, RequestOptions options = null); + /// /// Bulk-modifies the order of channels in this guild. /// /// The properties used to modify the channel positions with. @@ -336,7 +432,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains a ban object, which - /// contains the user information and the reason for the ban; null if the ban entry cannot be found. + /// contains the user information and the reason for the ban; if the ban entry cannot be found. /// Task GetBanAsync(IUser user, RequestOptions options = null); /// @@ -346,7 +442,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains a ban object, which - /// contains the user information and the reason for the ban; null if the ban entry cannot be found. + /// contains the user information and the reason for the ban; if the ban entry cannot be found. /// Task GetBanAsync(ulong userId, RequestOptions options = null); /// @@ -410,7 +506,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the generic channel - /// associated with the specified ; null if none is found. + /// associated with the specified ; if none is found. /// Task GetChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// @@ -431,7 +527,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the text channel - /// associated with the specified ; null if none is found. + /// associated with the specified ; if none is found. /// Task GetTextChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// @@ -462,7 +558,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the voice channel associated - /// with the specified ; null if none is found. + /// with the specified ; if none is found. /// Task GetVoiceChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// @@ -472,7 +568,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the voice channel that the - /// AFK users will be moved to after they have idled for too long; null if none is set. + /// AFK users will be moved to after they have idled for too long; if none is set. /// Task GetAFKChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// @@ -482,7 +578,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the text channel where - /// randomized welcome messages will be sent to; null if none is set. + /// randomized welcome messages will be sent to; if none is set. /// Task GetSystemChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// @@ -492,7 +588,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the first viewable text - /// channel in this guild; null if none is found. + /// channel in this guild; if none is found. /// Task GetDefaultChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// @@ -502,9 +598,40 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the embed channel set - /// within the server's widget settings; null if none is set. + /// within the server's widget settings; if none is set. /// + [Obsolete("This endpoint is deprecated, use GetWidgetChannelAsync instead.")] Task GetEmbedChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + /// + /// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild. + /// + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the widget channel set + /// within the server's widget settings; if none is set. + /// + Task GetWidgetChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + /// + /// Gets the text channel where Community guilds can display rules and/or guidelines. + /// + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the text channel + /// where Community guilds can display rules and/or guidelines; if none is set. + /// + Task GetRulesChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + /// + /// Gets the text channel channel where admins and moderators of Community guilds receive notices from Discord. + /// + /// The that determines whether the object should be fetched from cache. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the text channel channel where + /// admins and moderators of Community guilds receive notices from Discord; if none is set. + /// + Task GetPublicUpdatesChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// /// Creates a new text channel in this guild. @@ -573,7 +700,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the partial metadata of - /// the vanity invite found within this guild; null if none is found. + /// the vanity invite found within this guild; if none is found. /// Task GetVanityInviteAsync(RequestOptions options = null); @@ -582,7 +709,7 @@ namespace Discord /// /// The snowflake identifier for the role. /// - /// A role that is associated with the specified ; null if none is found. + /// A role that is associated with the specified ; if none is found. /// IRole GetRole(ulong id); /// @@ -624,7 +751,7 @@ namespace Discord /// The OAuth2 access token for the user, requested with the guilds.join scope. /// The delegate containing the properties to be applied to the user upon being added to the guild. /// The options to be used when sending the request. - /// A guild user associated with the specified ; null if the user is already in the guild. + /// A guild user associated with the specified ; if the user is already in the guild. Task AddGuildUserAsync(ulong userId, string accessToken, Action func = null, RequestOptions options = null); /// /// Gets a collection of all users in this guild. @@ -649,7 +776,7 @@ namespace Discord /// /// This method retrieves a user found within this guild. /// - /// This may return null in the WebSocket implementation due to incomplete user collection in + /// This may return in the WebSocket implementation due to incomplete user collection in /// large guilds. /// /// @@ -658,7 +785,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the guild user - /// associated with the specified ; null if none is found. + /// associated with the specified ; if none is found. /// Task GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// @@ -752,7 +879,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the webhook with the - /// specified ; null if none is found. + /// specified ; if none is found. /// Task GetWebhookAsync(ulong id, RequestOptions options = null); /// @@ -772,7 +899,7 @@ namespace Discord /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the emote found with the - /// specified ; null if none is found. + /// specified ; if none is found. /// Task GetEmoteAsync(ulong id, RequestOptions options = null); /// diff --git a/src/Discord.Net.Core/Entities/IUpdateable.cs b/src/Discord.Net.Core/Entities/IUpdateable.cs index 3ae4613f5..d561e57a6 100644 --- a/src/Discord.Net.Core/Entities/IUpdateable.cs +++ b/src/Discord.Net.Core/Entities/IUpdateable.cs @@ -10,6 +10,7 @@ namespace Discord /// /// Updates this object's properties with its current state. /// + /// The options to be used when sending the request. Task UpdateAsync(RequestOptions options = null); } } diff --git a/src/Discord.Net.Rest/API/Common/Guild.cs b/src/Discord.Net.Rest/API/Common/Guild.cs index 56bd841ea..414929a7b 100644 --- a/src/Discord.Net.Rest/API/Common/Guild.cs +++ b/src/Discord.Net.Rest/API/Common/Guild.cs @@ -13,6 +13,8 @@ namespace Discord.API public string Icon { get; set; } [JsonProperty("splash")] public string Splash { get; set; } + [JsonProperty("discovery_splash")] + public string DiscoverySplash { get; set; } [JsonProperty("owner_id")] public ulong OwnerId { get; set; } [JsonProperty("region")] @@ -22,9 +24,9 @@ namespace Discord.API [JsonProperty("afk_timeout")] public int AFKTimeout { get; set; } [JsonProperty("embed_enabled")] - public bool EmbedEnabled { get; set; } + public Optional EmbedEnabled { get; set; } [JsonProperty("embed_channel_id")] - public ulong? EmbedChannelId { get; set; } + public Optional EmbedChannelId { get; set; } [JsonProperty("verification_level")] public VerificationLevel VerificationLevel { get; set; } [JsonProperty("default_message_notifications")] @@ -43,6 +45,10 @@ namespace Discord.API public MfaLevel MfaLevel { get; set; } [JsonProperty("application_id")] public ulong? ApplicationId { get; set; } + [JsonProperty("widget_enabled")] + public Optional WidgetEnabled { get; set; } + [JsonProperty("widget_channel_id")] + public Optional WidgetChannelId { get; set; } [JsonProperty("system_channel_id")] public ulong? SystemChannelId { get; set; } [JsonProperty("premium_tier")] @@ -56,9 +62,23 @@ namespace Discord.API // this value is inverted, flags set will turn OFF features [JsonProperty("system_channel_flags")] public SystemChannelMessageDeny SystemChannelFlags { get; set; } + [JsonProperty("rules_channel_id")] + public ulong? RulesChannelId { get; set; } + [JsonProperty("max_presences")] + public Optional MaxPresences { get; set; } + [JsonProperty("max_members")] + public Optional MaxMembers { get; set; } [JsonProperty("premium_subscription_count")] - public int? PremiumSubscriptionCount { get; set; } + public Optional PremiumSubscriptionCount { get; set; } [JsonProperty("preferred_locale")] public string PreferredLocale { get; set; } + [JsonProperty("public_updates_channel_id")] + public ulong? PublicUpdatesChannelId { get; set; } + [JsonProperty("max_video_channel_users")] + public Optional MaxVideoChannelUsers { get; set; } + [JsonProperty("approximate_member_count")] + public Optional ApproximateMemberCount { get; set; } + [JsonProperty("approximate_presence_count")] + public Optional ApproximatePresenceCount { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Common/GuildWidget.cs b/src/Discord.Net.Rest/API/Common/GuildWidget.cs new file mode 100644 index 000000000..c15ad8aac --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/GuildWidget.cs @@ -0,0 +1,13 @@ +#pragma warning disable CS1591 +using Newtonsoft.Json; + +namespace Discord.API +{ + internal class GuildWidget + { + [JsonProperty("enabled")] + public bool Enabled { get; set; } + [JsonProperty("channel_id")] + public ulong? ChannelId { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildWidgetParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildWidgetParams.cs new file mode 100644 index 000000000..506f1dfbb --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildWidgetParams.cs @@ -0,0 +1,14 @@ +#pragma warning disable CS1591 +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + internal class ModifyGuildWidgetParams + { + [JsonProperty("enabled")] + public Optional Enabled { get; set; } + [JsonProperty("channel")] + public Optional ChannelId { get; set; } + } +} diff --git a/src/Discord.Net.Rest/ClientHelper.cs b/src/Discord.Net.Rest/ClientHelper.cs index a8f6b58ef..6ebdbcacb 100644 --- a/src/Discord.Net.Rest/ClientHelper.cs +++ b/src/Discord.Net.Rest/ClientHelper.cs @@ -62,9 +62,9 @@ namespace Discord.Rest } public static async Task GetGuildAsync(BaseDiscordClient client, - ulong id, RequestOptions options) + ulong id, bool withCounts, RequestOptions options) { - var model = await client.ApiClient.GetGuildAsync(id, options).ConfigureAwait(false); + var model = await client.ApiClient.GetGuildAsync(id, withCounts, options).ConfigureAwait(false); if (model != null) return RestGuild.Create(client, model); return null; @@ -77,6 +77,14 @@ namespace Discord.Rest return RestGuildEmbed.Create(model); return null; } + public static async Task GetGuildWidgetAsync(BaseDiscordClient client, + ulong id, RequestOptions options) + { + var model = await client.ApiClient.GetGuildWidgetAsync(id, options).ConfigureAwait(false); + if (model != null) + return RestGuildWidget.Create(model); + return null; + } public static IAsyncEnumerable> GetGuildSummariesAsync(BaseDiscordClient client, ulong? fromGuildId, int? limit, RequestOptions options) { @@ -106,13 +114,13 @@ namespace Discord.Rest count: limit ); } - public static async Task> GetGuildsAsync(BaseDiscordClient client, RequestOptions options) + public static async Task> GetGuildsAsync(BaseDiscordClient client, bool withCounts, RequestOptions options) { var summaryModels = await GetGuildSummariesAsync(client, null, null, options).FlattenAsync().ConfigureAwait(false); var guilds = ImmutableArray.CreateBuilder(); foreach (var summaryModel in summaryModels) { - var guildModel = await client.ApiClient.GetGuildAsync(summaryModel.Id).ConfigureAwait(false); + var guildModel = await client.ApiClient.GetGuildAsync(summaryModel.Id, withCounts).ConfigureAwait(false); if (guildModel != null) guilds.Add(RestGuild.Create(client, guildModel)); } @@ -140,7 +148,7 @@ namespace Discord.Rest public static async Task GetGuildUserAsync(BaseDiscordClient client, ulong guildId, ulong id, RequestOptions options) { - var guild = await GetGuildAsync(client, guildId, options).ConfigureAwait(false); + var guild = await GetGuildAsync(client, guildId, false, options).ConfigureAwait(false); if (guild == null) return null; diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index 27658e7ac..592ad7e92 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -787,7 +787,7 @@ namespace Discord.API } //Guilds - public async Task GetGuildAsync(ulong guildId, RequestOptions options = null) + public async Task GetGuildAsync(ulong guildId, bool withCounts, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); @@ -795,7 +795,7 @@ namespace Discord.API try { var ids = new BucketIds(guildId: guildId); - return await SendAsync("GET", () => $"guilds/{guildId}", ids, options: options).ConfigureAwait(false); + return await SendAsync("GET", () => $"guilds/{guildId}?with_counts={(withCounts ? "true" : "false")}", ids, options: options).ConfigureAwait(false); } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } } @@ -938,6 +938,32 @@ namespace Discord.API return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/embed", args, ids, options: options).ConfigureAwait(false); } + //Guild Widget + /// must not be equal to zero. + public async Task GetGuildWidgetAsync(ulong guildId, RequestOptions options = null) + { + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + options = RequestOptions.CreateOrClone(options); + + try + { + var ids = new BucketIds(guildId: guildId); + return await SendAsync("GET", () => $"guilds/{guildId}/widget", ids, options: options).ConfigureAwait(false); + } + catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } + } + /// must not be equal to zero. + /// must not be . + public async Task ModifyGuildWidgetAsync(ulong guildId, Rest.ModifyGuildWidgetParams args, RequestOptions options = null) + { + Preconditions.NotNull(args, nameof(args)); + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(guildId: guildId); + return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/widget", args, ids, options: options).ConfigureAwait(false); + } + //Guild Integrations /// must not be equal to zero. public async Task> GetGuildIntegrationsAsync(ulong guildId, RequestOptions options = null) diff --git a/src/Discord.Net.Rest/DiscordRestClient.cs b/src/Discord.Net.Rest/DiscordRestClient.cs index 4c29d1625..bef4e6b2a 100644 --- a/src/Discord.Net.Rest/DiscordRestClient.cs +++ b/src/Discord.Net.Rest/DiscordRestClient.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Collections.Immutable; using System.IO; @@ -76,15 +77,22 @@ namespace Discord.Rest => ClientHelper.GetInviteAsync(this, inviteId, options); public Task GetGuildAsync(ulong id, RequestOptions options = null) - => ClientHelper.GetGuildAsync(this, id, options); + => ClientHelper.GetGuildAsync(this, id, false, options); + public Task GetGuildAsync(ulong id, bool withCounts, RequestOptions options = null) + => ClientHelper.GetGuildAsync(this, id, withCounts, options); + [Obsolete("This endpoint is deprecated, use GetGuildWidgetAsync instead.")] public Task GetGuildEmbedAsync(ulong id, RequestOptions options = null) => ClientHelper.GetGuildEmbedAsync(this, id, options); + public Task GetGuildWidgetAsync(ulong id, RequestOptions options = null) + => ClientHelper.GetGuildWidgetAsync(this, id, options); public IAsyncEnumerable> GetGuildSummariesAsync(RequestOptions options = null) => ClientHelper.GetGuildSummariesAsync(this, null, null, options); public IAsyncEnumerable> GetGuildSummariesAsync(ulong fromGuildId, int limit, RequestOptions options = null) => ClientHelper.GetGuildSummariesAsync(this, fromGuildId, limit, options); public Task> GetGuildsAsync(RequestOptions options = null) - => ClientHelper.GetGuildsAsync(this, options); + => ClientHelper.GetGuildsAsync(this, false, options); + public Task> GetGuildsAsync(bool withCounts, RequestOptions options = null) + => ClientHelper.GetGuildsAsync(this, withCounts, options); public Task CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null, RequestOptions options = null) => ClientHelper.CreateGuildAsync(this, name, region, jpegIcon, options); diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index 225c53edf..04ec27930 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -5,6 +5,7 @@ using System.Collections.Immutable; using System.Linq; using System.Threading.Tasks; using EmbedModel = Discord.API.GuildEmbed; +using WidgetModel = Discord.API.GuildWidget; using Model = Discord.API.Guild; using RoleModel = Discord.API.Role; using ImageModel = Discord.API.Image; @@ -99,6 +100,27 @@ namespace Discord.Rest return await client.ApiClient.ModifyGuildEmbedAsync(guild.Id, apiArgs, options).ConfigureAwait(false); } + /// is null. + public static async Task ModifyWidgetAsync(IGuild guild, BaseDiscordClient client, + Action func, RequestOptions options) + { + if (func == null) + throw new ArgumentNullException(nameof(func)); + + var args = new GuildWidgetProperties(); + func(args); + var apiArgs = new API.Rest.ModifyGuildWidgetParams + { + Enabled = args.Enabled + }; + + if (args.Channel.IsSpecified) + apiArgs.ChannelId = args.Channel.Value?.Id; + else if (args.ChannelId.IsSpecified) + apiArgs.ChannelId = args.ChannelId.Value; + + return await client.ApiClient.ModifyGuildWidgetAsync(guild.Id, apiArgs, options).ConfigureAwait(false); + } public static async Task ReorderChannelsAsync(IGuild guild, BaseDiscordClient client, IEnumerable args, RequestOptions options) { diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index 482eaf556..c1dd39afe 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -7,6 +7,7 @@ using System.Globalization; using System.Linq; using System.Threading.Tasks; using EmbedModel = Discord.API.GuildEmbed; +using WidgetModel = Discord.API.GuildWidget; using Model = Discord.API.Guild; namespace Discord.Rest @@ -28,6 +29,8 @@ namespace Discord.Rest /// public bool IsEmbeddable { get; private set; } /// + public bool IsWidgetEnabled { get; private set; } + /// public VerificationLevel VerificationLevel { get; private set; } /// public MfaLevel MfaLevel { get; private set; } @@ -41,8 +44,14 @@ namespace Discord.Rest /// public ulong? EmbedChannelId { get; private set; } /// + public ulong? WidgetChannelId { get; private set; } + /// public ulong? SystemChannelId { get; private set; } /// + public ulong? RulesChannelId { get; private set; } + /// + public ulong? PublicUpdatesChannelId { get; private set; } + /// public ulong OwnerId { get; private set; } /// public string VoiceRegionId { get; private set; } @@ -50,6 +59,8 @@ namespace Discord.Rest public string IconId { get; private set; } /// public string SplashId { get; private set; } + /// + public string DiscoverySplashId { get; private set; } internal bool Available { get; private set; } /// public ulong? ApplicationId { get; private set; } @@ -67,6 +78,16 @@ namespace Discord.Rest public int PremiumSubscriptionCount { get; private set; } /// public string PreferredLocale { get; private set; } + /// + public int? MaxPresences { get; private set; } + /// + public int? MaxMembers { get; private set; } + /// + public int? MaxVideoChannelUsers { get; private set; } + /// + public int? ApproximateMemberCount { get; private set; } + /// + public int? ApproximatePresenceCount { get; private set; } /// public CultureInfo PreferredCulture { get; private set; } @@ -81,6 +102,8 @@ namespace Discord.Rest /// public string SplashUrl => CDN.GetGuildSplashUrl(Id, SplashId); /// + public string DiscoverySplashUrl => CDN.GetGuildDiscoverySplashUrl(Id, DiscoverySplashId); + /// public string BannerUrl => CDN.GetGuildBannerUrl(Id, BannerId); /// @@ -110,15 +133,24 @@ namespace Discord.Rest internal void Update(Model model) { AFKChannelId = model.AFKChannelId; - EmbedChannelId = model.EmbedChannelId; + if (model.EmbedChannelId.IsSpecified) + EmbedChannelId = model.EmbedChannelId.Value; + if (model.WidgetChannelId.IsSpecified) + WidgetChannelId = model.WidgetChannelId.Value; SystemChannelId = model.SystemChannelId; + RulesChannelId = model.RulesChannelId; + PublicUpdatesChannelId = model.PublicUpdatesChannelId; AFKTimeout = model.AFKTimeout; - IsEmbeddable = model.EmbedEnabled; + if (model.EmbedEnabled.IsSpecified) + IsEmbeddable = model.EmbedEnabled.Value; + if (model.WidgetEnabled.IsSpecified) + IsWidgetEnabled = model.WidgetEnabled.Value; IconId = model.Icon; Name = model.Name; OwnerId = model.OwnerId; VoiceRegionId = model.Region; SplashId = model.Splash; + DiscoverySplashId = model.DiscoverySplash; VerificationLevel = model.VerificationLevel; MfaLevel = model.MfaLevel; DefaultMessageNotifications = model.DefaultMessageNotifications; @@ -129,9 +161,20 @@ namespace Discord.Rest BannerId = model.Banner; SystemChannelFlags = model.SystemChannelFlags; Description = model.Description; - PremiumSubscriptionCount = model.PremiumSubscriptionCount.GetValueOrDefault(); + if (model.PremiumSubscriptionCount.IsSpecified) + PremiumSubscriptionCount = model.PremiumSubscriptionCount.Value; + if (model.MaxPresences.IsSpecified) + MaxPresences = model.MaxPresences.Value ?? 25000; + if (model.MaxMembers.IsSpecified) + MaxMembers = model.MaxMembers.Value; + if (model.MaxVideoChannelUsers.IsSpecified) + MaxVideoChannelUsers = model.MaxVideoChannelUsers.Value; PreferredLocale = model.PreferredLocale; PreferredCulture = new CultureInfo(PreferredLocale); + if (model.ApproximateMemberCount.IsSpecified) + ApproximateMemberCount = model.ApproximateMemberCount.Value; + if (model.ApproximatePresenceCount.IsSpecified) + ApproximatePresenceCount = model.ApproximatePresenceCount.Value; if (model.Emojis != null) { @@ -163,17 +206,36 @@ namespace Discord.Rest EmbedChannelId = model.ChannelId; IsEmbeddable = model.Enabled; } + internal void Update(WidgetModel model) + { + WidgetChannelId = model.ChannelId; + IsWidgetEnabled = model.Enabled; + } //General /// public async Task UpdateAsync(RequestOptions options = null) - => Update(await Discord.ApiClient.GetGuildAsync(Id, options).ConfigureAwait(false)); + => Update(await Discord.ApiClient.GetGuildAsync(Id, false, options).ConfigureAwait(false)); + /// + /// Updates this object's properties with its current state. + /// + /// + /// If true, and + /// will be updated as well. + /// + /// The options to be used when sending the request. + /// + /// If is true, and + /// will be updated as well. + /// + public async Task UpdateAsync(bool withCounts, RequestOptions options = null) + => Update(await Discord.ApiClient.GetGuildAsync(Id, withCounts, options).ConfigureAwait(false)); /// public Task DeleteAsync(RequestOptions options = null) => GuildHelper.DeleteAsync(this, Discord, options); /// - /// is null. + /// is . public async Task ModifyAsync(Action func, RequestOptions options = null) { var model = await GuildHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); @@ -181,7 +243,8 @@ namespace Discord.Rest } /// - /// is null. + /// is . + [Obsolete("This endpoint is deprecated, use ModifyWidgetAsync instead.")] public async Task ModifyEmbedAsync(Action func, RequestOptions options = null) { var model = await GuildHelper.ModifyEmbedAsync(this, Discord, func, options).ConfigureAwait(false); @@ -189,7 +252,15 @@ namespace Discord.Rest } /// - /// is null. + /// is . + public async Task ModifyWidgetAsync(Action func, RequestOptions options = null) + { + var model = await GuildHelper.ModifyWidgetAsync(this, Discord, func, options).ConfigureAwait(false); + Update(model); + } + + /// + /// is . public async Task ReorderChannelsAsync(IEnumerable args, RequestOptions options = null) { var arr = args.ToArray(); @@ -230,7 +301,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains a ban object, which - /// contains the user information and the reason for the ban; null if the ban entry cannot be found. + /// contains the user information and the reason for the ban; if the ban entry cannot be found. /// public Task GetBanAsync(IUser user, RequestOptions options = null) => GuildHelper.GetBanAsync(this, Discord, user.Id, options); @@ -241,7 +312,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains a ban object, which - /// contains the user information and the reason for the ban; null if the ban entry cannot be found. + /// contains the user information and the reason for the ban; if the ban entry cannot be found. /// public Task GetBanAsync(ulong userId, RequestOptions options = null) => GuildHelper.GetBanAsync(this, Discord, userId, options); @@ -279,7 +350,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the generic channel - /// associated with the specified ; null if none is found. + /// associated with the specified ; if none is found. /// public Task GetChannelAsync(ulong id, RequestOptions options = null) => GuildHelper.GetChannelAsync(this, Discord, id, options); @@ -291,7 +362,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the text channel - /// associated with the specified ; null if none is found. + /// associated with the specified ; if none is found. /// public async Task GetTextChannelAsync(ulong id, RequestOptions options = null) { @@ -320,7 +391,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the voice channel associated - /// with the specified ; null if none is found. + /// with the specified ; if none is found. /// public async Task GetVoiceChannelAsync(ulong id, RequestOptions options = null) { @@ -362,7 +433,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the voice channel that the - /// AFK users will be moved to after they have idled for too long; null if none is set. + /// AFK users will be moved to after they have idled for too long; if none is set. /// public async Task GetAFKChannelAsync(RequestOptions options = null) { @@ -381,7 +452,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the first viewable text - /// channel in this guild; null if none is found. + /// channel in this guild; if none is found. /// public async Task GetDefaultChannelAsync(RequestOptions options = null) { @@ -399,8 +470,9 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the embed channel set - /// within the server's widget settings; null if none is set. + /// within the server's widget settings; if none is set. /// + [Obsolete("This endpoint is deprecated, use GetWidgetChannelAsync instead.")] public async Task GetEmbedChannelAsync(RequestOptions options = null) { var embedId = EmbedChannelId; @@ -410,12 +482,28 @@ namespace Discord.Rest } /// - /// Gets the first viewable text channel in this guild. + /// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild. /// /// The options to be used when sending the request. /// - /// A task that represents the asynchronous get operation. The task result contains the first viewable text - /// channel in this guild; null if none is found. + /// A task that represents the asynchronous get operation. The task result contains the widget channel set + /// within the server's widget settings; if none is set. + /// + public async Task GetWidgetChannelAsync(RequestOptions options = null) + { + var widgetChannelId = WidgetChannelId; + if (widgetChannelId.HasValue) + return await GuildHelper.GetChannelAsync(this, Discord, widgetChannelId.Value, options).ConfigureAwait(false); + return null; + } + + /// + /// Gets the text channel where guild notices such as welcome messages and boost events are posted. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the text channel + /// where guild notices such as welcome messages and boost events are poste; if none is found. /// public async Task GetSystemChannelAsync(RequestOptions options = null) { @@ -427,6 +515,45 @@ namespace Discord.Rest } return null; } + + /// + /// Gets the text channel where Community guilds can display rules and/or guidelines. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the text channel + /// where Community guilds can display rules and/or guidelines; if none is set. + /// + public async Task GetRulesChannelAsync(RequestOptions options = null) + { + var rulesChannelId = RulesChannelId; + if (rulesChannelId.HasValue) + { + var channel = await GuildHelper.GetChannelAsync(this, Discord, rulesChannelId.Value, options).ConfigureAwait(false); + return channel as RestTextChannel; + } + return null; + } + + /// + /// Gets the text channel channel where admins and moderators of Community guilds receive notices from Discord. + /// + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous get operation. The task result contains the text channel channel where + /// admins and moderators of Community guilds receive notices from Discord; if none is set. + /// + public async Task GetPublicUpdatesChannelAsync(RequestOptions options = null) + { + var publicUpdatesChannelId = PublicUpdatesChannelId; + if (publicUpdatesChannelId.HasValue) + { + var channel = await GuildHelper.GetChannelAsync(this, Discord, publicUpdatesChannelId.Value, options).ConfigureAwait(false); + return channel as RestTextChannel; + } + return null; + } + /// /// Creates a new text channel in this guild. /// @@ -458,7 +585,7 @@ namespace Discord.Rest /// The name of the new channel. /// The delegate containing the properties to be applied to the channel upon its creation. /// The options to be used when sending the request. - /// is null. + /// is . /// /// The created voice channel. /// @@ -470,7 +597,7 @@ namespace Discord.Rest /// The name of the new channel. /// The delegate containing the properties to be applied to the channel upon its creation. /// The options to be used when sending the request. - /// is null. + /// is . /// /// The created category channel. /// @@ -521,7 +648,7 @@ namespace Discord.Rest /// /// The snowflake identifier for the role. /// - /// A role that is associated with the specified ; null if none is found. + /// A role that is associated with the specified ; if none is found. /// public RestRole GetRole(ulong id) { @@ -585,7 +712,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the guild user - /// associated with the specified ; null if none is found. + /// associated with the specified ; if none is found. /// public Task GetUserAsync(ulong id, RequestOptions options = null) => GuildHelper.GetUserAsync(this, Discord, id, options); @@ -675,7 +802,7 @@ namespace Discord.Rest /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the webhook with the - /// specified ; null if none is found. + /// specified ; if none is found. /// public Task GetWebhookAsync(ulong id, RequestOptions options = null) => GuildHelper.GetWebhookAsync(this, Discord, id, options); @@ -708,7 +835,7 @@ namespace Discord.Rest public Task CreateEmoteAsync(string name, Image image, Optional> roles = default(Optional>), RequestOptions options = null) => GuildHelper.CreateEmoteAsync(this, Discord, name, image, roles, options); /// - /// is null. + /// is . public Task ModifyEmoteAsync(GuildEmote emote, Action func, RequestOptions options = null) => GuildHelper.ModifyEmoteAsync(this, Discord, emote.Id, func, options); /// @@ -808,6 +935,7 @@ namespace Discord.Rest return null; } /// + [Obsolete("This endpoint is deprecated, use GetWidgetChannelAsync instead.")] async Task IGuild.GetEmbedChannelAsync(CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) @@ -816,6 +944,14 @@ namespace Discord.Rest return null; } /// + async Task IGuild.GetWidgetChannelAsync(CacheMode mode, RequestOptions options) + { + if (mode == CacheMode.AllowDownload) + return await GetWidgetChannelAsync(options).ConfigureAwait(false); + else + return null; + } + /// async Task IGuild.GetSystemChannelAsync(CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) @@ -824,6 +960,22 @@ namespace Discord.Rest return null; } /// + async Task IGuild.GetRulesChannelAsync(CacheMode mode, RequestOptions options) + { + if (mode == CacheMode.AllowDownload) + return await GetRulesChannelAsync(options).ConfigureAwait(false); + else + return null; + } + /// + async Task IGuild.GetPublicUpdatesChannelAsync(CacheMode mode, RequestOptions options) + { + if (mode == CacheMode.AllowDownload) + return await GetPublicUpdatesChannelAsync(options).ConfigureAwait(false); + else + return null; + } + /// async Task IGuild.CreateTextChannelAsync(string name, Action func, RequestOptions options) => await CreateTextChannelAsync(name, func, options).ConfigureAwait(false); /// diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuildWidget.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuildWidget.cs new file mode 100644 index 000000000..065739c57 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuildWidget.cs @@ -0,0 +1,25 @@ +using System.Diagnostics; +using Model = Discord.API.GuildWidget; + +namespace Discord.Rest +{ + [DebuggerDisplay(@"{DebuggerDisplay,nq}")] + public struct RestGuildWidget + { + public bool IsEnabled { get; private set; } + public ulong? ChannelId { get; private set; } + + internal RestGuildWidget(bool isEnabled, ulong? channelId) + { + ChannelId = channelId; + IsEnabled = isEnabled; + } + internal static RestGuildWidget Create(Model model) + { + return new RestGuildWidget(model.Enabled, model.ChannelId); + } + + public override string ToString() => ChannelId?.ToString() ?? "Unknown"; + private string DebuggerDisplay => $"{ChannelId} ({(IsEnabled ? "Enabled" : "Disabled")})"; + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index a08ba06ef..2365ec6a6 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -48,6 +48,8 @@ namespace Discord.WebSocket /// public bool IsEmbeddable { get; private set; } /// + public bool IsWidgetEnabled { get; private set; } + /// public VerificationLevel VerificationLevel { get; private set; } /// public MfaLevel MfaLevel { get; private set; } @@ -83,7 +85,10 @@ namespace Discord.WebSocket internal ulong? AFKChannelId { get; private set; } internal ulong? EmbedChannelId { get; private set; } + internal ulong? WidgetChannelId { get; private set; } internal ulong? SystemChannelId { get; private set; } + internal ulong? RulesChannelId { get; private set; } + internal ulong? PublicUpdatesChannelId { get; private set; } /// public ulong OwnerId { get; private set; } /// Gets the user that owns this guild. @@ -95,6 +100,8 @@ namespace Discord.WebSocket /// public string SplashId { get; private set; } /// + public string DiscoverySplashId { get; private set; } + /// public PremiumTier PremiumTier { get; private set; } /// public string BannerId { get; private set; } @@ -108,6 +115,12 @@ namespace Discord.WebSocket public int PremiumSubscriptionCount { get; private set; } /// public string PreferredLocale { get; private set; } + /// + public int? MaxPresences { get; private set; } + /// + public int? MaxMembers { get; private set; } + /// + public int? MaxVideoChannelUsers { get; private set; } /// public CultureInfo PreferredCulture { get; private set; } @@ -119,6 +132,8 @@ namespace Discord.WebSocket /// public string SplashUrl => CDN.GetGuildSplashUrl(Id, SplashId); /// + public string DiscoverySplashUrl => CDN.GetGuildDiscoverySplashUrl(Id, DiscoverySplashId); + /// public string BannerUrl => CDN.GetGuildBannerUrl(Id, BannerId); /// Indicates whether the client has all the members downloaded to the local guild cache. public bool HasAllMembers => MemberCount == DownloadedMemberCount;// _downloaderPromise.Task.IsCompleted; @@ -152,7 +167,7 @@ namespace Discord.WebSocket /// /// /// A that the AFK users will be moved to after they have idled for too - /// long; null if none is set. + /// long; if none is set. /// public SocketVoiceChannel AFKChannel { @@ -166,8 +181,9 @@ namespace Discord.WebSocket /// Gets the embed channel (i.e. the channel set in the guild's widget settings) in this guild. /// /// - /// A channel set within the server's widget settings; null if none is set. + /// A channel set within the server's widget settings; if none is set. /// + [Obsolete("This property is deprecated, use WidgetChannel instead.")] public SocketGuildChannel EmbedChannel { get @@ -177,10 +193,24 @@ namespace Discord.WebSocket } } /// + /// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild. + /// + /// + /// A channel set within the server's widget settings; if none is set. + /// + public SocketGuildChannel WidgetChannel + { + get + { + var id = WidgetChannelId; + return id.HasValue ? GetChannel(id.Value) : null; + } + } + /// /// Gets the system channel where randomized welcome messages are sent in this guild. /// /// - /// A text channel where randomized welcome messages will be sent to; null if none is set. + /// A text channel where randomized welcome messages will be sent to; if none is set. /// public SocketTextChannel SystemChannel { @@ -191,6 +221,36 @@ namespace Discord.WebSocket } } /// + /// Gets the channel with the guild rules. + /// + /// + /// A text channel with the guild rules; if none is set. + /// + public SocketTextChannel RulesChannel + { + get + { + var id = RulesChannelId; + return id.HasValue ? GetTextChannel(id.Value) : null; + } + } + /// + /// Gets the channel where admins and moderators of Community guilds receive + /// notices from Discord. + /// + /// + /// A text channel where admins and moderators of Community guilds receive + /// notices from Discord; if none is set. + /// + public SocketTextChannel PublicUpdatesChannel + { + get + { + var id = PublicUpdatesChannelId; + return id.HasValue ? GetTextChannel(id.Value) : null; + } + } + /// /// Gets a collection of all text channels in this guild. /// /// @@ -360,15 +420,24 @@ namespace Discord.WebSocket internal void Update(ClientState state, Model model) { AFKChannelId = model.AFKChannelId; - EmbedChannelId = model.EmbedChannelId; + if (model.EmbedChannelId.IsSpecified) + EmbedChannelId = model.EmbedChannelId.Value; + if (model.WidgetChannelId.IsSpecified) + WidgetChannelId = model.WidgetChannelId.Value; SystemChannelId = model.SystemChannelId; + RulesChannelId = model.RulesChannelId; + PublicUpdatesChannelId = model.PublicUpdatesChannelId; AFKTimeout = model.AFKTimeout; - IsEmbeddable = model.EmbedEnabled; + if (model.EmbedEnabled.IsSpecified) + IsEmbeddable = model.EmbedEnabled.Value; + if (model.WidgetEnabled.IsSpecified) + IsWidgetEnabled = model.WidgetEnabled.Value; IconId = model.Icon; Name = model.Name; OwnerId = model.OwnerId; VoiceRegionId = model.Region; SplashId = model.Splash; + DiscoverySplashId = model.DiscoverySplash; VerificationLevel = model.VerificationLevel; MfaLevel = model.MfaLevel; DefaultMessageNotifications = model.DefaultMessageNotifications; @@ -379,7 +448,14 @@ namespace Discord.WebSocket BannerId = model.Banner; SystemChannelFlags = model.SystemChannelFlags; Description = model.Description; - PremiumSubscriptionCount = model.PremiumSubscriptionCount.GetValueOrDefault(); + if (model.PremiumSubscriptionCount.IsSpecified) + PremiumSubscriptionCount = model.PremiumSubscriptionCount.Value; + if (model.MaxPresences.IsSpecified) + MaxPresences = model.MaxPresences.Value ?? 25000; + if (model.MaxMembers.IsSpecified) + MaxMembers = model.MaxMembers.Value; + if (model.MaxVideoChannelUsers.IsSpecified) + MaxVideoChannelUsers = model.MaxVideoChannelUsers.Value; PreferredLocale = model.PreferredLocale; PreferredCulture = PreferredLocale == null ? null : new CultureInfo(PreferredLocale); @@ -447,15 +523,20 @@ namespace Discord.WebSocket => GuildHelper.DeleteAsync(this, Discord, options); /// - /// is null. + /// is . public Task ModifyAsync(Action func, RequestOptions options = null) => GuildHelper.ModifyAsync(this, Discord, func, options); /// - /// is null. + /// is . + [Obsolete("This endpoint is deprecated, use ModifyWidgetAsync instead.")] public Task ModifyEmbedAsync(Action func, RequestOptions options = null) => GuildHelper.ModifyEmbedAsync(this, Discord, func, options); /// + /// is . + public Task ModifyWidgetAsync(Action func, RequestOptions options = null) + => GuildHelper.ModifyWidgetAsync(this, Discord, func, options); + /// public Task ReorderChannelsAsync(IEnumerable args, RequestOptions options = null) => GuildHelper.ReorderChannelsAsync(this, Discord, args, options); /// @@ -485,7 +566,7 @@ namespace Discord.WebSocket /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains a ban object, which - /// contains the user information and the reason for the ban; null if the ban entry cannot be found. + /// contains the user information and the reason for the ban; if the ban entry cannot be found. /// public Task GetBanAsync(IUser user, RequestOptions options = null) => GuildHelper.GetBanAsync(this, Discord, user.Id, options); @@ -496,7 +577,7 @@ namespace Discord.WebSocket /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains a ban object, which - /// contains the user information and the reason for the ban; null if the ban entry cannot be found. + /// contains the user information and the reason for the ban; if the ban entry cannot be found. /// public Task GetBanAsync(ulong userId, RequestOptions options = null) => GuildHelper.GetBanAsync(this, Discord, userId, options); @@ -521,7 +602,7 @@ namespace Discord.WebSocket /// /// The snowflake identifier for the channel. /// - /// A generic channel associated with the specified ; null if none is found. + /// A generic channel associated with the specified ; if none is found. /// public SocketGuildChannel GetChannel(ulong id) { @@ -535,7 +616,7 @@ namespace Discord.WebSocket /// /// The snowflake identifier for the text channel. /// - /// A text channel associated with the specified ; null if none is found. + /// A text channel associated with the specified ; if none is found. /// public SocketTextChannel GetTextChannel(ulong id) => GetChannel(id) as SocketTextChannel; @@ -544,7 +625,7 @@ namespace Discord.WebSocket /// /// The snowflake identifier for the voice channel. /// - /// A voice channel associated with the specified ; null if none is found. + /// A voice channel associated with the specified ; if none is found. /// public SocketVoiceChannel GetVoiceChannel(ulong id) => GetChannel(id) as SocketVoiceChannel; @@ -553,7 +634,7 @@ namespace Discord.WebSocket /// /// The snowflake identifier for the category channel. /// - /// A category channel associated with the specified ; null if none is found. + /// A category channel associated with the specified ; if none is found. /// public SocketCategoryChannel GetCategoryChannel(ulong id) => GetChannel(id) as SocketCategoryChannel; @@ -589,7 +670,7 @@ namespace Discord.WebSocket /// The new name for the voice channel. /// The delegate containing the properties to be applied to the channel upon its creation. /// The options to be used when sending the request. - /// is null. + /// is . /// /// A task that represents the asynchronous creation operation. The task result contains the newly created /// voice channel. @@ -602,7 +683,7 @@ namespace Discord.WebSocket /// The new name for the category. /// The delegate containing the properties to be applied to the channel upon its creation. /// The options to be used when sending the request. - /// is null. + /// is . /// /// A task that represents the asynchronous creation operation. The task result contains the newly created /// category channel. @@ -666,7 +747,7 @@ namespace Discord.WebSocket /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the partial metadata of - /// the vanity invite found within this guild; null if none is found. + /// the vanity invite found within this guild; if none is found. /// public Task GetVanityInviteAsync(RequestOptions options = null) => GuildHelper.GetVanityInviteAsync(this, Discord, options); @@ -677,7 +758,7 @@ namespace Discord.WebSocket /// /// The snowflake identifier for the role. /// - /// A role that is associated with the specified ; null if none is found. + /// A role that is associated with the specified ; if none is found. /// public SocketRole GetRole(ulong id) { @@ -699,7 +780,7 @@ namespace Discord.WebSocket /// Whether the role is separated from others on the sidebar. /// Whether the role can be mentioned. /// The options to be used when sending the request. - /// is null. + /// is . /// /// A task that represents the asynchronous creation operation. The task result contains the newly created /// role. @@ -731,13 +812,13 @@ namespace Discord.WebSocket /// /// This method retrieves a user found within this guild. /// - /// This may return null in the WebSocket implementation due to incomplete user collection in + /// This may return in the WebSocket implementation due to incomplete user collection in /// large guilds. /// /// /// The snowflake identifier of the user. /// - /// A guild user associated with the specified ; null if none is found. + /// A guild user associated with the specified ; if none is found. /// public SocketGuildUser GetUser(ulong id) { @@ -891,7 +972,7 @@ namespace Discord.WebSocket /// The options to be used when sending the request. /// /// A task that represents the asynchronous get operation. The task result contains the webhook with the - /// specified ; null if none is found. + /// specified ; if none is found. /// public Task GetWebhookAsync(ulong id, RequestOptions options = null) => GuildHelper.GetWebhookAsync(this, Discord, id, options); @@ -914,7 +995,7 @@ namespace Discord.WebSocket public Task CreateEmoteAsync(string name, Image image, Optional> roles = default(Optional>), RequestOptions options = null) => GuildHelper.CreateEmoteAsync(this, Discord, name, image, roles, options); /// - /// is null. + /// is . public Task ModifyEmoteAsync(GuildEmote emote, Action func, RequestOptions options = null) => GuildHelper.ModifyEmoteAsync(this, Discord, emote.Id, func, options); /// @@ -1133,11 +1214,21 @@ namespace Discord.WebSocket /// ulong? IGuild.EmbedChannelId => EmbedChannelId; /// + ulong? IGuild.WidgetChannelId => WidgetChannelId; + /// ulong? IGuild.SystemChannelId => SystemChannelId; /// + ulong? IGuild.RulesChannelId => RulesChannelId; + /// + ulong? IGuild.PublicUpdatesChannelId => PublicUpdatesChannelId; + /// IRole IGuild.EveryoneRole => EveryoneRole; /// IReadOnlyCollection IGuild.Roles => Roles; + /// + int? IGuild.ApproximateMemberCount => null; + /// + int? IGuild.ApproximatePresenceCount => null; /// async Task> IGuild.GetBansAsync(RequestOptions options) @@ -1177,12 +1268,22 @@ namespace Discord.WebSocket Task IGuild.GetDefaultChannelAsync(CacheMode mode, RequestOptions options) => Task.FromResult(DefaultChannel); /// + [Obsolete("This method is deprecated, use GetWidgetChannelAsync instead.")] Task IGuild.GetEmbedChannelAsync(CacheMode mode, RequestOptions options) => Task.FromResult(EmbedChannel); /// + Task IGuild.GetWidgetChannelAsync(CacheMode mode, RequestOptions options) + => Task.FromResult(WidgetChannel); + /// Task IGuild.GetSystemChannelAsync(CacheMode mode, RequestOptions options) => Task.FromResult(SystemChannel); /// + Task IGuild.GetRulesChannelAsync(CacheMode mode, RequestOptions options) + => Task.FromResult(RulesChannel); + /// + Task IGuild.GetPublicUpdatesChannelAsync(CacheMode mode, RequestOptions options) + => Task.FromResult(PublicUpdatesChannel); + /// async Task IGuild.CreateTextChannelAsync(string name, Action func, RequestOptions options) => await CreateTextChannelAsync(name, func, options).ConfigureAwait(false); ///