Better Validators and More Destucturing

This commit is contained in:
Daniel Odendahl Jr
2017-04-19 18:55:26 +00:00
parent c064401b37
commit d77f71b66a
40 changed files with 114 additions and 124 deletions
+13 -8
View File
@@ -18,16 +18,22 @@ module.exports = class StrawpollCommand extends Command {
prompt: 'What would you like the title of the Strawpoll to be?',
type: 'string',
validate: title => {
if (title.length > 200) {
return 'Please limit your title to 200 characters.';
if (title.length < 200) {
return true;
}
return true;
return `Please keep your title under 200 characters, you have ${title.length}.`;
}
}, {
key: 'choices',
prompt: 'What choices do you want me pick from?',
prompt: 'What choices do you want me pick from? Maximum of 31.',
type: 'string',
infinite: true
infinite: true,
validate: choice => {
if (choice.length < 160) {
return true;
}
return `Please keep your choices under 160 characters each, you have ${choice.length}.`;
}
}]
});
}
@@ -40,14 +46,13 @@ module.exports = class StrawpollCommand extends Command {
if (choices.length < 2) return message.say(':x: Error! You provided less than two choices!');
if (choices.length > 31) return message.say(':x: Error! You provided more than thirty choices!');
try {
const response = await request
const { body } = await request
.post('https://strawpoll.me/api/v2/polls')
.send({
title: title,
options: choices
});
const data = response.body;
return message.say(`${data.title}\nhttp://strawpoll.me/${data.id}`);
return message.say(`${body.title}\nhttp://strawpoll.me/${body.id}`);
}
catch (err) {
return message.say(':x: Error! Something went wrong!');
+5 -5
View File
@@ -22,16 +22,16 @@ module.exports = class TodayCommand extends Command {
if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!');
}
try {
const response = await request
const { text } = await request
.get('http://history.muffinlabs.com/date')
.buffer(true);
const parsedResponse = JSON.parse(response.text);
const events = parsedResponse.data.Events;
const data = JSON.parse(text);
const events = data.data.Events;
const randomNumber = Math.floor(Math.random() * events.length);
const embed = new RichEmbed()
.setColor(0x9797FF)
.setURL(parsedResponse.url)
.setTitle(`On this day (${parsedResponse.date})...`)
.setURL(data.url)
.setTitle(`On this day (${data.date})...`)
.setTimestamp()
.setDescription(`${events[randomNumber].text} (${events[randomNumber].year})`);
return message.embed(embed);
+4 -5
View File
@@ -23,14 +23,13 @@ module.exports = class WouldYouRatherCommand extends Command {
if (!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return message.say(':x: Error! I don\'t have the Embed Links Permission!');
}
try {
const response = await request
const { body } = await request
.get('http://www.rrrather.com/botapi');
const data = response.body;
const embed = new RichEmbed()
.setTitle(`${data.title}...`)
.setURL(data.link)
.setTitle(`${body.title}...`)
.setURL(body.link)
.setColor(0x9797FF)
.setDescription(`${data.choicea} OR ${data.choiceb}?`);
.setDescription(`${body.choicea} OR ${body.choiceb}?`);
return message.embed(embed);
} catch (err) {
return message.say(':x: Error! Something went wrong!');