From bfd193658196b8b09a816a92ed7e5b46f6bbc932 Mon Sep 17 00:00:00 2001 From: ITOH Date: Wed, 29 Mar 2023 17:49:04 +0200 Subject: [PATCH] feat(bot,client,types): add role subscriptions (#2899) Closes: https://github.com/discordeno/discordeno/issues/2859 Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> --- packages/bot/src/transformers/toggles/guild.ts | 13 ++++++++++++- packages/bot/src/transformers/toggles/role.ts | 6 ++++++ packages/client/src/Constants.ts | 6 ++++-- packages/client/src/Structures/guilds/Role.ts | 11 ++++++++++- packages/types/src/discord.ts | 6 +++++- packages/types/src/shared.ts | 10 ++++++++-- 6 files changed, 45 insertions(+), 7 deletions(-) diff --git a/packages/bot/src/transformers/toggles/guild.ts b/packages/bot/src/transformers/toggles/guild.ts index 677d7233b..af30bc036 100644 --- a/packages/bot/src/transformers/toggles/guild.ts +++ b/packages/bot/src/transformers/toggles/guild.ts @@ -53,6 +53,10 @@ export const GuildToggle = { partnered: 1n << 9n, /** Whether the guild can enable welcome screen, Membership Screening, stage channels and discovery, and receives community updates */ community: 1n << 10n, + /** Whether the guild has enabled monetization. */ + creatorMonetizableProvisional: 1n << 31n, + /** Whether the guild has enabled the role subscription promo page. */ + creatorStorePage: 1n << 32n, /** Whether the guild has access to set an animated guild banner image */ animatedBanner: 1n << 11n, /** Whether the guild has access to create news channels */ @@ -81,6 +85,10 @@ export const GuildToggle = { privateThreads: 1n << 26n, /** Whether the guild is able to set role icons */ roleIcons: 1n << 27n, + /** Whether the guild has role subscriptions that can be purchased. */ + roleSubscriptionsAvailableForPurchase: 1n << 33n, + /** Whether the guild has enabled role subscriptions. */ + roleSubscriptionsEnabled: 1n << 34n, /** Whether the guild has set up auto moderation rules */ autoModeration: 1n << 28n, /** Whether the guild has paused invites, preventing new users from joining */ @@ -111,6 +119,8 @@ export class GuildToggles extends ToggleBitfieldBigint { if (guild.features.includes(GuildFeatures.Verified)) this.add(GuildToggle.verified) if (guild.features.includes(GuildFeatures.Partnered)) this.add(GuildToggle.partnered) if (guild.features.includes(GuildFeatures.Community)) this.add(GuildToggle.community) + if (guild.features.includes(GuildFeatures.CreatorMonetizableProvisional)) this.add(GuildToggle.creatorMonetizableProvisional) + if (guild.features.includes(GuildFeatures.CreatorStorePage)) this.add(GuildToggle.creatorStorePage) if (guild.features.includes(GuildFeatures.DeveloperSupportServer)) this.add(GuildToggle.developerSupportServer) if (guild.features.includes(GuildFeatures.AnimatedBanner)) this.add(GuildToggle.animatedBanner) if (guild.features.includes(GuildFeatures.News)) this.add(GuildToggle.news) @@ -124,10 +134,11 @@ export class GuildToggles extends ToggleBitfieldBigint { } if (guild.features.includes(GuildFeatures.PreviewEnabled)) this.add(GuildToggle.previewEnabled) if (guild.features.includes(GuildFeatures.TicketedEventsEnabled)) this.add(GuildToggle.ticketedEventsEnabled) - if (guild.features.includes(GuildFeatures.MonetizationEnabled)) this.add(GuildToggle.monetizationEnabled) if (guild.features.includes(GuildFeatures.MoreStickers)) this.add(GuildToggle.moreStickers) if (guild.features.includes(GuildFeatures.PrivateThreads)) this.add(GuildToggle.privateThreads) if (guild.features.includes(GuildFeatures.RoleIcons)) this.add(GuildToggle.roleIcons) + if (guild.features.includes(GuildFeatures.RoleSubscriptionsAvailableForPurchase)) this.add(GuildToggle.roleSubscriptionsAvailableForPurchase) + if (guild.features.includes(GuildFeatures.RoleSubscriptionsEnabled)) this.add(GuildToggle.roleSubscriptionsEnabled) if (guild.features.includes(GuildFeatures.AutoModeration)) this.add(GuildToggle.autoModeration) if (guild.features.includes(GuildFeatures.InvitesDisabled)) this.add(GuildToggle.invitesDisabled) } diff --git a/packages/bot/src/transformers/toggles/role.ts b/packages/bot/src/transformers/toggles/role.ts index d47b43baf..661e659f5 100644 --- a/packages/bot/src/transformers/toggles/role.ts +++ b/packages/bot/src/transformers/toggles/role.ts @@ -10,6 +10,10 @@ export const RoleToggle = { mentionable: 1 << 2, /** Whether this is the guilds premium subscriber role */ premiumSubscriber: 1 << 3, + /** Whether this role is available for purchase. */ + availableForPurchase: 1 << 4, + /** Whether this role is available for guild connections. */ + guildConnections: 1 << 5, } export class RoleToggles extends ToggleBitfield { @@ -24,6 +28,8 @@ export class RoleToggles extends ToggleBitfield { if (role.managed) this.add(RoleToggle.managed) if (role.mentionable) this.add(RoleToggle.mentionable) if (role.tags?.premium_subscriber === null) this.add(RoleToggle.premiumSubscriber) + if (role.tags?.available_for_purchase === null) this.add(RoleToggle.availableForPurchase) + if (role.tags?.guild_connections === null) this.add(RoleToggle.guildConnections) } } diff --git a/packages/client/src/Constants.ts b/packages/client/src/Constants.ts index ed76d4f18..6fdb715c7 100644 --- a/packages/client/src/Constants.ts +++ b/packages/client/src/Constants.ts @@ -180,17 +180,19 @@ export const GuildFeatures = [ 'BANNER', 'COMMERCE', 'COMMUNITY', + 'CREATOR_MONETIZABLE_PROVISIONAL', + 'CREATOR_STORE_PAGE', 'DISCOVERABLE', 'FEATURABLE', 'INVITE_SPLASH', 'MEMBER_VERIFICATION_GATE_ENABLED', - 'MONETIZATION_ENABLED', 'MORE_STICKERS', 'NEWS', 'PARTNERED', 'PREVIEW_ENABLED', 'PRIVATE_THREADS', 'ROLE_ICONS', + 'ROLE_SUBSCRIPTIONS_AVAILABLE_FOR_PURCHASE', 'ROLE_SUBSCRIPTIONS_ENABLED', 'SEVEN_DAY_THREAD_ARCHIVE', 'THREE_DAY_THREAD_ARCHIVE', @@ -645,4 +647,4 @@ export const Constants = { WebhookTypes, } // eslint-disable-next-line @typescript-eslint/no-redeclare -export type Constants = typeof Constants; \ No newline at end of file +export type Constants = typeof Constants diff --git a/packages/client/src/Structures/guilds/Role.ts b/packages/client/src/Structures/guilds/Role.ts index 200a6e80a..627a6c820 100644 --- a/packages/client/src/Structures/guilds/Role.ts +++ b/packages/client/src/Structures/guilds/Role.ts @@ -20,7 +20,11 @@ export class Role extends Base { unicodeEmoji?: string position: number guild: Guild - tags?: Omit & { premium_subscriber?: boolean } + tags?: Omit & { + premium_subscriber?: boolean + available_for_purchase?: boolean + guild_connections?: boolean + } constructor(data: DiscordRole, guild: Guild) { super(data.id) @@ -40,6 +44,9 @@ export class Role extends Base { bot_id: data.tags.bot_id, integration_id: data.tags.integration_id, premium_subscriber: data.tags.premium_subscriber === null, + subscription_listing_id: data.tags.subscription_listing_id, + available_for_purchase: data.tags.available_for_purchase === null, + guild_connections: data.tags.guild_connections === null, } : undefined } @@ -70,6 +77,8 @@ export class Role extends Base { this.tags = { bot_id: data.tags.bot_id, integration_id: data.tags.integration_id, + subscription_listing_id: data.tags.subscription_listing_id, + available_for_purchase: data.tags.available_for_purchase === null, premium_subscriber: data.tags.premium_subscriber === null, } } diff --git a/packages/types/src/discord.ts b/packages/types/src/discord.ts index a5831b6a2..a9a557863 100644 --- a/packages/types/src/discord.ts +++ b/packages/types/src/discord.ts @@ -84,7 +84,7 @@ export interface DiscordIntegration { id: string /** Integration name */ name: string - /** Integration type (twitch, youtube or discord) */ + /** Integration type (twitch, youtube, discord, or guild_subscription). */ type: 'twitch' | 'youtube' | 'discord' /** Is this integration enabled */ enabled?: boolean @@ -616,6 +616,10 @@ export interface DiscordRoleTags { integration_id?: string /** Whether this is the guild's premium subscriber role */ premium_subscriber?: null + /** Id of this role's subscription sku and listing. */ + subscription_listing_id?: string + /** Whether this role is available for purchase. */ + available_for_purchase?: null /** Whether this is a guild's linked role */ guild_connections?: null } diff --git a/packages/types/src/shared.ts b/packages/types/src/shared.ts index 698b5a5a0..304b6eec2 100644 --- a/packages/types/src/shared.ts +++ b/packages/types/src/shared.ts @@ -187,6 +187,10 @@ export enum GuildFeatures { Partnered = 'PARTNERED', /** Guild can enable welcome screen, Membership Screening, stage channels and discovery, and receives community updates */ Community = 'COMMUNITY', + /** Guild has enabled monetization. */ + CreatorMonetizableProvisional = 'CREATOR_MONETIZABLE_PROVISIONAL', + /** Guild has enabled the role subscription promo page. */ + CreatorStorePage = 'CREATOR_STORE_PAGE', /** Guild has been set as a support server on the App Directory */ DeveloperSupportServer = 'DEVELOPER_SUPPORT_SERVER', /** Guild has access to create news channels */ @@ -207,14 +211,16 @@ export enum GuildFeatures { PreviewEnabled = 'PREVIEW_ENABLED', /** Guild has enabled ticketed events */ TicketedEventsEnabled = 'TICKETED_EVENTS_ENABLED', - /** Guild has enabled monetization */ - MonetizationEnabled = 'MONETIZATION_ENABLED', /** Guild has increased custom sticker slots */ MoreStickers = 'MORE_STICKERS', /** Guild has access to create private threads */ PrivateThreads = 'PRIVATE_THREADS', /** Guild is able to set role icons */ RoleIcons = 'ROLE_ICONS', + /** Guild has role subscriptions that can be purchased. */ + RoleSubscriptionsAvailableForPurchase = 'ROLE_SUBSCRIPTIONS_AVAILABLE_FOR_PURCHASE', + /** Guild has enabled role subscriptions. */ + RoleSubscriptionsEnabled = 'ROLE_SUBSCRIPTIONS_ENABLED', /** Guild has set up auto moderation rules */ AutoModeration = 'AUTO_MODERATION', /** Guild has paused invites, preventing new users from joining */