-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
74 lines (67 loc) · 2.06 KB
/
bot.js
File metadata and controls
74 lines (67 loc) · 2.06 KB
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
require('dotenv').config();
const StaticMaps = require('staticmaps');
//Declare variables for fetch module
const fetch = require('node-fetch');
const ISSURL = "https://api.wheretheiss.at/v1/satellites/25544";
let settings = { method: "Get" };
//Get Discord client
const Discord = require('discord.js');
const client = new Discord.Client();
//Get BOTTOKEN
client.login(process.env.BOTTOKEN);
//Server set up
client.on('ready', readyDiscord);
//Connection with Discord established
function readyDiscord(){
console.log('Outta this world! 👽');
}
//Get map with marker of ISS location
async function getISSData(){
const response = await fetch(ISSURL, settings);
const data = await response.json();
const { latitude, longitude } = data;
const options = {
width: 720,
height: 720
};
const map = new StaticMaps(options);
const marker = {
img: './marker.png',
width: 48,
height: 48,
coord: [longitude, latitude]
};
map.addMarker(marker);
map.render([longitude, latitude], 4)
.then(() => map.image.save('map.png'))
.then(() => console.log('File saved!'))
.catch(console.log);
}
function sleep(ms){
return new Promise(resolve => setTimeout(resolve, ms));
}
client.on('message', gotMessage);
async function gotMessage(msg){
console.log(msg.content);
getISSData();
//Send picture with approximate location
if(msg.content == '!locate'){
await sleep(2000);
const attachment = new Discord.MessageAttachment('./map.png');
msg.channel.send('This is an approximate location of the ISS', attachment);
}
//Give help instructions
else if(msg.content == '!help'){
const embed = new Discord.MessageEmbed()
.setTitle('Instructions')
.setColor(0xff0000)
.setDescription('Use \'!locate\' to get the location of the ISS.\nUse\'!help\' to make this menu pop up.');
msg.channel.send(embed);
}
}
//Welcome new members
client.on('guildMemberAdd', member => {
const channel = member.guild.channels.cache.find(ch => ch.name === 'member-log');
if (!channel) return;
channel.send(`здравствуйте, ${member}!`);
});