From 7075d4ee35a572740aeae928afd42750faa22e6c Mon Sep 17 00:00:00 2001 From: Quin Lynch <49576606+quinchs@users.noreply.github.com> Date: Fri, 14 Jan 2022 07:56:20 -0400 Subject: [PATCH] Add missing guild features (#2036) --- .../Entities/Guilds/GuildFeature.cs | 124 ++++++++++++++---- .../Entities/Guilds/GuildFeatures.cs | 81 +++++++++++- .../Entities/Guilds/GuildHelper.cs | 6 + 3 files changed, 188 insertions(+), 23 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Guilds/GuildFeature.cs b/src/Discord.Net.Core/Entities/Guilds/GuildFeature.cs index e3c325227..aec637be2 100644 --- a/src/Discord.Net.Core/Entities/Guilds/GuildFeature.cs +++ b/src/Discord.Net.Core/Entities/Guilds/GuildFeature.cs @@ -14,92 +14,172 @@ namespace Discord /// None = 0, /// + /// The guild has access to animated banners. + /// + AnimatedBanner = 1 << 0, + /// /// The guild has access to set an animated guild icon. /// - AnimatedIcon = 1 << 0, + AnimatedIcon = 1 << 1, /// /// The guild has access to set a guild banner image. /// - Banner = 1 << 1, + Banner = 1 << 2, + /// + /// The guild has access to channel banners. + /// + ChannelBanner = 1 << 3, /// /// The guild has access to use commerce features (i.e. create store channels). /// - Commerce = 1 << 2, + Commerce = 1 << 4, /// /// The guild can enable welcome screen, Membership Screening, stage channels and discovery, and receives community updates. /// - Community = 1 << 3, + Community = 1 << 5, /// /// The guild is able to be discovered in the directory. /// - Discoverable = 1 << 4, + Discoverable = 1 << 6, + /// + /// The guild has discoverable disabled. + /// + DiscoverableDisabled = 1 << 7, + /// + /// The guild has enabled discoverable before. + /// + EnabledDiscoverableBefore = 1 << 8, /// /// The guild is able to be featured in the directory. /// - Featureable = 1 << 5, + Featureable = 1 << 9, + /// + /// The guild has a force relay. + /// + ForceRelay = 1 << 10, + /// + /// The guild has a directory entry. + /// + HasDirectoryEntry = 1 << 11, + /// + /// The guild is a hub. + /// + Hub = 1 << 12, + /// + /// You shouldn't be here... + /// + InternalEmployeeOnly = 1 << 13, /// /// The guild has access to set an invite splash background. /// - InviteSplash = 1 << 6, + InviteSplash = 1 << 14, + /// + /// The guild is linked to a hub. + /// + LinkedToHub = 1 << 15, + /// + /// The guild has member profiles. + /// + MemberProfiles = 1 << 16, /// /// The guild has enabled Membership Screening. /// - MemberVerificationGateEnabled = 1 << 7, + MemberVerificationGateEnabled = 1 << 17, /// /// The guild has enabled monetization. /// - MonetizationEnabled = 1 << 8, + MonetizationEnabled = 1 << 18, + /// + /// The guild has more emojis. + /// + MoreEmoji = 1 << 19, /// /// The guild has increased custom sticker slots. /// - MoreStickers = 1 << 9, + MoreStickers = 1 << 20, /// /// The guild has access to create news channels. /// - News = 1 << 10, + News = 1 << 21, + /// + /// The guild has new thread permissions. + /// + NewThreadPermissions = 1 << 22, /// /// The guild is partnered. /// - Partnered = 1 << 11, + Partnered = 1 << 23, + /// + /// The guild has a premium tier three override; guilds made by Discord usually have this. + /// + PremiumTier3Override = 1 << 24, /// /// The guild can be previewed before joining via Membership Screening or the directory. /// - PreviewEnabled = 1 << 12, + PreviewEnabled = 1 << 25, /// /// The guild has access to create private threads. /// - PrivateThreads = 1 << 13, + PrivateThreads = 1 << 26, + /// + /// The guild has relay enabled. + /// + RelayEnabled = 1 << 27, /// /// The guild is able to set role icons. /// - RoleIcons = 1 << 14, + RoleIcons = 1 << 28, + /// + /// The guild has role subscriptions available for purchase. + /// + RoleSubscriptionsAvailableForPurchase = 1 << 29, + /// + /// The guild has role subscriptions enabled. + /// + RoleSubscriptionsEnabled = 1 << 30, /// /// The guild has access to the seven day archive time for threads. /// - SevenDayThreadArchive = 1 << 15, + SevenDayThreadArchive = 1 << 31, + /// + /// The guild has text in voice enabled. + /// + TextInVoiceEnabled = 1 << 32, + /// + /// The guild has threads enabled. + /// + ThreadsEnabled = 1 << 33, + /// + /// The guild has testing threads enabled. + /// + ThreadsEnabledTesting = 1 << 34, + /// + /// The guild has the default thread auto archive. + /// + ThreadsDefaultAutoArchiveDuration = 1 << 35, /// /// The guild has access to the three day archive time for threads. /// - ThreeDayThreadArchive = 1 << 16, + ThreeDayThreadArchive = 1 << 36, /// /// The guild has enabled ticketed events. /// - TicketedEventsEnabled = 1 << 17, + TicketedEventsEnabled = 1 << 37, /// /// The guild has access to set a vanity URL. /// - VanityUrl = 1 << 18, + VanityUrl = 1 << 38, /// /// The guild is verified. /// - Verified = 1 << 19, + Verified = 1 << 39, /// /// The guild has access to set 384kbps bitrate in voice (previously VIP voice servers). /// - VIPRegions = 1 << 20, + VIPRegions = 1 << 40, /// /// The guild has enabled the welcome screen. /// - WelcomeScreenEnabled = 1 << 21, + WelcomeScreenEnabled = 1 << 41, } } diff --git a/src/Discord.Net.Core/Entities/Guilds/GuildFeatures.cs b/src/Discord.Net.Core/Entities/Guilds/GuildFeatures.cs index 699e47cf3..b553a8340 100644 --- a/src/Discord.Net.Core/Entities/Guilds/GuildFeatures.cs +++ b/src/Discord.Net.Core/Entities/Guilds/GuildFeatures.cs @@ -15,10 +15,78 @@ namespace Discord public GuildFeature Value { get; } /// - /// Gets a collection of experimental features for this guild. + /// Gets a collection of experimental features for this guild. Features that are not contained in are put in here. /// public IReadOnlyCollection Experimental { get; } + /// + /// Gets whether or not the guild has threads enabled. + /// + public bool HasThreads + => HasFeature(GuildFeature.ThreadsEnabled | GuildFeature.ThreadsEnabledTesting); + + /// + /// Gets whether or not the guild has text-in-voice enabled. + /// + public bool HasTextInVoice + => HasFeature(GuildFeature.TextInVoiceEnabled); + + /// + /// Gets whether or not the server is a internal staff server. + /// + /// + /// You shouldn't touch anything here unless you know what you're doing :) + /// + public bool IsStaffServer + => HasFeature(GuildFeature.InternalEmployeeOnly); + + /// + /// Gets whether or not this server is a hub. + /// + public bool IsHub + => HasFeature(GuildFeature.Hub); + + /// + /// Gets whether or this server is linked to a hub server. + /// + public bool IsLinkedToHub + => HasFeature(GuildFeature.LinkedToHub); + + /// + /// Gets whether or not this server is partnered. + /// + public bool IsPartnered + => HasFeature(GuildFeature.Partnered); + + /// + /// Gets whether or not this server is verified. + /// + public bool IsVerified + => HasFeature(GuildFeature.Verified); + + /// + /// Gets whether or not this server has vanity urls enabled. + /// + public bool HasVanityUrl + => HasFeature(GuildFeature.VanityUrl); + + /// + /// Gets whether or not this server has role subscriptions enabled. + /// + public bool HasRoleSubscriptions + => HasFeature(GuildFeature.RoleSubscriptionsEnabled | GuildFeature.RoleSubscriptionsAvailableForPurchase); + + /// + /// Gets whether or not this server has role icons enabled. + /// + public bool HasRoleIcons + => HasFeature(GuildFeature.RoleIcons); + + /// + /// Gets whether or not this server has private threads enabled. + /// + public bool HasPrivateThreads + => HasFeature(GuildFeature.PrivateThreads); internal GuildFeatures(GuildFeature value, string[] experimental) { @@ -26,8 +94,19 @@ namespace Discord Experimental = experimental.ToImmutableArray(); } + /// + /// Returns whether or not this guild has a feature. + /// + /// The feature(s) to check for. + /// if this guild has the provided feature(s), otherwise . public bool HasFeature(GuildFeature feature) => Value.HasFlag(feature); + + /// + /// Returns whether or not this guild has a feature. + /// + /// The feature to check for. + /// if this guild has the provided feature, otherwise . public bool HasFeature(string feature) => Experimental.Contains(feature); diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index ff16c31f1..874d3c2cd 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -40,6 +40,12 @@ namespace Discord.Rest IsBoostProgressBarEnabled = args.IsBoostProgressBarEnabled }; + if (apiArgs.Banner.IsSpecified) + guild.Features.EnsureFeature(GuildFeature.Banner); + + if (apiArgs.Splash.IsSpecified) + guild.Features.EnsureFeature(GuildFeature.InviteSplash); + if (args.AfkChannel.IsSpecified) apiArgs.AfkChannelId = args.AfkChannel.Value.Id; else if (args.AfkChannelId.IsSpecified)