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
This commit is contained in:
Paulo
2020-11-17 05:23:45 -03:00
committed by GitHub
parent 04389a4f3e
commit ec212b175d
14 changed files with 644 additions and 96 deletions

View File

@@ -48,6 +48,8 @@ namespace Discord.WebSocket
/// <inheritdoc />
public bool IsEmbeddable { get; private set; }
/// <inheritdoc />
public bool IsWidgetEnabled { get; private set; }
/// <inheritdoc />
public VerificationLevel VerificationLevel { get; private set; }
/// <inheritdoc />
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; }
/// <inheritdoc />
public ulong OwnerId { get; private set; }
/// <summary> Gets the user that owns this guild. </summary>
@@ -95,6 +100,8 @@ namespace Discord.WebSocket
/// <inheritdoc />
public string SplashId { get; private set; }
/// <inheritdoc />
public string DiscoverySplashId { get; private set; }
/// <inheritdoc />
public PremiumTier PremiumTier { get; private set; }
/// <inheritdoc />
public string BannerId { get; private set; }
@@ -108,6 +115,12 @@ namespace Discord.WebSocket
public int PremiumSubscriptionCount { get; private set; }
/// <inheritdoc />
public string PreferredLocale { get; private set; }
/// <inheritdoc />
public int? MaxPresences { get; private set; }
/// <inheritdoc />
public int? MaxMembers { get; private set; }
/// <inheritdoc />
public int? MaxVideoChannelUsers { get; private set; }
/// <inheritdoc />
public CultureInfo PreferredCulture { get; private set; }
@@ -119,6 +132,8 @@ namespace Discord.WebSocket
/// <inheritdoc />
public string SplashUrl => CDN.GetGuildSplashUrl(Id, SplashId);
/// <inheritdoc />
public string DiscoverySplashUrl => CDN.GetGuildDiscoverySplashUrl(Id, DiscoverySplashId);
/// <inheritdoc />
public string BannerUrl => CDN.GetGuildBannerUrl(Id, BannerId);
/// <summary> Indicates whether the client has all the members downloaded to the local guild cache. </summary>
public bool HasAllMembers => MemberCount == DownloadedMemberCount;// _downloaderPromise.Task.IsCompleted;
@@ -152,7 +167,7 @@ namespace Discord.WebSocket
/// </summary>
/// <returns>
/// A <see cref="SocketVoiceChannel" /> that the AFK users will be moved to after they have idled for too
/// long; <c>null</c> if none is set.
/// long; <see langword="null"/> if none is set.
/// </returns>
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.
/// </summary>
/// <returns>
/// A channel set within the server's widget settings; <c>null</c> if none is set.
/// A channel set within the server's widget settings; <see langword="null"/> if none is set.
/// </returns>
[Obsolete("This property is deprecated, use WidgetChannel instead.")]
public SocketGuildChannel EmbedChannel
{
get
@@ -177,10 +193,24 @@ namespace Discord.WebSocket
}
}
/// <summary>
/// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild.
/// </summary>
/// <returns>
/// A channel set within the server's widget settings; <see langword="null"/> if none is set.
/// </returns>
public SocketGuildChannel WidgetChannel
{
get
{
var id = WidgetChannelId;
return id.HasValue ? GetChannel(id.Value) : null;
}
}
/// <summary>
/// Gets the system channel where randomized welcome messages are sent in this guild.
/// </summary>
/// <returns>
/// A text channel where randomized welcome messages will be sent to; <c>null</c> if none is set.
/// A text channel where randomized welcome messages will be sent to; <see langword="null"/> if none is set.
/// </returns>
public SocketTextChannel SystemChannel
{
@@ -191,6 +221,36 @@ namespace Discord.WebSocket
}
}
/// <summary>
/// Gets the channel with the guild rules.
/// </summary>
/// <returns>
/// A text channel with the guild rules; <see langword="null"/> if none is set.
/// </returns>
public SocketTextChannel RulesChannel
{
get
{
var id = RulesChannelId;
return id.HasValue ? GetTextChannel(id.Value) : null;
}
}
/// <summary>
/// Gets the channel where admins and moderators of Community guilds receive
/// notices from Discord.
/// </summary>
/// <returns>
/// A text channel where admins and moderators of Community guilds receive
/// notices from Discord; <see langword="null"/> if none is set.
/// </returns>
public SocketTextChannel PublicUpdatesChannel
{
get
{
var id = PublicUpdatesChannelId;
return id.HasValue ? GetTextChannel(id.Value) : null;
}
}
/// <summary>
/// Gets a collection of all text channels in this guild.
/// </summary>
/// <returns>
@@ -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);
/// <inheritdoc />
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception>
public Task ModifyAsync(Action<GuildProperties> func, RequestOptions options = null)
=> GuildHelper.ModifyAsync(this, Discord, func, options);
/// <inheritdoc />
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception>
[Obsolete("This endpoint is deprecated, use ModifyWidgetAsync instead.")]
public Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null)
=> GuildHelper.ModifyEmbedAsync(this, Discord, func, options);
/// <inheritdoc />
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception>
public Task ModifyWidgetAsync(Action<GuildWidgetProperties> func, RequestOptions options = null)
=> GuildHelper.ModifyWidgetAsync(this, Discord, func, options);
/// <inheritdoc />
public Task ReorderChannelsAsync(IEnumerable<ReorderChannelProperties> args, RequestOptions options = null)
=> GuildHelper.ReorderChannelsAsync(this, Discord, args, options);
/// <inheritdoc />
@@ -485,7 +566,7 @@ namespace Discord.WebSocket
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// 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; <c>null</c> if the ban entry cannot be found.
/// contains the user information and the reason for the ban; <see langword="null"/> if the ban entry cannot be found.
/// </returns>
public Task<RestBan> GetBanAsync(IUser user, RequestOptions options = null)
=> GuildHelper.GetBanAsync(this, Discord, user.Id, options);
@@ -496,7 +577,7 @@ namespace Discord.WebSocket
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// 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; <c>null</c> if the ban entry cannot be found.
/// contains the user information and the reason for the ban; <see langword="null"/> if the ban entry cannot be found.
/// </returns>
public Task<RestBan> GetBanAsync(ulong userId, RequestOptions options = null)
=> GuildHelper.GetBanAsync(this, Discord, userId, options);
@@ -521,7 +602,7 @@ namespace Discord.WebSocket
/// </summary>
/// <param name="id">The snowflake identifier for the channel.</param>
/// <returns>
/// A generic channel associated with the specified <paramref name="id" />; <c>null</c> if none is found.
/// A generic channel associated with the specified <paramref name="id" />; <see langword="null"/> if none is found.
/// </returns>
public SocketGuildChannel GetChannel(ulong id)
{
@@ -535,7 +616,7 @@ namespace Discord.WebSocket
/// </summary>
/// <param name="id">The snowflake identifier for the text channel.</param>
/// <returns>
/// A text channel associated with the specified <paramref name="id" />; <c>null</c> if none is found.
/// A text channel associated with the specified <paramref name="id" />; <see langword="null"/> if none is found.
/// </returns>
public SocketTextChannel GetTextChannel(ulong id)
=> GetChannel(id) as SocketTextChannel;
@@ -544,7 +625,7 @@ namespace Discord.WebSocket
/// </summary>
/// <param name="id">The snowflake identifier for the voice channel.</param>
/// <returns>
/// A voice channel associated with the specified <paramref name="id" />; <c>null</c> if none is found.
/// A voice channel associated with the specified <paramref name="id" />; <see langword="null"/> if none is found.
/// </returns>
public SocketVoiceChannel GetVoiceChannel(ulong id)
=> GetChannel(id) as SocketVoiceChannel;
@@ -553,7 +634,7 @@ namespace Discord.WebSocket
/// </summary>
/// <param name="id">The snowflake identifier for the category channel.</param>
/// <returns>
/// A category channel associated with the specified <paramref name="id" />; <c>null</c> if none is found.
/// A category channel associated with the specified <paramref name="id" />; <see langword="null"/> if none is found.
/// </returns>
public SocketCategoryChannel GetCategoryChannel(ulong id)
=> GetChannel(id) as SocketCategoryChannel;
@@ -589,7 +670,7 @@ namespace Discord.WebSocket
/// <param name="name">The new name for the voice channel.</param>
/// <param name="func">The delegate containing the properties to be applied to the channel upon its creation.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <see langword="null"/>.</exception>
/// <returns>
/// A task that represents the asynchronous creation operation. The task result contains the newly created
/// voice channel.
@@ -602,7 +683,7 @@ namespace Discord.WebSocket
/// <param name="name">The new name for the category.</param>
/// <param name="func">The delegate containing the properties to be applied to the channel upon its creation.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <see langword="null"/>.</exception>
/// <returns>
/// A task that represents the asynchronous creation operation. The task result contains the newly created
/// category channel.
@@ -666,7 +747,7 @@ namespace Discord.WebSocket
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous get operation. The task result contains the partial metadata of
/// the vanity invite found within this guild; <c>null</c> if none is found.
/// the vanity invite found within this guild; <see langword="null"/> if none is found.
/// </returns>
public Task<RestInviteMetadata> GetVanityInviteAsync(RequestOptions options = null)
=> GuildHelper.GetVanityInviteAsync(this, Discord, options);
@@ -677,7 +758,7 @@ namespace Discord.WebSocket
/// </summary>
/// <param name="id">The snowflake identifier for the role.</param>
/// <returns>
/// A role that is associated with the specified <paramref name="id"/>; <c>null</c> if none is found.
/// A role that is associated with the specified <paramref name="id"/>; <see langword="null"/> if none is found.
/// </returns>
public SocketRole GetRole(ulong id)
{
@@ -699,7 +780,7 @@ namespace Discord.WebSocket
/// <param name="isHoisted">Whether the role is separated from others on the sidebar.</param>
/// <param name="isMentionable">Whether the role can be mentioned.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <see langword="null"/>.</exception>
/// <returns>
/// A task that represents the asynchronous creation operation. The task result contains the newly created
/// role.
@@ -731,13 +812,13 @@ namespace Discord.WebSocket
/// <remarks>
/// This method retrieves a user found within this guild.
/// <note>
/// This may return <c>null</c> in the WebSocket implementation due to incomplete user collection in
/// This may return <see langword="null"/> in the WebSocket implementation due to incomplete user collection in
/// large guilds.
/// </note>
/// </remarks>
/// <param name="id">The snowflake identifier of the user.</param>
/// <returns>
/// A guild user associated with the specified <paramref name="id"/>; <c>null</c> if none is found.
/// A guild user associated with the specified <paramref name="id"/>; <see langword="null"/> if none is found.
/// </returns>
public SocketGuildUser GetUser(ulong id)
{
@@ -891,7 +972,7 @@ namespace Discord.WebSocket
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous get operation. The task result contains the webhook with the
/// specified <paramref name="id"/>; <c>null</c> if none is found.
/// specified <paramref name="id"/>; <see langword="null"/> if none is found.
/// </returns>
public Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null)
=> GuildHelper.GetWebhookAsync(this, Discord, id, options);
@@ -914,7 +995,7 @@ namespace Discord.WebSocket
public Task<GuildEmote> CreateEmoteAsync(string name, Image image, Optional<IEnumerable<IRole>> roles = default(Optional<IEnumerable<IRole>>), RequestOptions options = null)
=> GuildHelper.CreateEmoteAsync(this, Discord, name, image, roles, options);
/// <inheritdoc />
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception>
public Task<GuildEmote> ModifyEmoteAsync(GuildEmote emote, Action<EmoteProperties> func, RequestOptions options = null)
=> GuildHelper.ModifyEmoteAsync(this, Discord, emote.Id, func, options);
/// <inheritdoc />
@@ -1133,11 +1214,21 @@ namespace Discord.WebSocket
/// <inheritdoc />
ulong? IGuild.EmbedChannelId => EmbedChannelId;
/// <inheritdoc />
ulong? IGuild.WidgetChannelId => WidgetChannelId;
/// <inheritdoc />
ulong? IGuild.SystemChannelId => SystemChannelId;
/// <inheritdoc />
ulong? IGuild.RulesChannelId => RulesChannelId;
/// <inheritdoc />
ulong? IGuild.PublicUpdatesChannelId => PublicUpdatesChannelId;
/// <inheritdoc />
IRole IGuild.EveryoneRole => EveryoneRole;
/// <inheritdoc />
IReadOnlyCollection<IRole> IGuild.Roles => Roles;
/// <inheritdoc />
int? IGuild.ApproximateMemberCount => null;
/// <inheritdoc />
int? IGuild.ApproximatePresenceCount => null;
/// <inheritdoc />
async Task<IReadOnlyCollection<IBan>> IGuild.GetBansAsync(RequestOptions options)
@@ -1177,12 +1268,22 @@ namespace Discord.WebSocket
Task<ITextChannel> IGuild.GetDefaultChannelAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<ITextChannel>(DefaultChannel);
/// <inheritdoc />
[Obsolete("This method is deprecated, use GetWidgetChannelAsync instead.")]
Task<IGuildChannel> IGuild.GetEmbedChannelAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<IGuildChannel>(EmbedChannel);
/// <inheritdoc />
Task<IGuildChannel> IGuild.GetWidgetChannelAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<IGuildChannel>(WidgetChannel);
/// <inheritdoc />
Task<ITextChannel> IGuild.GetSystemChannelAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<ITextChannel>(SystemChannel);
/// <inheritdoc />
Task<ITextChannel> IGuild.GetRulesChannelAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<ITextChannel>(RulesChannel);
/// <inheritdoc />
Task<ITextChannel> IGuild.GetPublicUpdatesChannelAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<ITextChannel>(PublicUpdatesChannel);
/// <inheritdoc />
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, Action<TextChannelProperties> func, RequestOptions options)
=> await CreateTextChannelAsync(name, func, options).ConfigureAwait(false);
/// <inheritdoc />