Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
acerolaorionheart1 committed Sep 19, 2022
2 parents f2a3655 + 279d19d commit e8f0269
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 141 deletions.
66 changes: 33 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
}
});
})
~~~
20 changes: 10 additions & 10 deletions examples/button.js
Original file line number Diff line number Diff line change
@@ -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!'))
}
});
})
30 changes: 15 additions & 15 deletions examples/embed.js
Original file line number Diff line number Diff line change
@@ -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!'))
}
});
})
22 changes: 11 additions & 11 deletions examples/select-menu.js
Original file line number Diff line number Diff line change
@@ -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'))
}
});
})
60 changes: 36 additions & 24 deletions lib/structures/Button.js
Original file line number Diff line number Diff line change
@@ -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
}

/**
Expand All @@ -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
}

/**
Expand All @@ -30,7 +36,8 @@ module.exports = class Button {
* @returns {Button}
*/
setLabel(label) {
return this.label = label;
this.label = label
return this
}

/**
Expand All @@ -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
}

/**
Expand All @@ -58,27 +67,30 @@ 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
* @param {string|object} content Message or embed that will be send with 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: [
Expand Down Expand Up @@ -109,7 +121,7 @@ module.exports = class Button {
components: [this]
}
]
});
})
}
}
}
Loading

0 comments on commit e8f0269

Please sign in to comment.