Skip to content

Commit

Permalink
v1.2.12
Browse files Browse the repository at this point in the history
+ default values for select menus
  • Loading branch information
fb-sean committed Sep 22, 2023
1 parent 4467513 commit 9d38cad
Show file tree
Hide file tree
Showing 73 changed files with 246 additions and 162 deletions.
2 changes: 1 addition & 1 deletion docs/1.2.11/ActionRow.html → docs/1.2.12/ActionRow.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/1.2.11/Button.html → docs/1.2.12/Button.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/1.2.11/Embed.html → docs/1.2.12/Embed.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/1.2.11/Guild.html → docs/1.2.12/Guild.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/1.2.11/Member.html → docs/1.2.12/Member.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/1.2.11/Message.html → docs/1.2.12/Message.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/1.2.11/Modal.html → docs/1.2.12/Modal.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/1.2.11/Rest.html → docs/1.2.12/Rest.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/1.2.11/TextInput.html → docs/1.2.12/TextInput.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/1.2.11/User.html → docs/1.2.12/User.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/1.2.11/Utils.html → docs/1.2.12/Utils.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/1.2.11/api_api.js.html → docs/1.2.12/api_api.js.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/1.2.11/global.html → docs/1.2.12/global.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/1.2.11/index.html → docs/1.2.12/index.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<body>
Hi
<script>
setTimeout(function () {
window.location.href = 'https://interactionsjs.com/1.2.12';
}, 1000);
</script>
</body>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "interactions.js",
"version": "1.2.11",
"version": "1.2.12",
"description": "A powerful Javascript library to work with discords interactions",
"main": "./src/index.js",
"typings": "./typings/index.d.ts",
Expand Down
125 changes: 80 additions & 45 deletions src/structures/SelectMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ class SelectMenu {
* @type {boolean}
* @private
*/
disabled: false
disabled: false,

/**
* The default values of the select menu
* @type {array}
* @private
*/
default_values: []
};
}

Expand All @@ -98,7 +105,7 @@ class SelectMenu {
throw new Error("[Interactions.js => <SelectMenu>.setType] Type must be a number");
}

if(!Object.values(SelectMenuTypes).includes(type)) {
if (!Object.values(SelectMenuTypes).includes(type)) {
throw new Error("[Interactions.js => <SelectMenu>.setType] Type must be a valid type");
}

Expand All @@ -116,7 +123,7 @@ class SelectMenu {
throw new Error("[Interactions.js => <SelectMenu>.setCustomId] Custom id must be a string");
}

if(customId.length > 100) {
if (customId.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.setCustomId] Custom id must be less than 100 characters");
}

Expand All @@ -130,42 +137,42 @@ class SelectMenu {
* @return {SelectMenu}
*/
addOptions(options) {
if(!options) {
if (!options) {
throw new Error("[Interactions.js => <SelectMenu>.addOptions] Options are required");
}

if(!Array.isArray(options)) {
if (!Array.isArray(options)) {
throw new Error("[Interactions.js => <SelectMenu>.addOptions] Options must be an array");
}

if(options.length > 25) {
if (options.length > 25) {
throw new Error("[Interactions.js => <SelectMenu>.addOptions] Options must be less than 25");
}

for(let option of options) {
if(option?.data) option = option.toJSON();
for (let option of options) {
if (option?.data) option = option.toJSON();

if(option?.label?.length > 100) {
if (option?.label?.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.addOptions] Option label must be less than 100 characters");
}

if(option?.description && option?.description?.length > 100) {
if (option?.description && option?.description?.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.addOptions] Option description must be less than 100 characters");
}

if(option?.value?.length > 100) {
if (option?.value?.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.addOptions] Option value must be less than 100 characters");
}

if(option?.emoji?.name && option?.emoji?.name?.length > 100) {
if (option?.emoji?.name && option?.emoji?.name?.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.addOptions] Option emoji name must be less than 100 characters");
}

if(option?.emoji && option?.emoji.id && option?.emoji?.id?.length > 100) {
if (option?.emoji && option?.emoji.id && option?.emoji?.id?.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.addOptions] Option emoji id must be less than 100 characters");
}

if(!option?.emoji?.id && !option?.emoji?.name) {
if (!option?.emoji?.id && !option?.emoji?.name) {
throw new Error("[Interactions.js => <SelectMenu>.addOptions] Option emoji must have an id or name");
}
}
Expand All @@ -180,33 +187,33 @@ class SelectMenu {
* @return {SelectMenu}
*/
addOption(option) {
if(typeof option !== "object") {
if (typeof option !== "object") {
throw new Error("[Interactions.js => <SelectMenu>.addOption] Option must be an object");
}

if(option?.data) option = option.toJSON();
if (option?.data) option = option.toJSON();

if(option.label.length > 100) {
if (option.label.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.addOption] Option label must be less than 100 characters");
}

if(option.description && option.description.length > 100) {
if (option.description && option.description.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.addOption] Option description must be less than 100 characters");
}

if(option.value.length > 100) {
if (option.value.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.addOption] Option value must be less than 100 characters");
}

if(option.emoji?.name && option.emoji.name.length > 100) {
if (option.emoji?.name && option.emoji.name.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.addOption] Option emoji name must be less than 100 characters");
}

if(option.emoji && option.emoji.id && option.emoji.id.length > 100) {
if (option.emoji && option.emoji.id && option.emoji.id.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.addOption] Option emoji id must be less than 100 characters");
}

if(!option?.emoji?.id && !option?.emoji?.name) {
if (!option?.emoji?.id && !option?.emoji?.name) {
throw new Error("[Interactions.js => <SelectMenu>.addOption] Option emoji must have an id or name");
}

Expand All @@ -220,42 +227,42 @@ class SelectMenu {
* @return {SelectMenu}
*/
setOptions(options) {
if(!options) {
if (!options) {
throw new Error("[Interactions.js => <SelectMenu>.setOptions] Options are required");
}

if(!Array.isArray(options)) {
if (!Array.isArray(options)) {
throw new Error("[Interactions.js => <SelectMenu>.setOptions] Options must be an array");
}

if(options.length > 25) {
if (options.length > 25) {
throw new Error("[Interactions.js => <SelectMenu>.setOptions] Options must be less than 25");
}

for(let option of options) {
if(option?.data) option = option.toJSON();
for (let option of options) {
if (option?.data) option = option.toJSON();

if(option?.label?.length > 100) {
if (option?.label?.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.setOptions] Option label must be less than 100 characters");
}

if(option?.description && option?.description?.length > 100) {
if (option?.description && option?.description?.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.setOptions] Option description must be less than 100 characters");
}

if(option?.value?.length > 100) {
if (option?.value?.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.setOptions] Option value must be less than 100 characters");
}

if(option?.emoji && option?.emoji?.name && option?.emoji?.name?.length > 100) {
if (option?.emoji && option?.emoji?.name && option?.emoji?.name?.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.setOptions] Option emoji name must be less than 100 characters");
}

if(option?.emoji && option?.emoji.id && option?.emoji?.id?.length > 100) {
if (option?.emoji && option?.emoji.id && option?.emoji?.id?.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.setOptions] Option emoji id must be less than 100 characters");
}

if(option?.emoji && !option?.emoji?.id && !option?.emoji?.name) {
if (option?.emoji && !option?.emoji?.id && !option?.emoji?.name) {
throw new Error("[Interactions.js => <SelectMenu>.setOptions] Option emoji must have an id or name");
}
}
Expand All @@ -270,7 +277,7 @@ class SelectMenu {
* @return {SelectMenu}
*/
setChannelTypes(channelTypes) {
if(!Array.isArray(channelTypes)) {
if (!Array.isArray(channelTypes)) {
throw new Error("[Interactions.js => <SelectMenu>.setChannelTypes] Channel types must be an array");
}

Expand All @@ -284,11 +291,11 @@ class SelectMenu {
* @return {SelectMenu}
*/
setPlaceholder(placeholder) {
if(typeof placeholder !== "string") {
if (typeof placeholder !== "string") {
throw new Error("[Interactions.js => <SelectMenu>.setPlaceholder] Placeholder must be a string");
}

if(placeholder.length > 100) {
if (placeholder.length > 100) {
throw new Error("[Interactions.js => <SelectMenu>.setPlaceholder] Placeholder must be less than 100 characters");
}

Expand All @@ -302,15 +309,15 @@ class SelectMenu {
* @return {SelectMenu}
*/
setMinValues(minValues) {
if(typeof minValues !== "number") {
if (typeof minValues !== "number") {
throw new Error("[Interactions.js => <SelectMenu>.setMinValues] Min values must be a number");
}

if(minValues < 1) {
if (minValues < 1) {
throw new Error("[Interactions.js => <SelectMenu>.setMinValues] Min values must be greater than 0");
}

if(minValues > 25) {
if (minValues > 25) {
throw new Error("[Interactions.js => <SelectMenu>.setMinValues] Min values must be less than 25");
}

Expand All @@ -324,15 +331,15 @@ class SelectMenu {
* @return {SelectMenu}
*/
setMaxValues(maxValues) {
if(typeof maxValues !== "number") {
if (typeof maxValues !== "number") {
throw new Error("[Interactions.js => <SelectMenu>.setMaxValues] Max values must be a number");
}

if(maxValues < 1) {
if (maxValues < 1) {
throw new Error("[Interactions.js => <SelectMenu>.setMaxValues] Max values must be greater than 0");
}

if(maxValues > 25) {
if (maxValues > 25) {
throw new Error("[Interactions.js => <SelectMenu>.setMaxValues] Max values must be less than 25");
}

Expand All @@ -346,23 +353,51 @@ class SelectMenu {
* @return {SelectMenu}
*/
setDisabled(disabled) {
if(typeof disabled !== "boolean") {
if (typeof disabled !== "boolean") {
throw new Error("[Interactions.js => <SelectMenu>.setDisabled] Disabled must be a boolean");
}

this.data.disabled = disabled;
return this;
}

/**
* set the default values of the select menu
* @param {array} defaultValues
* @returns {SelectMenu}
*/
setDefaultValues(defaultValues) {
if (!Array.isArray(defaultValues)) {
throw new Error("[Interactions.js => <SelectMenu>.setDefaultValues] Default values must be an array");
}

if (defaultValues.length > 25) {
throw new Error("[Interactions.js => <SelectMenu>.setDefaultValues] Default values must be less than 25");
}

for (let value of defaultValues) {
if (!value.id) {
throw new Error("[Interactions.js => <SelectMenu>.setDefaultValues] Default values must have an id");
}

if (!value.type) {
throw new Error("[Interactions.js => <SelectMenu>.setDefaultValues] Default values must have a type [role, user, channel]");
}
}

this.data.default_values = defaultValues;
return this;
}

/**
* return the select menu as json
* @return {Object} The select menu as json
* @private
*/
toJSON() {
const data = { ...this.data };
const data = {...this.data};

if(data.type === 3 && data.options <= 0) {
if (data.type === 3 && data.options <= 0) {
throw new Error("[Interactions.js => <SelectMenu>.toJSON] Select menu must have at least one option");
}

Expand Down
6 changes: 6 additions & 0 deletions typings/structures/SelectMenu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ declare class SelectMenu {
* @return {SelectMenu}
*/
setDisabled(disabled: boolean): SelectMenu;
/**
* set the default values of the select menu
* @param {array} defaultValues
* @returns {SelectMenu}
*/
setDefaultValues(defaultValues: any[]): SelectMenu;
/**
* return the select menu as json
* @return {Object} The select menu as json
Expand Down
2 changes: 1 addition & 1 deletion typings/structures/SelectMenu.d.ts.map

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

0 comments on commit 9d38cad

Please sign in to comment.