mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-20 14:00:22 +02:00
22.0.0
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { FriendlyError } = require('discord.js-commando');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const snekfetch = require('snekfetch');
|
||||
|
||||
@@ -14,9 +15,12 @@ module.exports = class StrawpollCommand extends Command {
|
||||
key: 'title',
|
||||
prompt: 'What would you like the title of the Strawpoll to be?',
|
||||
type: 'string',
|
||||
validate: title => {
|
||||
if (title.length < 200) return true;
|
||||
return 'Invalid Title. Title must be under 200 characters.';
|
||||
validate: (title) => {
|
||||
if (title.length < 200) {
|
||||
return true;
|
||||
} else {
|
||||
return 'Invalid Title. Title must be under 200 characters.';
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -24,9 +28,12 @@ module.exports = class StrawpollCommand extends Command {
|
||||
prompt: 'What options do you want me pick from? Maximum of 31.',
|
||||
type: 'string',
|
||||
infinite: true,
|
||||
validate: choice => {
|
||||
if (choice.length < 160) return true;
|
||||
return 'Invalid Choice. Choices must be under 140 characters each.';
|
||||
validate: (choice) => {
|
||||
if (choice.length < 160) {
|
||||
return true;
|
||||
} else {
|
||||
return 'Invalid Choice. Choices must be under 140 characters each.';
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -35,18 +42,17 @@ module.exports = class StrawpollCommand extends Command {
|
||||
|
||||
async run(msg, args) {
|
||||
const { title, options } = args;
|
||||
if (options.length < 2) return msg.say('You provided less than two choices.');
|
||||
if (options.length > 31) return msg.say('You provided more than thirty choices.');
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
.post('https://strawpoll.me/api/v2/polls')
|
||||
.send({ title, options });
|
||||
return msg.say(stripIndents`
|
||||
${body.title}
|
||||
http://strawpoll.me/${body.id}
|
||||
`);
|
||||
} catch (err) {
|
||||
return msg.say(`${err.name}: ${err.message}`);
|
||||
if (options.length < 2) {
|
||||
throw new FriendlyError('You provided less than two choices.');
|
||||
} else if (options.length > 31) {
|
||||
throw new FriendlyError('You provided more than thirty choices.');
|
||||
}
|
||||
const { body } = await snekfetch
|
||||
.post('https://strawpoll.me/api/v2/polls')
|
||||
.send({ title, options });
|
||||
return msg.say(stripIndents`
|
||||
${body.title}
|
||||
http://strawpoll.me/${body.id}
|
||||
`);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user