diff --git a/README.md b/README.md index c07c31e..cf29db4 100644 --- a/README.md +++ b/README.md @@ -7,58 +7,58 @@ npm i eris-addons ## Examples - Embed ~~~javascript -const ErisAddons = require('eris-addons'); -const {Client} = require('eris'); -const client = new Client('bot token'); +const ErisAddons = require('eris-addons') +const { Client } = require('eris') +const client = new Client('bot token') client.on("messageCreate", message => { if (message.content === "!embed") { - const embed = new ErisAddons.Embed(); - embed.setAuthor(message.author.username, message.author.avatarURL); - embed.setTitle('Title of embed'); - embed.setDescription('Description of embed'); - embed.addField('The field\'s name of embed', 'The field\'s description of the embed'); - embed.setColor('0x7289DA'); - embed.setThumbnail(message.author.avatarURL); - embed.setFooter(message.author.username, message.author.avatarURL); - embed.setTimestamp(); + const embed = new ErisAddons.Embed() + .setAuthor(message.author.username, message.author.avatarURL) + .setTitle('Title of embed') + .setDescription('Description of embed') + .addField('The field\'s name of embed', 'The field\'s description of the embed') + .setColor('0x7289DA') + .setThumbnail(message.author.avatarURL) + .setFooter(message.author.username, message.author.avatarURL) + .setTimestamp() - message.channel.createMessage(embed.build('Hello, world!')); + message.channel.createMessage(embed.build('Hello, world!')) } -}); +}) ~~~ - Button ~~~javascript -const ErisAddons = require('eris-addons'); -const {Client} = require('eris'); -const client = new Client('bot token'); +const ErisAddons = require('eris-addons') +const { Client } = require('eris') +const client = new Client('bot token') client.on('messageCreate', message => { if(message.content.toLowerCase() === '!button') { - const button = new ErisAddons.Button(); - button.setStyle('DANGER'); - button.setLabel('OMG, click this'); - button.setCustomID('https://discord.gg/7UeV8jFz6m'); + const button = new ErisAddons.Button() + .setStyle('DANGER') + .setLabel('OMG, click this') + .setCustomID('https://discord.gg/7UeV8jFz6m') - message.channel.createMessage(button.build('Click this!')); + message.channel.createMessage(button.build('Click this!')) } -}); +}) ~~~ - Select Menu ~~~javascript -const ErisAddons = require('eris-addons'); -const {Client} = require('eris'); -const client = new Client('bot token'); +const ErisAddons = require('eris-addons') +const {Client} = require('eris') +const client = new Client('bot token') client.on('messageCreate', message => { if(message.content.toLowerCase() === '!selectmenu') { - const menu = new ErisAddons.SelectMenu(); - menu.setPlaceholder('Select this'); - menu.addOption('Oh, click this', 'Click this for select', 'option value', '🔥'); - menu.addOption('Another option', 'Click this for select', 'option value 2', '💧'); - menu.setCustomID('select'); + const menu = new ErisAddons.SelectMenu() + .setPlaceholder('Select this') + .addOption('Oh, click this', 'Click this for select', 'option value', '🔥') + .addOption('Another option', 'Click this for select', 'option value 2', '💧') + .setCustomID('select') - message.channel.createMessage(menu.build('Click this')); + message.channel.createMessage(menu.build('Click this')) } -}); +}) ~~~ \ No newline at end of file diff --git a/examples/button.js b/examples/button.js index 62bdd8a..e1b3353 100644 --- a/examples/button.js +++ b/examples/button.js @@ -1,14 +1,14 @@ -const ErisAddons = require('../index'); -const {Client} = require('eris'); -const client = new Client('bot token'); +const ErisAddons = require('../index') +const { Client } = require('eris') +const client = new Client('bot token') client.on('messageCreate', message => { - if(message.content.toLowerCase() === '!button') { - const button = new ErisAddons.Button(); - button.setStyle('DANGER'); - button.setLabel('OMG, click this'); - button.setCustomID('https://discord.gg/7UeV8jFz6m'); + if (message.content.toLowerCase() === '!button') { + const button = new ErisAddons.Button() + .setStyle('DANGER') + .setLabel('OMG, click this') + .setCustomID('https://discord.gg/7UeV8jFz6m') - message.channel.createMessage(button.build('Click this!')); + message.channel.createMessage(button.build('Click this!')) } -}); \ No newline at end of file +}) \ No newline at end of file diff --git a/examples/embed.js b/examples/embed.js index 03d5586..200ac68 100644 --- a/examples/embed.js +++ b/examples/embed.js @@ -1,19 +1,19 @@ -const ErisAddons = require('../index'); -const {Client} = require('eris'); -const client = new Client('bot token'); +const ErisAddons = require('../index') +const { Client } = require('eris') +const client = new Client('bot token') client.on("messageCreate", message => { if (message.content === "!embed") { - const embed = new ErisAddons.Embed(); - embed.setAuthor(message.author.username, message.author.avatarURL); - embed.setTitle('Title of embed'); - embed.setDescription('Description of embed'); - embed.addField('The field\'s name of embed', 'The field\'s description of the embed'); - embed.setColor('0x7289DA'); - embed.setThumbnail(message.author.avatarURL); - embed.setFooter(message.author.username, message.author.avatarURL); - embed.setTimestamp(); - - message.channel.createMessage(embed.build('Hello, world!')); + const embed = new ErisAddons.Embed() + .setAuthor(message.author.username, message.author.avatarURL) + .setTitle('Title of embed') + .setDescription('Description of embed') + .addField('The field\'s name of embed', 'The field\'s description of the embed') + .setColor('0x7289DA') + .setThumbnail(message.author.avatarURL) + .setFooter(message.author.username, message.author.avatarURL) + .setTimestamp() + + message.channel.createMessage(embed.build('Hello, world!')) } -}); \ No newline at end of file +}) \ No newline at end of file diff --git a/examples/select-menu.js b/examples/select-menu.js index e0535b4..350a287 100644 --- a/examples/select-menu.js +++ b/examples/select-menu.js @@ -1,15 +1,15 @@ -const ErisAddons = require('../index'); -const {Client} = require('eris'); -const client = new Client('bot token'); +const ErisAddons = require('../index') +const { Client } = require('eris') +const client = new Client('bot token') client.on('messageCreate', message => { - if(message.content.toLowerCase() === '!selectmenu') { - const menu = new ErisAddons.SelectMenu(); - menu.setPlaceholder('Select this'); - menu.addOption('Oh, click this', 'Click this for select', 'option value', '🔥'); - menu.addOption('Another option', 'Click this for select', 'option value 2', '💧'); - menu.setCustomID('select'); + if (message.content.toLowerCase() === '!selectmenu') { + const menu = new ErisAddons.SelectMenu() + .setPlaceholder('Select this') + .addOption('Oh, click this', 'Click this for select', 'option value', '🔥') + .addOption('Another option', 'Click this for select', 'option value 2', '💧') + .setCustomID('select') - message.channel.createMessage(menu.build('Click this')); + message.channel.createMessage(menu.build('Click this')) } -}); \ No newline at end of file +}) \ No newline at end of file diff --git a/lib/structures/Button.js b/lib/structures/Button.js index 561ccec..65ba232 100644 --- a/lib/structures/Button.js +++ b/lib/structures/Button.js @@ -1,11 +1,11 @@ module.exports = class Button { constructor() { - this.type = 2; - this.style = null; - this.custom_id = null; - this.emoji = null; - this.url = null; - this.disabled = null; + this.type = 2 + this.style = null + this.custom_id = null + this.emoji = null + this.url = null + this.disabled = null } /** @@ -14,14 +14,20 @@ module.exports = class Button { * @returns {Button} */ setStyle(style) { - switch(style.toUpperCase()) { - case 'PRIMARY': return this.style = 1; - case 'SECONDARY': return this.style = 2; - case 'SUCCESS': return this.style = 3; - case 'DANGER': return this.style = 4; - case 'LINK': return this.style = 5; - default: throw new Error('Invalid style! Please, choose: \'PRIMARY\', \'SECONDARY\', \'SUCCESS\', \'DANGER\', \'LINK\''); + switch (style.toUpperCase()) { + case 'PRIMARY': this.style = 1 + break + case 'SECONDARY': this.style = 2 + break + case 'SUCCESS': this.style = 3 + break + case 'DANGER': this.style = 4 + break + case 'LINK': this.style = 5 + break + default: throw new Error('Invalid style! Please, choose: \'PRIMARY\', \'SECONDARY\', \'SUCCESS\', \'DANGER\', \'LINK\'') } + return this } /** @@ -30,7 +36,8 @@ module.exports = class Button { * @returns {Button} */ setLabel(label) { - return this.label = label; + this.label = label + return this } /** @@ -39,16 +46,18 @@ module.exports = class Button { * @returns {Button} */ setCustomID(customID) { - return this.custom_id = customID; + this.custom_id = customID + return this } - + /** * Puts a emoji in the button * @param {string} emoji Button emoji * @returns {Button} */ setEmoji(emoji) { - return this.emoji = emoji; + this.emoji = emoji + return this } /** @@ -58,17 +67,20 @@ module.exports = class Button { */ setURL(url) { - if(this.style !== 5) throw new Error(`The button style must be 'LINK'`); - else return this.url = url; + if (this.style !== 5) throw new Error(`The button style must be 'LINK'`) + else { + this.url = url + return this + } } /** * Disables the button - * @param {boolean} disabled * @returns {Button} */ setDisabled() { - return this.disabled = true; + this.disabled = true + return this } /** * Build the button @@ -76,9 +88,9 @@ module.exports = class Button { * @param {object} file File that will be send with button */ build(content = '', file) { - switch(typeof content) { + switch (typeof content) { case 'string': - if(file?.file && file?.name) { + if (file?.file && file?.name) { return { content, components: [ @@ -109,7 +121,7 @@ module.exports = class Button { components: [this] } ] - }); + }) } } } \ No newline at end of file diff --git a/lib/structures/Embed.js b/lib/structures/Embed.js index 3743342..f0bd324 100644 --- a/lib/structures/Embed.js +++ b/lib/structures/Embed.js @@ -1,17 +1,17 @@ -const ColorResolver = require('../util/ColorResolver.js'); +const ColorResolver = require('../util/ColorResolver.js') module.exports = class Embed { constructor() { - this.author = null; - this.title = null; - this.url = null; - this.description = null; - this.fields = []; - this.image = null; - this.thumbnail = null; - this.timestamp = null; - this.footer = null; - this.color = null; + this.author = null + this.title = null + this.url = null + this.description = null + this.fields = [] + this.image = null + this.thumbnail = null + this.timestamp = null + this.footer = null + this.color = null } /** * Adds a author to your embed @@ -21,7 +21,8 @@ module.exports = class Embed { * @returns {Embed} */ setAuthor(name, icon_url, url) { - return this.author = {name, icon_url, url} + this.author = { name, icon_url, url } + return this } /** * Adds a title to your embed @@ -29,7 +30,8 @@ module.exports = class Embed { * @returns {Embed} */ setTitle(title) { - return this.title = title; + this.title = title + return this } /** * Adds a description to your embed @@ -37,7 +39,8 @@ module.exports = class Embed { * @returns {Embed} */ setDescription(description) { - return this.description = description.toString().substring(0, 2048); + this.description = description.toString().substring(0, 2048) + return this } /** * Adds a color to your embed @@ -45,7 +48,8 @@ module.exports = class Embed { * @returns {Embed} */ setColor(color) { - return this.color = ColorResolver.resolve(color); + this.color = ColorResolver.resolve(color) + return this } /** * Adds a field to your embed @@ -55,11 +59,12 @@ module.exports = class Embed { * @returns {Embed} */ addField(name, value, inline = false) { - return this.fields.push({ + this.fields.push({ name: name.toString().substring(0, 256), value: value.toString().substring(0, 1024), - inline: inline - }); + inline + }) + return this } /** * Adds a thumbnail to your embed @@ -67,14 +72,16 @@ module.exports = class Embed { * @returns {Embed} */ setThumbnail(url) { - return this.thumbnail = {url} + this.thumbnail = { url } + return this } /** * Adds a imagem to your embed * @param {string} url Image URL */ setImage(url) { - return this.image = {url}; + this.image = { url } + return this } /** * Adds a URL to your embed @@ -82,7 +89,8 @@ module.exports = class Embed { * @returns {Embed} */ setURL(url) { - return this.url = url; + this.url = url + return this } /** * Adds a timestamp to your embed @@ -90,7 +98,8 @@ module.exports = class Embed { * @returns {Embed} */ setTimestamp(timestamp = new Date()) { - return this.timestamp = timestamp; + this.timestamp = timestamp + return this } /** * Adds a footer to your embed @@ -99,10 +108,11 @@ module.exports = class Embed { * @returns {Embed} */ setFooter(text, iconURL) { - return this.footer = { + this.footer = { text: text.toString().substring(0, 2048), icon_url: iconURL } + return this } /** * Removes elements from an array @@ -110,7 +120,8 @@ module.exports = class Embed { * @param {number} deleteCount The number of elements to remove */ spliceFields(start, deleteCount) { - return this.fields.splice(start, deleteCount); + this.fields.splice(start, deleteCount) + return this } /** * Replaces a field for another field @@ -120,8 +131,8 @@ module.exports = class Embed { * @param {boolean} inline */ replaceField(pos, name, value, inline = false) { - this.fields[pos] = {name, value, inline} - return this; + this.fields[pos] = { name, value, inline } + return this } /** * Build embed @@ -129,6 +140,6 @@ module.exports = class Embed { * @returns {Embed} */ build(content = '') { - return {content, embeds: [this]} + return { content, embeds: [this] } } } \ No newline at end of file diff --git a/lib/structures/SelectMenu.js b/lib/structures/SelectMenu.js index a917638..51f0487 100644 --- a/lib/structures/SelectMenu.js +++ b/lib/structures/SelectMenu.js @@ -1,12 +1,12 @@ module.exports = class SelectMenu { constructor() { - this.type = 3; - this.customID = null; - this.placeholder = null; - this.options = []; - this.min_values = null; - this.max_values = null; - this.disabled = null; + this.type = 3 + this.customID = null + this.placeholder = null + this.options = [] + this.min_values = null + this.max_values = null + this.disabled = null } /** @@ -15,7 +15,8 @@ module.exports = class SelectMenu { * @returns {SelectMenu} */ setPlaceholder(placeholder) { - return this.placeholder = placeholder; + this.placeholder = placeholder + return this } /** @@ -27,17 +28,19 @@ module.exports = class SelectMenu { * @returns {SelectMenu} */ addOption(label, description, value, emoji) { - if(isNaN(emoji)) return this.options.push({label, description, value, emoji: {name: emoji}}); - else return this.options.push({label, description, value, emoji: {id: emoji}}); + if (isNaN(emoji)) this.options.push({ label, description, value, emoji: { name: emoji } }) + else this.options.push({ label, description, value, emoji: { id: emoji } }) + return this } - + /** * Sets the minimum values that will be selected * @param {number} number Minimum amount of selections the user can make * @returns {SelectMenu} */ setMinValues(number = 1) { - return this.min_values = number + this.min_values = number + return this } /** @@ -46,14 +49,16 @@ module.exports = class SelectMenu { * @returns {SelectMenu} */ setMaxValues(number = 1) { - return this.max_values = number; + this.max_values = number + return this } /** * Disables the menu * @returns {SelectMenu} */ setDisabled() { - return this.disabled = true; + this.disabled = true + return this } /** @@ -62,7 +67,8 @@ module.exports = class SelectMenu { * @returns {SelectMenu} */ setCustomID(customID) { - return this.custom_id = customID; + this.custom_id = customID + return this } /** @@ -71,9 +77,9 @@ module.exports = class SelectMenu { * @param {object} file File that will be send with menu */ build(content = '', file) { - switch(typeof content) { + switch (typeof content) { case 'string': - if(file?.file && file?.name) { + if (file?.file && file?.name) { return { content, components: [ @@ -104,7 +110,7 @@ module.exports = class SelectMenu { components: [this] } ] - }); + }) } } } \ No newline at end of file diff --git a/lib/util/ColorResolver.js b/lib/util/ColorResolver.js index 7192e64..bed22f7 100644 --- a/lib/util/ColorResolver.js +++ b/lib/util/ColorResolver.js @@ -5,7 +5,7 @@ module.exports = class ColorResolver { * @returns */ static resolve(color) { - if(typeof color !== 'string') throw new Error('The color type must be a string'); - return parseInt(color.toUpperCase().replace('#', ''), 16); + if(typeof color !== 'string') throw new Error('The color type must be a string') + return parseInt(color.toUpperCase().replace('#', ''), 16) } } \ No newline at end of file diff --git a/package.json b/package.json index 16d7759..cd02035 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eris-addons", - "version": "1.0.31", + "version": "1.1.0", "description": "A powerful addon to the eris library.", "main": "index.js", "scripts": {