From 2cf6b30a780ce5e70013bbb5e6ae73ab8de1819d Mon Sep 17 00:00:00 2001 From: loicbersier Date: Fri, 28 Jun 2019 19:19:08 +0200 Subject: [PATCH] strawpoll creation command --- commands/utility/strawpoll.js | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 commands/utility/strawpoll.js diff --git a/commands/utility/strawpoll.js b/commands/utility/strawpoll.js new file mode 100644 index 00000000..a088a01d --- /dev/null +++ b/commands/utility/strawpoll.js @@ -0,0 +1,63 @@ +const { Command } = require('discord-akairo'); +const fetch = require('node-fetch'); + +class SayCommand extends Command { + constructor() { + super('strawpoll', { + aliases: ['strawpoll', 'poll'], + category: 'general', + args: [ + { + id: 'title', + type: 'string', + prompt: { + start: 'What should the title of the poll be?', + }, + }, + { + id: 'options', + type: 'string', + prompt: { + start: 'What the options should be?', + }, + match: 'rest' + }, + { + id: 'multi', + match: 'flag', + flag: '--multi' + } + ], + description: { + content: 'Simply create strawpoll ( use | to separate the options )', + usage: '[title] [options]', + examples: ['"am i cool?" hell yea | nah | you suck!'] + } + }); + } + + async exec(message, args) { + let options = args.options.trim().split('|'); + + + let request = { + 'title': args.title, + 'options': options, + 'multi': args.multi + }; + + console.log(JSON.stringify(request)); + + fetch('https://www.strawpoll.me/api/v2/polls', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(request), + }).then((response) => { + return response.json(); + }).then((response) => { + return message.channel.send(` Your strawpoll is ready! https://www.strawpoll.me/${response.id}`); + }); + } +} + +module.exports = SayCommand; \ No newline at end of file