From a2519de93ba57780ecf8195148b2e4d91d064209 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Wed, 26 Sep 2018 13:23:45 +0200 Subject: [PATCH] Added a basic weather command --- commands/fun/weather.js | 36 ++++++++++++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 commands/fun/weather.js diff --git a/commands/fun/weather.js b/commands/fun/weather.js new file mode 100644 index 00000000..d992a652 --- /dev/null +++ b/commands/fun/weather.js @@ -0,0 +1,36 @@ +const { Command } = require('discord.js-commando'); +const Discord = require('discord.js'); +const snekfetch = require('snekfetch'); +module.exports = class WeatherCommand extends Command { + constructor(client) { + super(client, { + name: 'weather', + group: 'fun', + memberName: 'weather', + description: `Choose the city you want to know the weather`, + args: [ + { + key: 'city', + prompt: 'city', + type: 'string', + } + ] + }); + } + + async run(message, { city }) { + const { body } = await snekfetch.get('https://api.openweathermap.org/data/2.5/weather?q='+ city +'&units=metric&APPID=688e6d7bcdfdc4b71d921a3de461f76b'); + if (!body.main.temp) { + return message.say(`No results found for **${city}**`); + } + const test = new Discord.RichEmbed() + .setColor("#ff9900") + .setTitle(body.name + ' current weather') + .setDescription(body.main.temp + '°c') + .addField('Temp min', body.main.temp_min + '°c') + .addField('Temp max', body.main.temp_max + '°c') + + + message.say(test); + } +}; \ No newline at end of file diff --git a/package.json b/package.json index 89956917..fe8ffbb1 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "homepage": "https://gitlab.com/loicbersier/discordbot#readme", "dependencies": { "discord.js": "^11.4.2", - "discord.js-commando": "^0.10.0" + "discord.js-commando": "^0.10.0", + "snekfetch": "^4.0.4" } }