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

Expose components #1189

Merged
merged 17 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
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
42 changes: 41 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ declare namespace Eris {
// Message
type AdvancedMessageContent = {
allowedMentions?: AllowedMentions;
components?: ActionRow[];
content?: string;
embed?: EmbedOptions;
flags?: number;
Expand All @@ -61,6 +62,9 @@ declare namespace Eris {
messageReferenceID?: string;
tts?: boolean;
};
type ActionRowComponents = Button | SelectMenu;
type Button = InteractionButton | URLButton;
type Component = ActionRow | ActionRowComponents;
type ImageFormat = "jpg" | "jpeg" | "png" | "gif" | "webp";
type MessageContent = string | AdvancedMessageContent;
type MFALevel = 0 | 1;
Expand All @@ -80,7 +84,7 @@ declare namespace Eris {
type ConverterCommand = "./ffmpeg" | "./avconv" | "ffmpeg" | "avconv";

// Webhook
type MessageWebhookContent = Pick<WebhookPayload, "content" | "embeds" | "file" | "allowedMentions">;
type MessageWebhookContent = Pick<WebhookPayload, "content" | "embeds" | "file" | "allowedMentions" | "components">;

// INTERFACES
// Internals
Expand Down Expand Up @@ -814,6 +818,10 @@ declare namespace Eris {
}

// Message
interface ActionRow {
components: ActionRowComponents[];
type: 1;
}
interface ActiveMessages {
args: string[];
command: Command;
Expand All @@ -835,12 +843,38 @@ declare namespace Eris {
url: string;
width?: number;
}
interface ButtonBase {
disabled?: boolean;
emoji?: Partial<PartialEmoji>;
label?: string;
type: 2;
}
interface SelectMenu {
custom_id: string;
disabled?: boolean;
max_values?: number;
min_values?: number;
options: SelectMenuOptions[];
placeholder?: string;
type: 3;
}
interface SelectMenuOptions {
default?: boolean;
description?: string;
emoji?: Partial<PartialEmoji>;
label: string;
value: string;
}
interface GetMessageReactionOptions {
after?: string;
/** @deprecated */
before?: string;
limit?: number;
}
interface InteractionButton extends ButtonBase {
custom_id: string;
style: 1 | 2 | 3 | 4;
}
interface MessageActivity {
party_id?: string;
type: Constants["MessageActivityTypes"][keyof Constants["MessageActivityTypes"]];
Expand Down Expand Up @@ -891,6 +925,10 @@ declare namespace Eris {
name: string;
format_type: Constants["StickerFormats"][keyof Constants["StickerFormats"]];
}
interface URLButton extends ButtonBase {
style: 5;
url: string;
}

// Presence
interface Activity extends ActivityPartial<ActivityType> {
Expand Down Expand Up @@ -1018,6 +1056,7 @@ declare namespace Eris {
allowedMentions?: AllowedMentions;
auth?: boolean;
avatarURL?: string;
components?: ActionRow[];
content?: string;
embeds?: EmbedOptions[];
file?: MessageFile | MessageFile[];
Expand Down Expand Up @@ -2242,6 +2281,7 @@ declare namespace Eris {
/** @deprecated */
cleanContent: string;
command?: Command;
components?: ActionRow[];
content: string;
createdAt: number;
editedTimestamp?: number;
Expand Down
71 changes: 70 additions & 1 deletion lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,23 @@ class Client extends EventEmitter {
* @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow.
* @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow.
* @arg {Boolean} [content.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to.
* @arg {Array<Object>} [content.components] An array of component objects
* @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 0-4 and type 3 only)
* @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3 only)
* @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
* @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
* @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
* @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
* @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
* @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
* @arg {String} [content.components[].options[].description] The description for this option
* @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
* @arg {String} content.components[].options[].label The label for this option
* @arg {Number | String} content.components[].options[].value The value for this option
* @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3 only)
* @arg {Number} [content.components[].style] The style of the component (type 2 only) - If 0-4, `custom_id` is required; if 5, `url` is required
* @arg {Number} content.components[].type The type of component - If 1, it is a collection and a `components` array (nested) is required; if 2, it is a button; if 3, it is a select menu
* @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
* @arg {String} content.content A content string
* @arg {Object} [content.embed] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
* @arg {Object} [content.messageReference] The message reference, used when replying to messages
Expand Down Expand Up @@ -1221,6 +1238,23 @@ class Client extends EventEmitter {
* @arg {Boolean} [content.allowedMentions.everyone] Whether or not to allow @everyone/@here.
* @arg {Boolean | Array<String>} [content.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow.
* @arg {Boolean | Array<String>} [content.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow.
* @arg {Array<Object>} [content.components] An array of component objects
* @arg {String} [content.components[].custom_id] The ID of the component (type 2 style 0-4 and type 3 only)
* @arg {Boolean} [content.components[].disabled] Whether the component is disabled (type 2 and 3 only)
* @arg {Object} [content.components[].emoji] The emoji to be displayed in the component (type 2)
* @arg {String} [content.components[].label] The label to be displayed in the component (type 2)
* @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
* @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
* @arg {Array<Object>} [content.components[].options] The options for this component (type 3 only)
* @arg {Boolean} [content.components[].options[].default] Whether this option should be the default value selected
* @arg {String} [content.components[].options[].description] The description for this option
* @arg {Object} [content.components[].options[].emoji] The emoji to be displayed in this option
* @arg {String} content.components[].options[].label The label for this option
* @arg {Number | String} content.components[].options[].value The value for this option
* @arg {String} [content.components[].placeholder] The placeholder text for the component when no option is selected (type 3 only)
* @arg {Number} [content.components[].style] The style of the component (type 2 only) - If 0-4, `custom_id` is required; if 5, `url` is required
* @arg {Number} content.components[].type The type of component - If 1, it is a collection and a `components` array (nested) is required; if 2, it is a button; if 3, it is a select menu
* @arg {String} [content.components[].url] The URL that the component should open for users (type 2 style 5 only)
* @arg {String} content.content A content string
* @arg {Object} [content.embed] An embed object. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#embed-object) for object structure
* @arg {Number} [content.flags] A number representing the flags to apply to the message. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/channel#message-object-message-flags) for flags reference
Expand Down Expand Up @@ -1465,6 +1499,23 @@ class Client extends EventEmitter {
* @arg {Boolean | Array<String>} [options.allowedMentions.roles] Whether or not to allow all role mentions, or an array of specific role mentions to allow.
* @arg {Boolean | Array<String>} [options.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow.
* @arg {Boolean} [options.allowedMentions.repliedUser] Whether or not to mention the author of the message being replied to.
* @arg {Array<Object>} [options.components] An array of component objects
* @arg {String} [options.components[].custom_id] The ID of the component (type 2 style 0-4 and type 3 only)
* @arg {Boolean} [options.components[].disabled] Whether the component is disabled (type 2 only)
* @arg {Object} [options.components[].emoji] The emoji to be displayed in the component (type 2)
* @arg {String} [options.components[].label] The label to be displayed in the component (type 2)
* @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
* @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
* @arg {Array<Object>} [options.components[].options] The options for this component (type 3 only)
* @arg {Boolean} [options.components[].options[].default] Whether this option should be the default value selected
* @arg {String} [options.components[].options[].description] The description for this option
* @arg {Object} [options.components[].options[].emoji] The emoji to be displayed in this option
* @arg {String} options.components[].options[].label The label for this option
* @arg {Number | String} options.components[].options[].value The value for this option
* @arg {String} [options.components[].placeholder] The placeholder text for the component when no option is selected (type 3 only)
* @arg {Number} [options.components[].style] The style of the component (type 2 only) - If 0-4, `custom_id` is required; if 5, `url` is required
* @arg {Number} options.components[].type The type of component - If 1, it is a collection and a `components` array (nested) is required; if 2, it is a button; if 3, it is a select menu
* @arg {String} [options.components[].url] The URL that the component should open for users (type 2 style 5 only)
* @arg {String} [options.content=""] A content string
* @arg {Array<Object>} [options.embeds] An array of Discord embeds
* @arg {Object | Array<Object>} [options.file] A file object (or an Array of them)
Expand Down Expand Up @@ -1527,6 +1578,23 @@ class Client extends EventEmitter {
* @arg {Boolean | Array<String>} [options.allowedMentions.users] Whether or not to allow all user mentions, or an array of specific user mentions to allow.
* @arg {Boolean} [options.auth=false] Whether or not to authenticate with the bot token.
* @arg {String} [options.avatarURL] A URL for a custom avatar, defaults to webhook default avatar if not specified
* @arg {Array<Object>} [options.components] An array of component objects
* @arg {String} [options.components[].custom_id] The ID of the component (type 2 style 0-4 and type 3 only)
* @arg {Boolean} [options.components[].disabled] Whether the component is disabled (type 2 only)
* @arg {Object} [options.components[].emoji] The emoji to be displayed in the component (type 2)
* @arg {String} [options.components[].label] The label to be displayed in the component (type 2)
* @arg {Number} [content.components[].max_values] The maximum number of items that can be chosen (1-25, default 1)
* @arg {Number} [content.components[].min_values] The minimum number of items that must be chosen (0-25, default 1)
* @arg {Array<Object>} [options.components[].options] The options for this component (type 3 only)
* @arg {Boolean} [options.components[].options[].default] Whether this option should be the default value selected
* @arg {String} [options.components[].options[].description] The description for this option
* @arg {Object} [options.components[].options[].emoji] The emoji to be displayed in this option
* @arg {String} options.components[].options[].label The label for this option
* @arg {Number | String} options.components[].options[].value The value for this option
* @arg {String} [options.components[].placeholder] The placeholder text for the component when no option is selected (type 3 only)
* @arg {Number} [options.components[].style] The style of the component (type 2 only) - If 0-4, `custom_id` is required; if 5, `url` is required
* @arg {Number} options.components[].type The type of component - If 1, it is a collection and a `components` array (nested) is required; if 2, it is a button; if 3, it is a select menu
* @arg {String} [options.components[].url] The URL that the component should open for users (type 2 style 5 only)
* @arg {String} [options.content=""] A content string
* @arg {Array<Object>} [options.embeds] An array of Discord embeds
* @arg {Object | Array<Object>} [options.file] A file object (or an Array of them)
Expand All @@ -1547,7 +1615,8 @@ class Client extends EventEmitter {
username: options.username,
avatar_url: options.avatarURL,
tts: options.tts,
allowed_mentions: this._formatAllowedMentions(options.allowedMentions)
allowed_mentions: this._formatAllowedMentions(options.allowedMentions),
components: options.components
}, options.file).then((response) => options.wait ? new Message(response, this) : undefined);
}

Expand Down
Loading