-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
60 lines (47 loc) · 1.49 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
const { Client, GatewayIntentBits, ActivityType, EmbedBuilder } = require("discord.js");
const axios = require("axios").default;
const config = require("./config.json");
const url = "https://www.oref.org.il/WarningMessages/alert/alerts.json";
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
client.once("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity("rockets from gaza", { type: ActivityType.Watching });
let prevId = "";
setInterval(() => {
axios.get(url, {
headers: {
"Accept": "application/json",
"X-Requested-With": "XMLHttpRequest",
"Referer": "https://www.oref.org.il/12481-he/Pakar.aspx"
},
maxContentLength: Infinity
})
.then(res => {
if (res.data !== "" && res.data.constructor === Object) {
let json = JSON.parse(JSON.stringify(res.data));
if (json.id != prevId){
prevId = json.id;
let locations = "";
for (let i = 0; i < json.data.length; i++) {
locations += json.data[i] + "\n";
}
let embed = new EmbedBuilder()
.setColor("#ff0001")
.setTitle(json.title)
.setDescription(json.desc)
.addFields({
name: "יישובים",
value: locations
})
.setTimestamp();
client.channels.cache.get(config.CHANNELID).send({ embeds: [embed] });
console.log(`[${new Date()}] Sent message!`);
}
}
})
.catch(err => {
console.log(err);
});
}, 1500);
});
client.login(config.TOKEN);