Browse Source

Add missing guild features (#2036)

tags/3.2.0
Quin Lynch GitHub 3 years ago
parent
commit
7075d4ee35
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 188 additions and 23 deletions
  1. +102
    -22
      src/Discord.Net.Core/Entities/Guilds/GuildFeature.cs
  2. +80
    -1
      src/Discord.Net.Core/Entities/Guilds/GuildFeatures.cs
  3. +6
    -0
      src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs

+ 102
- 22
src/Discord.Net.Core/Entities/Guilds/GuildFeature.cs View File

@@ -14,92 +14,172 @@ namespace Discord
/// </summary>
None = 0,
/// <summary>
/// The guild has access to animated banners.
/// </summary>
AnimatedBanner = 1 << 0,
/// <summary>
/// The guild has access to set an animated guild icon.
/// </summary>
AnimatedIcon = 1 << 0,
AnimatedIcon = 1 << 1,
/// <summary>
/// The guild has access to set a guild banner image.
/// </summary>
Banner = 1 << 1,
Banner = 1 << 2,
/// <summary>
/// The guild has access to channel banners.
/// </summary>
ChannelBanner = 1 << 3,
/// <summary>
/// The guild has access to use commerce features (i.e. create store channels).
/// </summary>
Commerce = 1 << 2,
Commerce = 1 << 4,
/// <summary>
/// The guild can enable welcome screen, Membership Screening, stage channels and discovery, and receives community updates.
/// </summary>
Community = 1 << 3,
Community = 1 << 5,
/// <summary>
/// The guild is able to be discovered in the directory.
/// </summary>
Discoverable = 1 << 4,
Discoverable = 1 << 6,
/// <summary>
/// The guild has discoverable disabled.
/// </summary>
DiscoverableDisabled = 1 << 7,
/// <summary>
/// The guild has enabled discoverable before.
/// </summary>
EnabledDiscoverableBefore = 1 << 8,
/// <summary>
/// The guild is able to be featured in the directory.
/// </summary>
Featureable = 1 << 5,
Featureable = 1 << 9,
/// <summary>
/// The guild has a force relay.
/// </summary>
ForceRelay = 1 << 10,
/// <summary>
/// The guild has a directory entry.
/// </summary>
HasDirectoryEntry = 1 << 11,
/// <summary>
/// The guild is a hub.
/// </summary>
Hub = 1 << 12,
/// <summary>
/// You shouldn't be here...
/// </summary>
InternalEmployeeOnly = 1 << 13,
/// <summary>
/// The guild has access to set an invite splash background.
/// </summary>
InviteSplash = 1 << 6,
InviteSplash = 1 << 14,
/// <summary>
/// The guild is linked to a hub.
/// </summary>
LinkedToHub = 1 << 15,
/// <summary>
/// The guild has member profiles.
/// </summary>
MemberProfiles = 1 << 16,
/// <summary>
/// The guild has enabled <seealso href="https://discord.com/developers/docs/resources/guild#membership-screening-object">Membership Screening</seealso>.
/// </summary>
MemberVerificationGateEnabled = 1 << 7,
MemberVerificationGateEnabled = 1 << 17,
/// <summary>
/// The guild has enabled monetization.
/// </summary>
MonetizationEnabled = 1 << 8,
MonetizationEnabled = 1 << 18,
/// <summary>
/// The guild has more emojis.
/// </summary>
MoreEmoji = 1 << 19,
/// <summary>
/// The guild has increased custom sticker slots.
/// </summary>
MoreStickers = 1 << 9,
MoreStickers = 1 << 20,
/// <summary>
/// The guild has access to create news channels.
/// </summary>
News = 1 << 10,
News = 1 << 21,
/// <summary>
/// The guild has new thread permissions.
/// </summary>
NewThreadPermissions = 1 << 22,
/// <summary>
/// The guild is partnered.
/// </summary>
Partnered = 1 << 11,
Partnered = 1 << 23,
/// <summary>
/// The guild has a premium tier three override; guilds made by Discord usually have this.
/// </summary>
PremiumTier3Override = 1 << 24,
/// <summary>
/// The guild can be previewed before joining via Membership Screening or the directory.
/// </summary>
PreviewEnabled = 1 << 12,
PreviewEnabled = 1 << 25,
/// <summary>
/// The guild has access to create private threads.
/// </summary>
PrivateThreads = 1 << 13,
PrivateThreads = 1 << 26,
/// <summary>
/// The guild has relay enabled.
/// </summary>
RelayEnabled = 1 << 27,
/// <summary>
/// The guild is able to set role icons.
/// </summary>
RoleIcons = 1 << 14,
RoleIcons = 1 << 28,
/// <summary>
/// The guild has role subscriptions available for purchase.
/// </summary>
RoleSubscriptionsAvailableForPurchase = 1 << 29,
/// <summary>
/// The guild has role subscriptions enabled.
/// </summary>
RoleSubscriptionsEnabled = 1 << 30,
/// <summary>
/// The guild has access to the seven day archive time for threads.
/// </summary>
SevenDayThreadArchive = 1 << 15,
SevenDayThreadArchive = 1 << 31,
/// <summary>
/// The guild has text in voice enabled.
/// </summary>
TextInVoiceEnabled = 1 << 32,
/// <summary>
/// The guild has threads enabled.
/// </summary>
ThreadsEnabled = 1 << 33,
/// <summary>
/// The guild has testing threads enabled.
/// </summary>
ThreadsEnabledTesting = 1 << 34,
/// <summary>
/// The guild has the default thread auto archive.
/// </summary>
ThreadsDefaultAutoArchiveDuration = 1 << 35,
/// <summary>
/// The guild has access to the three day archive time for threads.
/// </summary>
ThreeDayThreadArchive = 1 << 16,
ThreeDayThreadArchive = 1 << 36,
/// <summary>
/// The guild has enabled ticketed events.
/// </summary>
TicketedEventsEnabled = 1 << 17,
TicketedEventsEnabled = 1 << 37,
/// <summary>
/// The guild has access to set a vanity URL.
/// </summary>
VanityUrl = 1 << 18,
VanityUrl = 1 << 38,
/// <summary>
/// The guild is verified.
/// </summary>
Verified = 1 << 19,
Verified = 1 << 39,
/// <summary>
/// The guild has access to set 384kbps bitrate in voice (previously VIP voice servers).
/// </summary>
VIPRegions = 1 << 20,
VIPRegions = 1 << 40,
/// <summary>
/// The guild has enabled the welcome screen.
/// </summary>
WelcomeScreenEnabled = 1 << 21,
WelcomeScreenEnabled = 1 << 41,
}
}

+ 80
- 1
src/Discord.Net.Core/Entities/Guilds/GuildFeatures.cs View File

@@ -15,10 +15,78 @@ namespace Discord
public GuildFeature Value { get; }

/// <summary>
/// Gets a collection of experimental features for this guild.
/// Gets a collection of experimental features for this guild. Features that are not contained in <see cref="GuildFeature"/> are put in here.
/// </summary>
public IReadOnlyCollection<string> Experimental { get; }

/// <summary>
/// Gets whether or not the guild has threads enabled.
/// </summary>
public bool HasThreads
=> HasFeature(GuildFeature.ThreadsEnabled | GuildFeature.ThreadsEnabledTesting);

/// <summary>
/// Gets whether or not the guild has text-in-voice enabled.
/// </summary>
public bool HasTextInVoice
=> HasFeature(GuildFeature.TextInVoiceEnabled);

/// <summary>
/// Gets whether or not the server is a internal staff server.
/// </summary>
/// <remarks>
/// You shouldn't touch anything here unless you know what you're doing :)
/// </remarks>
public bool IsStaffServer
=> HasFeature(GuildFeature.InternalEmployeeOnly);

/// <summary>
/// Gets whether or not this server is a hub.
/// </summary>
public bool IsHub
=> HasFeature(GuildFeature.Hub);

/// <summary>
/// Gets whether or this server is linked to a hub server.
/// </summary>
public bool IsLinkedToHub
=> HasFeature(GuildFeature.LinkedToHub);

/// <summary>
/// Gets whether or not this server is partnered.
/// </summary>
public bool IsPartnered
=> HasFeature(GuildFeature.Partnered);

/// <summary>
/// Gets whether or not this server is verified.
/// </summary>
public bool IsVerified
=> HasFeature(GuildFeature.Verified);

/// <summary>
/// Gets whether or not this server has vanity urls enabled.
/// </summary>
public bool HasVanityUrl
=> HasFeature(GuildFeature.VanityUrl);

/// <summary>
/// Gets whether or not this server has role subscriptions enabled.
/// </summary>
public bool HasRoleSubscriptions
=> HasFeature(GuildFeature.RoleSubscriptionsEnabled | GuildFeature.RoleSubscriptionsAvailableForPurchase);

/// <summary>
/// Gets whether or not this server has role icons enabled.
/// </summary>
public bool HasRoleIcons
=> HasFeature(GuildFeature.RoleIcons);

/// <summary>
/// Gets whether or not this server has private threads enabled.
/// </summary>
public bool HasPrivateThreads
=> HasFeature(GuildFeature.PrivateThreads);

internal GuildFeatures(GuildFeature value, string[] experimental)
{
@@ -26,8 +94,19 @@ namespace Discord
Experimental = experimental.ToImmutableArray();
}

/// <summary>
/// Returns whether or not this guild has a feature.
/// </summary>
/// <param name="feature">The feature(s) to check for.</param>
/// <returns><see langword="true"/> if this guild has the provided feature(s), otherwise <see langword="false"/>.</returns>
public bool HasFeature(GuildFeature feature)
=> Value.HasFlag(feature);

/// <summary>
/// Returns whether or not this guild has a feature.
/// </summary>
/// <param name="feature">The feature to check for.</param>
/// <returns><see langword="true"/> if this guild has the provided feature, otherwise <see langword="false"/>.</returns>
public bool HasFeature(string feature)
=> Experimental.Contains(feature);



+ 6
- 0
src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs View File

@@ -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)


Loading…
Cancel
Save