forked from kappithannemo/WhatsAsenaDuplicated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather.js
57 lines (48 loc) · 2.82 KB
/
weather.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* Copyright (C) 2020 Yusuf Usta.
Licensed under the GPL-3.0 License;
you may not use this file except in compliance with the License.
WhatsAsena - Yusuf Usta
*/
const Asena = require('../events');
const {MessageType} = require('@adiwajshing/baileys');
const got = require('got');
const Language = require('../language');
const Lang = Language.getString('weather');
Asena.addCommand({pattern: 'weather ?(.*)', desc: Lang.WEATHER_DESC}, async (message, match) => {
if (match[1] === '') return await message.reply(Lang.NEED_LOCATION);
const url = `http://api.openweathermap.org/data/2.5/weather?q=${match[1]}&units=metric&appid=060a6bcfa19809c2cd4d97a212b19273&language=tr`;
try {
const response = await got(url);
const json = JSON.parse(response.body);
if (response.statusCode === 200) return await message.client.sendMessage(message.jid, '*📍 ' + Lang.LOCATION +':* ```' + match[1] + '```\n' +
'*🌐 ' + Lang.LAT +':* ```' + json.coord.lat + '```\n' +
'*🌐 ' + Lang.LONG +':* ```' + json.coord.lon + '```\n\n' +
'*ℹ ' + Lang.DESC +':* ```' + json.weather[0].description + '```\n' +
'*☀ ' + Lang.TEMP +':* ```' + json.main.temp_max + '°```\n' +
'*💧 ' + Lang.HUMI +':* ```%' + json.main.humidity + '```\n' +
'*🔆 ' + Lang.FEEL +':* ```' + json.main.feels_like + '°```\n' +
'*💨 ' + Lang.WIND +':* ```' + json.wind.speed + 'm/s```\n' +
'*☁ ' + Lang.CLOUD +':* ```%' + json.clouds.all + '```\n', MessageType.text,{quoted: message.data});
} catch {
return await message.client.sendMessage(message.jid, Lang.NOT_FOUND, MessageType.text );
}
});
Asena.addCommand({pattern: 'pweather ?(.*)', fromMe: true, dontAddCommandList: true}, async (message, match) => {
if (match[1] === '') return await message.reply(Lang.NEED_LOCATION);
const url = `http://api.openweathermap.org/data/2.5/weather?q=${match[1]}&units=metric&appid=060a6bcfa19809c2cd4d97a212b19273&language=tr`;
try {
const response = await got(url);
const json = JSON.parse(response.body);
if (response.statusCode === 200) return await message.client.sendMessage(message.jid, '*📍 ' + Lang.LOCATION +':* ```' + match[1] + '```\n' +
'*🌐 ' + Lang.LAT +':* ```' + json.coord.lat + '```\n' +
'*🌐 ' + Lang.LONG +':* ```' + json.coord.lon + '```\n\n' +
'*ℹ ' + Lang.DESC +':* ```' + json.weather[0].description + '```\n' +
'*☀ ' + Lang.TEMP +':* ```' + json.main.temp_max + '°```\n' +
'*💧 ' + Lang.HUMI +':* ```%' + json.main.humidity + '```\n' +
'*🔆 ' + Lang.FEEL +':* ```' + json.main.feels_like + '°```\n' +
'*💨 ' + Lang.WIND +':* ```' + json.wind.speed + 'm/s```\n' +
'*☁ ' + Lang.CLOUD +':* ```%' + json.clouds.all + '```\n', MessageType.text);
} catch {
return await message.client.sendMessage(message.jid, Lang.NOT_FOUND, MessageType.text);
}
});