Simp-O-Matic

Dumb Discord bot in TS.
git clone git://git.knutsen.co/Simp-O-Matic
Log | Files | Refs | README | LICENSE

commit 15b05d4d9777069e1d1e466efa70fb6d740ebbd2
parent 13720436e3d69cb62afa471780951f83b2120cc2
Author: danyisill <danyisill@users.noreply.github.com>
Date:   Mon, 23 Mar 2020 05:32:41 +0300

aaaah i cooded

Diffstat:
Mlib/commands/weather.ts | 22+++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/lib/commands/weather.ts b/lib/commands/weather.ts @@ -1,4 +1,5 @@ import fetch, { Response } from 'node-fetch'; +import { MessageAttachment, MessageEmbed } from 'discord.js'; const WEATHER_URL = 'http://api.openweathermap.org/data/2.5/weather'; @@ -29,15 +30,18 @@ export default (home_scope: HomeScope) => { const hour = (24 + date.getUTCHours() + tz) % 24; const country = !d.sys ? 'somewhere' : d.sys.country; - if (d.main) - message.answer(`${hour}:${date.getMinutes()} ${d.name}, \ - ${country}: ${d.main.temp}°C \ - (feels like ${d.main.feels_like}°C) \ - ${d.weather[0].description}, \ - ${d.main.temp_max}°C max, \ - ${d.main.temp_min}°C min`.squeeze()); - else message.answer(`Cannot get weather information` - + ` from ${location}.`); + const embed = d.main?new Discord.MessageEmbed() + .setTitle(`${d.main.temp}°C (feels like ${d.main.feels_like}°C`) + .setAuthor(`${d.name}, ${country} ${hour}:${date.getMinutes()}`) + .setDescription(d.weather[0].description) + .setThumbnail(`https://openweathermap.org/img/wn/${d.weather[0].icon}@2x.png`) + .addFields( + {name: 'Day temp', value: d.main.temp_max + '°C', inline: true}, + {name: 'Night temp', value: d.main.temp_min + '°C', inline: true} + ) + :new Discord.MessageEmbed().setTitle(`Cannot get weather information from ${location}.`); + + message.channel.send(embed); }) .catch(error); }