From bbe9a65b6583d7eebe85ffcfec79708a747313a0 Mon Sep 17 00:00:00 2001 From: dragonfire535 Date: Mon, 13 Mar 2017 23:12:28 -0400 Subject: [PATCH] More Additions --- commands/search/forecast.js | 51 +++++++++++++++++++++++++++++++++++++ index.js | 3 +-- 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 commands/search/forecast.js diff --git a/commands/search/forecast.js b/commands/search/forecast.js new file mode 100644 index 00000000..a20badee --- /dev/null +++ b/commands/search/forecast.js @@ -0,0 +1,51 @@ +const commando = require('discord.js-commando'); +const Discord = require('discord.js'); +const weather = require('yahoo-weather'); + +class ForecastCommand extends commando.Command { + constructor(Client){ + super(Client, { + name: 'forecast', + group: 'search', + memberName: 'forecast', + description: 'Gets the seven-day forecast for a specified location. (;forecast San Francisco)', + examples: [';forecast San Francisco'] + }); + } + + async run(message, args) { + if(message.channel.type !== 'dm') { + if(!message.channel.permissionsFor(this.client.user).hasPermission('SEND_MESSAGES')) return; + if(!message.channel.permissionsFor(this.client.user).hasPermission('READ_MESSAGES')) return; + if(!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return; + } + console.log("[Command] " + message.content); + let locationtosearch = message.content.split(" ").slice(1).join(" "); + weather(locationtosearch, 'f').then(info => { + const embed = new Discord.RichEmbed() + .setColor(0x0000FF) + .setAuthor(info.title, 'http://media.idownloadblog.com/wp-content/uploads/2013/12/yahoo-weather-213x220.png') + .setURL(info.link) + .setTimestamp() + .addField('**' + info.item.forecast[0].day + " - " + info.item.forecast[0].date + ':**', + '**High:** ' + info.item.forecast[0].high + ', **Low:** ' + info.item.forecast[0].low + ', **Condition:** ' + info.item.forecast[0].text) + .addField('**' + info.item.forecast[1].day + " - " + info.item.forecast[1].date + ':**', + '**High:** ' + info.item.forecast[1].high + ', **Low:** ' + info.item.forecast[1].low + ', **Condition:** ' + info.item.forecast[1].text) + .addField('**' + info.item.forecast[2].day + " - " + info.item.forecast[2].date + ':**', + '**High:** ' + info.item.forecast[2].high + ', **Low:** ' + info.item.forecast[2].low + ', **Condition:** ' + info.item.forecast[2].text) + .addField('**' + info.item.forecast[3].day + " - " + info.item.forecast[3].date + ':**', + '**High:** ' + info.item.forecast[3].high + ', **Low:** ' + info.item.forecast[3].low + ', **Condition:** ' + info.item.forecast[3].text) + .addField('**' + info.item.forecast[4].day + " - " + info.item.forecast[4].date + ':**', + '**High:** ' + info.item.forecast[4].high + ', **Low:** ' + info.item.forecast[4].low + ', **Condition:** ' + info.item.forecast[4].text) + .addField('**' + info.item.forecast[5].day + " - " + info.item.forecast[5].date + ':**', + '**High:** ' + info.item.forecast[5].high + ', **Low:** ' + info.item.forecast[5].low + ', **Condition:** ' + info.item.forecast[5].text) + .addField('**' + info.item.forecast[6].day + " - " + info.item.forecast[6].date + ':**', + '**High:** ' + info.item.forecast[6].high + ', **Low:** ' + info.item.forecast[6].low + ', **Condition:** ' + info.item.forecast[6].text); + message.channel.sendEmbed(embed).catch(console.error); + }).catch(err => { + message.channel.sendMessage(":x: Error! Make sure you typed the location correctly!"); + }); + } +} + +module.exports = ForecastCommand; \ No newline at end of file diff --git a/index.js b/index.js index 5e4ac471..e835becc 100644 --- a/index.js +++ b/index.js @@ -72,11 +72,10 @@ client.on('message', (message) => { } if(message.channel.type !== 'dm') { if (message.content.startsWith("<@" + client.user.id + ">")){ - if(message.guild.id === config.server) { + if(message.guild.id === config.server || message.author.id === config.owner) { console.log("[Cleverbot] " + message.content); if(message.author.id === clevusers.allowed[message.author.id]) { let cleverMessage = message.content.replace("<@" + client.user.id + ">", ""); - cleverMessage = cleverMessage.replace("", ''); message.channel.startTyping(); cleverbot.write(cleverMessage, function (response) { message.reply(response.output);