mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-04 15:56:52 +02:00
55 lines
2.9 KiB
JavaScript
55 lines
2.9 KiB
JavaScript
const { Command } = require('discord.js-commando');
|
|
const { RichEmbed } = require('discord.js');
|
|
const request = require('superagent');
|
|
|
|
module.exports = class ForecastCommand extends Command {
|
|
constructor(client) {
|
|
super(client, {
|
|
name: 'forecast',
|
|
group: 'search',
|
|
memberName: 'forecast',
|
|
description: 'Gets the seven-day forecast for a specified location.',
|
|
args: [{
|
|
key: 'location',
|
|
prompt: 'What location would you like to get the forecast for?',
|
|
type: 'string'
|
|
}]
|
|
});
|
|
}
|
|
|
|
async run(message, args) {
|
|
if (message.channel.type !== 'dm')
|
|
if (!message.channel.permissionsFor(this.client.user).has('EMBED_LINKS'))
|
|
return message.say('This Command requires the `Embed Links` Permission.');
|
|
const { location } = args;
|
|
try {
|
|
const { body } = await request
|
|
.get(`https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where u=\'f\' AND woeid in (select woeid from geo.places(1) where text="${location}")&format=json`);
|
|
const info = body.query.results.channel;
|
|
const data = info.item.forecast;
|
|
const embed = new RichEmbed()
|
|
.setColor(0x0000FF)
|
|
.setAuthor(info.title, 'http://media.idownloadblog.com/wp-content/uploads/2013/12/yahoo-weather-213x220.png')
|
|
.setURL(info.link)
|
|
.setTimestamp()
|
|
.addField(`**${data[0].day} - ${data[0].date}:**`,
|
|
`**High:** ${data[0].high}°F, **Low:** ${data[0].low}°F, **Condition:** ${data[0].text}`)
|
|
.addField(`**${data[1].day} - ${data[1].date}:**`,
|
|
`**High:** ${data[1].high}°F, **Low:** ${data[1].low}°F, **Condition:** ${data[1].text}`)
|
|
.addField(`**${data[2].day} - ${data[2].date}:**`,
|
|
`**High:** ${data[2].high}°F, **Low:** ${data[2].low}°F, **Condition:** ${data[2].text}`)
|
|
.addField(`**${data[3].day} - ${data[3].date}:**`,
|
|
`**High:** ${data[3].high}°F, **Low:** ${data[3].low}°F, **Condition:** ${data[3].text}`)
|
|
.addField(`**${data[4].day} - ${data[4].date}:**`,
|
|
`**High:** ${data[4].high}°F, **Low:** ${data[4].low}°F, **Condition:** ${data[4].text}`)
|
|
.addField(`**${data[5].day} - ${data[5].date}:**`,
|
|
`**High:** ${data[5].high}°F, **Low:** ${data[5].low}°F, **Condition:** ${data[5].text}`)
|
|
.addField(`**${data[6].day} - ${data[6].date}:**`,
|
|
`**High:** ${data[6].high}°F, **Low:** ${data[6].low}°F, **Condition:** ${data[6].text}`);
|
|
return message.embed(embed);
|
|
} catch (err) {
|
|
return message.say('An Error Occurred. The location may not have been found.');
|
|
}
|
|
}
|
|
};
|