Skip to content

Commit f36466e

Browse files
authored
feat: role subscriptions (abalabahaha#21)
* basic role subscription implementation * add role subscription data to Message object see API docs PR 5828 * align guild features with API docs * remove TODO comment roleSubscriptionData will be kept as a camelCased object
1 parent 0aa9d72 commit f36466e

File tree

4 files changed

+37
-42
lines changed

4 files changed

+37
-42
lines changed

index.d.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,12 @@ declare namespace Dysnomia {
14821482
messageID: string;
14831483
failIfNotExists?: boolean;
14841484
}
1485+
interface RoleSubscriptionData {
1486+
isRenewal: boolean;
1487+
roleSubscriptionListingID: string;
1488+
tierName: string;
1489+
totalMonthsSubscribed: number;
1490+
}
14851491
interface Sticker extends StickerItem {
14861492
/** @deprecated */
14871493
asset: "";
@@ -1593,6 +1599,8 @@ declare namespace Dysnomia {
15931599
guild_connections?: true;
15941600
integration_id?: string;
15951601
premium_subscriber?: true;
1602+
subscription_listing_id?: string;
1603+
available_for_purchase?: true;
15961604
}
15971605

15981606
// Thread
@@ -2023,39 +2031,25 @@ declare namespace Dysnomia {
20232031
GuildFeatures: [
20242032
"ANIMATED_BANNER",
20252033
"ANIMATED_ICON",
2034+
"APPLICATION_COMMAND_PERMISSIONS_V2",
20262035
"AUTO_MODERATION",
20272036
"BANNER",
2028-
"COMMERCE",
20292037
"COMMUNITY",
2030-
"CREATOR_MONETIZABLE",
2031-
"CREATOR_MONETIZABLE_DISABLED",
2038+
"CREATOR_MONETIZABLE_PROVISIONAL",
2039+
"CREATOR_STORE_PAGE",
2040+
"DEVELOPER_SUPPORT_SERVER",
20322041
"DISCOVERABLE",
2033-
"DISCOVERABLE_DISABLED",
2034-
"ENABLED_DISCOVERABLE_BEFORE",
20352042
"FEATURABLE",
2036-
"GUILD_HOME_TEST",
2037-
"HAS_DIRECTORY_ENTRY",
2038-
"HUB",
2043+
"INVITES_DISABLED",
20392044
"INVITE_SPLASH",
2040-
"LINKED_TO_HUB",
20412045
"MEMBER_VERIFICATION_GATE_ENABLED",
2042-
"MONETIZATION_ENABLED",
2043-
"MORE_EMOJI",
20442046
"MORE_STICKERS",
20452047
"NEWS",
2046-
"NEW_THREAD_PERMISSIONS",
20472048
"PARTNERED",
20482049
"PREVIEW_ENABLED",
2049-
"PREVIOUSLY_DISCOVERABLE",
2050-
"PRIVATE_THREADS",
20512050
"ROLE_ICONS",
20522051
"ROLE_SUBSCRIPTIONS_AVAILABLE_FOR_PURCHASE",
20532052
"ROLE_SUBSCRIPTIONS_ENABLED",
2054-
"SEVEN_DAY_THREAD_ARCHIVE",
2055-
"TEXT_IN_VOICE_ENABLED",
2056-
"THREADS_ENABLED",
2057-
"THREADS_ENABLED_TESTING",
2058-
"THREE_DAY_THREAD_ARCHIVE",
20592053
"TICKETED_EVENTS_ENABLED",
20602054
"VANITY_URL",
20612055
"VERIFIED",
@@ -2069,7 +2063,8 @@ declare namespace Dysnomia {
20692063
GuildIntegrationTypes: [
20702064
"twitch",
20712065
"youtube",
2072-
"discord"
2066+
"discord",
2067+
"guild_subscription"
20732068
];
20742069
GuildNSFWLevels: {
20752070
DEFAULT: 0;
@@ -3368,6 +3363,7 @@ declare namespace Dysnomia {
33683363
reactions: { [s: string]: { count: number; me: boolean } };
33693364
referencedMessage?: Message | null;
33703365
roleMentions: string[];
3366+
roleSubscriptionData?: RoleSubscriptionData;
33713367
stickerItems?: StickerItem[];
33723368
timestamp: number;
33733369
tts: boolean;

lib/Constants.js

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -247,41 +247,25 @@ module.exports.GatewayOPCodes = {
247247
module.exports.GuildFeatures = [
248248
"ANIMATED_BANNER",
249249
"ANIMATED_ICON",
250+
"APPLICATION_COMMAND_PERMISSIONS_V2",
250251
"AUTO_MODERATION",
251252
"BANNER",
252-
"COMMERCE",
253253
"COMMUNITY",
254-
"CREATOR_MONETIZABLE",
255-
"CREATOR_MONETIZABLE_DISABLED",
254+
"CREATOR_MONETIZABLE_PROVISIONAL",
255+
"CREATOR_STORE_PAGE",
256+
"DEVELOPER_SUPPORT_SERVER",
256257
"DISCOVERABLE",
257-
"DISCOVERABLE_DISABLED",
258-
"ENABLED_DISCOVERABLE_BEFORE",
259258
"FEATURABLE",
260-
"GUILD_HOME_TEST",
261-
"HAS_DIRECTORY_ENTRY",
262-
"HUB",
259+
"INVITES_DISABLED",
263260
"INVITE_SPLASH",
264-
"LINKED_TO_HUB",
265261
"MEMBER_VERIFICATION_GATE_ENABLED",
266-
"MONETIZATION_ENABLED",
267-
"MORE_EMOJI",
268-
"MORE_EMOJIS",
269262
"MORE_STICKERS",
270263
"NEWS",
271-
"NEW_THREAD_PERMISSIONS",
272264
"PARTNERED",
273265
"PREVIEW_ENABLED",
274-
"PREVIOUSLY_DISCOVERABLE",
275-
"PRIVATE_THREADS",
276266
"ROLE_ICONS",
277267
"ROLE_SUBSCRIPTIONS_AVAILABLE_FOR_PURCHASE",
278268
"ROLE_SUBSCRIPTIONS_ENABLED",
279-
"SEVEN_DAY_THREAD_ARCHIVE",
280-
"TEXT_IN_VOICE_ENABLED",
281-
"THREADS_ENABLED",
282-
"THREADS_ENABLED_TESTING",
283-
"THREE_DAY_THREAD_ARCHIVE",
284-
"THREADS_ENABLED",
285269
"TICKETED_EVENTS_ENABLED",
286270
"VANITY_URL",
287271
"VERIFIED",
@@ -296,7 +280,8 @@ module.exports.GuildIntegrationExpireBehavior = {
296280
module.exports.GuildIntegrationTypes = [
297281
"twitch",
298282
"youtube",
299-
"discord"
283+
"discord",
284+
"guild_subscription"
300285
];
301286

302287
module.exports.GuildNSFWLevels = {

lib/structures/Message.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const Collection = require("../util/Collection");
4444
* @prop {String?} prefix The prefix used in the Message, if any (CommandClient only)
4545
* @prop {Object} reactions An object containing the reactions on the message. Each key is a reaction emoji and each value is an object with properties `me` (Boolean) and `count` (Number) for that specific reaction emoji.
4646
* @prop {Message?} referencedMessage The message that was replied to. If undefined, message data was not received. If null, the message was deleted.
47+
* @prop {Object?} roleSubscriptionData Data about the role subscription that triggered this message
4748
* @prop {Array<String>} roleMentions Array of mentioned roles' ids
4849
* @prop {Array<Object>?} stickerItems The stickers sent with the message
4950
* @prop {Number} timestamp Timestamp of message creation
@@ -146,6 +147,15 @@ class Message extends Base {
146147
}
147148
}
148149

150+
if(data.role_subscription_data) {
151+
this.roleSubscriptionData = {
152+
isRenewal: data.role_subscription_data.is_renewal,
153+
roleSubscriptionListingID: data.role_subscription_data.role_subscription_listing_id,
154+
tierName: data.role_subscription_data.tier_name,
155+
totalMonthsSubscribed: data.role_subscription_data.total_months_subscribed
156+
};
157+
}
158+
149159
switch(this.type) {
150160
case MessageTypes.DEFAULT: {
151161
break;
@@ -227,6 +237,7 @@ class Message extends Base {
227237
break;
228238
}
229239
case MessageTypes.ROLE_SUBSCRIPTION_PURCHASE: {
240+
data.content = `${this.author.mention} ${this.roleSubscriptionData.isRenewal ? "renewed" : "joined"} **${this.roleSubscriptionData.tierName}** and has been a subscriber of ${this.channel.guild ? this.channel.guild.name : data.guild_id} for ${this.roleSubscriptionData.totalMonthsSubscribed} months!`;
230241
break;
231242
}
232243
case MessageTypes.INTERACTION_PREMIUM_UPSELL: {

lib/structures/Role.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class Role extends Base {
6363
if(this.tags.premium_subscriber === null) {
6464
this.tags.premium_subscriber = true;
6565
}
66+
if(this.tags.available_for_purchase === null) {
67+
this.tags.available_for_purchase = true;
68+
}
6669
}
6770
if(data.icon !== undefined) {
6871
this.icon = data.icon;

0 commit comments

Comments
 (0)