Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Role connections & subscriptions #1487

Merged
merged 22 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
498a17f
Add `RoleConnectionMetadataType`
conorwastakenwastaken Feb 7, 2024
2a57453
Add endpoint
conorwastakenwastaken Feb 7, 2024
9ba3601
Add get/edit functions
conorwastakenwastaken Feb 7, 2024
f2ff726
Fixxxx typo
conorwastakenwastaken Feb 7, 2024
3c61bb7
tsdoc
conorwastakenwastaken Feb 7, 2024
88ee4f0
Role subscription support
conorwastakenwastaken Feb 10, 2024
abb3ba5
Optional
conorwastakenwastaken Feb 10, 2024
e52c9d5
Merge branch 'dev' into roleconnections
conorwastakenwastaken Mar 27, 2024
adedac3
Add message content
conorwastakenwastaken Apr 11, 2024
218f65e
Lint
conorwastakenwastaken Apr 11, 2024
ca7c880
Merge branch 'dev' into roleconnections
conorwastakenwastaken Apr 11, 2024
eb3763a
LocaleStrings as record key
conorwastakenwastaken Apr 20, 2024
f580224
Fix
conorwastakenwastaken Apr 20, 2024
6623354
Consistent spacing
conorwastakenwastaken Apr 20, 2024
605e34f
`data` is an array
conorwastakenwastaken Apr 20, 2024
f28dbcd
regex key validation
conorwastakenwastaken Apr 20, 2024
31c2675
Update lib/structures/Message.js
conorwastakenwastaken Apr 20, 2024
b7d4f84
Add ROLE_SUBSCRIPTIONS_AVAILABLE_FOR_PURCHASE
conorwastakenwastaken Apr 20, 2024
2917120
Alphabetise & add missing features
conorwastakenwastaken Apr 20, 2024
05700ab
Merge branch 'dev' into roleconnections
conorwastakenwastaken Apr 20, 2024
2de2bf8
Merge remote-tracking branch 'upstream/dev' into roleconnections
conorwastakenwastaken Jun 21, 2024
a0a374e
Merge branch 'dev' into roleconnections
bsian03 Jul 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions index.d.ts
conorwastakenwastaken marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ declare namespace Eris {
type TextVoiceChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "GUILD_VOICE">];

// Client
type ApplicationRoleConnectionMetadataTypes = Constants["RoleConnectionMetadataTypes"][keyof Constants["RoleConnectionMetadataTypes"]];
type MembershipStates = Constants["MembershipState"][keyof Constants["MembershipState"]];
type OAuthTeamMemberRoleTypes = Constants["OAuthTeamMemberRoleTypes"][keyof Constants["OAuthTeamMemberRoleTypes"]];

Expand Down Expand Up @@ -529,6 +530,14 @@ declare namespace Eris {
}

// Client
interface ApplicationRoleConnectionMetadata {
description: string;
description_localizations?: Record<string, string> | null;
conorwastakenwastaken marked this conversation as resolved.
Show resolved Hide resolved
key: string;
name: string;
name_localizations?: Record<string, string> | null;
conorwastakenwastaken marked this conversation as resolved.
Show resolved Hide resolved
type: ApplicationRoleConnectionMetadataTypes;
}
interface ClientOptions {
/** @deprecated */
agent?: HTTPSAgent;
Expand Down Expand Up @@ -1340,12 +1349,10 @@ declare namespace Eris {
roles?: Collection<Role>;
users?: Collection<User>;
}

interface ComponentInteractionButtonData {
component_type: Constants["ComponentTypes"]["BUTTON"];
custom_id: string;
}

interface ComponentInteractionSelectMenuData {
component_type: Constants["ComponentTypes"]["SELECT_MENU"];
custom_id: string;
Expand Down Expand Up @@ -1693,6 +1700,12 @@ declare namespace Eris {
permissions?: bigint | number | string | Permission;
unicodeEmoji?: string;
}
interface RoleSubscriptionData {
is_renewal: boolean;
role_subscription_listing_id: string;
tier_name: string;
total_months_subscribed: number;
}
interface RoleTags {
bot_id?: string;
integration_id?: string;
Expand Down Expand Up @@ -2108,7 +2121,8 @@ declare namespace Eris {
GuildIntegrationTypes: [
"twitch",
"youtube",
"discord"
"discord",
"guild_subscription"
];
GuildNSFWLevels: {
DEFAULT: 0;
Expand Down Expand Up @@ -2414,6 +2428,16 @@ declare namespace Eris {
NITRO_CLASSIC: 1;
NITRO: 2;
};
RoleConnectionMetadataTypes: {
INTEGER_LESS_THAN_OR_EQUAL: 1,
INTEGER_GREATER_THAN_OR_EQUAL: 2,
INTEGER_EQUAL: 3,
INTEGER_NOT_EQUAL: 4,
DATETIME_LESS_THAN_OR_EQUAL: 5,
DATETIME_GREATER_THAN_OR_EQUAL: 6,
BOOLEAN_EQUAL: 7,
BOOLEAN_NOT_EQUAL: 8
};
conorwastakenwastaken marked this conversation as resolved.
Show resolved Hide resolved
RoleFlags: {
IN_PROMPT: 1;
};
Expand Down Expand Up @@ -2538,6 +2562,7 @@ declare namespace Eris {
name: string;
owner: PartialUser;
privacy_policy_url?: string;
role_connections_verification_url?: string;
rpc_origins?: string[];
/** @deprecated */
summary: "";
Expand Down Expand Up @@ -2877,6 +2902,7 @@ declare namespace Eris {
/** @deprecated */
editNickname(guildID: string, nick: string, reason?: string): Promise<void>;
editRole(guildID: string, roleID: string, options: RoleOptions, reason?: string): Promise<Role>; // TODO not all options are available?
editRoleConnectionMetadataRecords(data: ApplicationRoleConnectionMetadata): Promise<ApplicationRoleConnectionMetadata[]>
conorwastakenwastaken marked this conversation as resolved.
Show resolved Hide resolved
editRolePosition(guildID: string, roleID: string, position: number): Promise<void>;
editSelf(options: { avatar?: string; username?: string }): Promise<ExtendedUser>;
editSelfConnection(
Expand Down Expand Up @@ -2985,6 +3011,7 @@ declare namespace Eris {
getRESTGuildStickers(guildID: string): Promise<Sticker[]>;
getRESTSticker(stickerID: string): Promise<Sticker>;
getRESTUser(userID: string): Promise<User>;
getRoleConnectionMetadataRecords(): Promise<ApplicationRoleConnectionMetadata[]>;
getSelf(): Promise<ExtendedUser>;
getSelfBilling(): Promise<{
payment_gateway?: string;
Expand Down Expand Up @@ -3774,6 +3801,7 @@ declare namespace Eris {
reactions: { [s: string]: { count: number; me: boolean } };
referencedMessage?: Message | null;
roleMentions: string[];
roleSubscriptionData?: RoleSubscriptionData;
stickerItems?: StickerItems[];
/** @deprecated */
stickers?: Sticker[];
Expand Down
17 changes: 17 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2172,6 +2172,15 @@ class Client extends EventEmitter {
return this.requestHandler.request("PATCH", Endpoints.GUILD_ROLE(guildID, roleID), true, options).then((role) => new Role(role, this.guilds.get(guildID)));
}

/**
* Update the role connection metadata for the application
* @arg {Array<Object>} data An array of role connection metadata objects. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object) for object structure
* @returns {Promise<Array<Object>>} An array of role connection metadata objects
*/
editRoleConnectionMetadataRecords(data) {
return this.requestHandler.request("PUT", Endpoints.ROLE_CONNECTION_METADATA_RECORDS(this.application.id), true, data);
conorwastakenwastaken marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Edit a guild role's position. Note that role position numbers are highest on top and lowest at the bottom.
* @arg {String} guildID The ID of the guild the role is in
Expand Down Expand Up @@ -3421,6 +3430,14 @@ class Client extends EventEmitter {
return this.requestHandler.request("GET", Endpoints.USER(userID), true).then((user) => new User(user, this));
}

/**
* Get the role connection metadata for the application
* @returns {Promise<Array<Object>>} An array of role connection metadata objects. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object) for object structure
*/
getRoleConnectionMetadataRecords() {
return this.requestHandler.request("GET", Endpoints.ROLE_CONNECTION_METADATA_RECORDS(this.application.id), true);
}

/**
* Get properties of the bot user
* @returns {Promise<ExtendedUser>}
Expand Down
14 changes: 13 additions & 1 deletion lib/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ module.exports.GuildIntegrationExpireBehavior = {
module.exports.GuildIntegrationTypes = [
"twitch",
"youtube",
"discord"
"discord",
"guild_subscription"
];

module.exports.GuildNSFWLevels = {
Expand Down Expand Up @@ -646,6 +647,17 @@ module.exports.PremiumTypes = {
NITRO: 2
};

module.exports.RoleConnectionMetadataTypes = {
INTEGER_LESS_THAN_OR_EQUAL: 1,
INTEGER_GREATER_THAN_OR_EQUAL: 2,
INTEGER_EQUAL: 3,
INTEGER_NOT_EQUAL: 4,
DATETIME_LESS_THAN_OR_EQUAL: 5,
DATETIME_GREATER_THAN_OR_EQUAL: 6,
BOOLEAN_EQUAL: 7,
BOOLEAN_NOT_EQUAL: 8
};

module.exports.RoleFlags = {
IN_PROMPT: 1 << 0
};
Expand Down
1 change: 1 addition & 0 deletions lib/rest/Endpoints.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions lib/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const User = require("./User");
* @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.
* @prop {Message?} referencedMessage The message that was replied to. If undefined, message data was not received. If null, the message was deleted.
* @prop {Array<String>} roleMentions Array of mentioned roles' ids
* @prop {Object?} roleSubscriptionData An object containing the data of the role subscription purchase or renewal that prompted this `ROLE_SUBSCRIPTION_PURCHASE` message. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#role-subscription-data-object) for object structure
* @prop {Array<Object>?} stickers [DEPRECATED] The stickers sent with the message
* @prop {Array<Object>?} stickerItems The stickers sent with the message
* @prop {Number} timestamp Timestamp of message creation
Expand Down Expand Up @@ -140,6 +141,10 @@ class Message extends Base {
this.member = null;
}

if(data.role_subscription_data !== undefined) {
this.roleSubscriptionData = data.role_subscription_data;
}

switch(this.type) {
case MessageTypes.DEFAULT: {
break;
Expand Down Expand Up @@ -244,6 +249,10 @@ class Message extends Base {
case MessageTypes.AUTO_MODERATION_ACTION: {
break;
}
case MessageTypes.ROLE_SUBSCRIPTION_PURCHASE: {
// I have no clue what the message content is for this, any help would be appreciated
conorwastakenwastaken marked this conversation as resolved.
Show resolved Hide resolved
break;
}
default: {
this._client.emit("warn", `Unhandled MESSAGE_CREATE type: ${JSON.stringify(data, null, 2)}`);
break;
Expand Down