diff --git a/commandmanager.js b/commandmanager.js index 8676d54..885c85c 100644 --- a/commandmanager.js +++ b/commandmanager.js @@ -5,6 +5,7 @@ const Logger = require('./logger'); const Config = require('./config'); const Commands = require('./commands/commands') const MultiServerCommands = require('./commands/multiservercommands') +const SpaceCommands = require('./commands/spacecommands') const AdminCommands = require('./commands/admincommands') const CommandManager = require('./main'); @@ -48,6 +49,9 @@ module.exports.loadCommands = function() { addCommand('Poll', 'poll', undefined, 'poll start [option1/option2...] or poll stop', 'Starts/stops an automated poll with the options given as a third argument to \'poll start\' and are seperated with a \'/\' with no spaces, stopping a poll will produce the results', false, MultiServerCommands.poll); addCommand('Vote', 'vote', undefined, 'vote [option]', 'Places your vote on the option you chose, based on the running poll in the server the \'poll start\' command was issued in', false, MultiServerCommands.vote); + //space commands + addCommand('Next Launch', 'nextlaunch', undefined, 'nextlaunch', 'Returns information on the next significant space flight in the space industry', false, SpaceCommands.nextlaunch); + //admin commands addCommand('Shutdown', 'stop', undefined, 'stop', 'Shutsdown JefferyBot', true, AdminCommands.stop); addCommand('Reload', 'reload', undefined, 'reload', 'Reloads the server config and the misc config', false, AdminCommands.reload); diff --git a/commands/commands.js b/commands/commands.js index 015de36..c15398d 100644 --- a/commands/commands.js +++ b/commands/commands.js @@ -65,9 +65,9 @@ module.exports.dog = async function(message, msg, args, discordclient) { var url = 'https://dog.ceo/api/breeds/image/random'; try { var result = await Helper.requestPromise(url); - var output = JSON.parse(result).message; + var output = JSON.parse(result).messsage; } catch (e) { - message.channel.send(`:no_entry_sign: \`Somthing went wrong\``); + message.channel.send(`:no_entry_sign: \`There was a problem with the API...\``); return; } var em = new Discord.RichEmbed(); @@ -92,6 +92,7 @@ module.exports.undo = function (message, msg, args, discordclient) { module.exports.hug = function(message, msg, args, discordclient) { var em = new Discord.RichEmbed(); + em.setColor('BLUE'); em.setImage('https://cdn.discordapp.com/attachments/345580737149403146/442232811605458957/cat-instantly-hugs-plush-toy.gif'); message.channel.send(em); -} \ No newline at end of file +} diff --git a/commands/spacecommands.js b/commands/spacecommands.js new file mode 100644 index 0000000..0a955f6 --- /dev/null +++ b/commands/spacecommands.js @@ -0,0 +1,23 @@ +const Discord = require('discord.js'); +const ping = require('ping'); +const fs = require('fs'); +const Config = require('../config.js'); +const Helper = require('../helper.js'); + +/*message object, messaage full, message args, discord client*/ + +module.exports.nextlaunch = async function(message, msg, args, discordclient) { + var url = 'https://launchlibrary.net/1.4/launch/next/1'; + try { + var result = await Helper.requestPromise(url); + var json = JSON.parse(result).launches; + + var em = new Discord.RichEmbed(); + em.setTitle(json.name); + + message.channel.send(em); + } catch (e) { + console.log(e); + message.channel.send(`:no_entry_sign: \`There was a problem with the API...\``); + } +} diff --git a/helper.js b/helper.js index 95104f8..748f6bd 100644 --- a/helper.js +++ b/helper.js @@ -9,7 +9,7 @@ const Config = require('./config'); const Commands = require('./commands/commands') const CommandManager = require('./commandmanager'); -module.exports.requestPromise = function(url) { +module.exports.requestPromise = async function(url) { return new Promise((resolve, reject) => { request(url, function(error, response, body) { if (error) {