This repository has been archived by the owner on Apr 24, 2022. It is now read-only.
/
poll.js
36 lines (32 loc) · 1.53 KB
/
poll.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const { Command } = require("klasa");
const { post } = require("snekfetch");
module.exports = class extends Command {
constructor(...args) {
super(...args, {
runIn: ["text", "dm"],
cooldown: 10,
aliases: ["strawpoll", "createpoll"],
permissionLevel: 0,
requiredPermissions: ["EMBED_LINKS", "USE_EXTERNAL_EMOJIS"],
description: language => language.get("COMMAND_POLL_DESCRIPTION"),
usage: "<Question:string> <Options:string> [...]",
usageDelim: "|",
extendedHelp: "No extended help available."
});
}
async run(msg, [Question, ...Options]) {
if (Options.length < 2) return msg.sendMessage("<:penguError:435712890884849664> ***Less than two options are not allowed.***");
if (Options.length > 30) return msg.sendMessage("<:penguError:435712890884849664> ***I only allow 30 or less options.***");
try {
const { body } = await post("https://www.strawpoll.me/api/v2/polls")
.send({ title: Question, options: Options })
.catch(e => {
Error.captureStackTrace(e);
return e;
});
return msg.sendMessage(`<:penguSuccess:435712876506775553> ***Here's the poll you requested:*** https://www.strawpoll.me/${body.id}`);
} catch (e) {
return msg.sendMessage("<:penguError:435712890884849664> ***There was an error trying to create this poll, please try again.***");
}
}
};