-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
111 lines (70 loc) · 2.7 KB
/
index.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const Discord = require('discord.js');
const config = require('./config.json');
const fetch = require('node-fetch');
const client = new Discord.Client();
//checking about the initialization of the bot
client.once('ready', () => {
console.log('Space Information Bot is online!');
});
//All the commands for the bot
client.on('message', async msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
//Help command of the bot
if(msg.content === '!help')
{
msg.reply('Type !apod for Astronomy Picture Of The Day\nType !wmars for the weather on Mars\nType !launches for the next 5 launches');
}
//Command for NASA's api APOD(Astronomical Picture of the Day)
if (msg.content === '!apod')
{
let getApod = async () => {
let result = await fetch
('https://api.nasa.gov/planetary/apod?api_key=jZ7JIaKjGCMnOlPwqFryi0cfXaenexyWAJPXePcb')
let json = await result.json()
return json
}
let apodValue = await getApod();
msg.reply("Today's date is: " + apodValue.date +
"\n\nTitle: " +apodValue.title +
"\n\nWhat is it?: " + apodValue.explanation +
"\n\nCopyright: " + apodValue.copyright + "\n\n" +
apodValue.hdurl);
}
// Command for lastest weather on Mars
if (msg.content === '!wmars')
{
let getMarsData = async () => {
let result = await fetch
('https://api.nasa.gov/insight_weather/?api_key=wLY9MZpynjliPigK4cOJvRt9fHjmpXRM2qHFtnY2&feedtype=json&ver=1.0')
let json = await result.json()
return json
}
let marsDataVal = await getMarsData();
let sol = marsDataVal.sol_keys[6];
let lastestTemp = marsDataVal[sol].AT.av;
msg.reply("Latest temperature from NASA's InSight Mars Lander at Elysium Planitia: " + lastestTemp + '°C');
}
// Command for the lastest launches
if(msg.content === '!launches')
{
let getLaunches = async () => {
let result = await fetch
('https://launchlibrary.net/1.3/launch/next/5')
let json = await result.json()
return json
}
let launchesValue = await getLaunches();
msg.reply("Here are the launches:");
var i;
for (i = 0; i < 5; i++)
{
msg.channel.send(launchesValue.launches[i].name + "\n");
msg.channel.send("Date and Time : " + launchesValue.launches[i].net + "\n\n");
msg.channel.send("-----------------------------------");
}
}
});
//token for space information bot
client.login(config.token);