|
|
|
@ -6,7 +6,7 @@ const wfos = require("./data/wfos.json");
|
|
|
|
|
const blacklist = require("./data/blacklist.json");
|
|
|
|
|
const events = require("./data/events.json");
|
|
|
|
|
const outlookURLs = require("./data/outlook.json");
|
|
|
|
|
const satellites = require("./data/satellites.json");
|
|
|
|
|
const sattelites = require("./data/sattelites.json");
|
|
|
|
|
const nwrstreams = {callsigns:{}};
|
|
|
|
|
const Jimp = require("jimp");
|
|
|
|
|
const { client, xml } = require("@xmpp/client");
|
|
|
|
@ -377,14 +377,13 @@ xmpp.on("stanza", (stanza) => {
|
|
|
|
|
const now = new Date();
|
|
|
|
|
const diff = (now - product_id.timestamp) / 1000 / 60;
|
|
|
|
|
if (diff > 3) return;
|
|
|
|
|
// if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} New message from ${fromChannel}`);
|
|
|
|
|
console.log(`${colors.cyan("[INFO]")} ${getWFOByRoom(fromChannel).location} - ${evt.text} - ${product_id.timestamp}`);
|
|
|
|
|
if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} New message from ${fromChannel}`);
|
|
|
|
|
messages++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle NTFY
|
|
|
|
|
if (config.ntfy.enabled) {
|
|
|
|
|
//if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} Sending NTFY for ${config.ntfy.prefix}${fromChannel}`)
|
|
|
|
|
if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} Sending NTFY for ${config.ntfy.prefix}${fromChannel}`)
|
|
|
|
|
ntfyBody = {
|
|
|
|
|
"topic": `${config.ntfy.prefix}${fromChannel}`,
|
|
|
|
|
"message": bodyData.string,
|
|
|
|
@ -402,7 +401,7 @@ xmpp.on("stanza", (stanza) => {
|
|
|
|
|
'Authorization': `Bearer ${config.ntfy.token}`
|
|
|
|
|
}
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
//if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} NTFY sent for ${config.ntfy.prefix}${fromChannel} with status ${res.status} ${res.statusText}`);
|
|
|
|
|
if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} NTFY sent for ${config.ntfy.prefix}${fromChannel} with status ${res.status} ${res.statusText}`);
|
|
|
|
|
if (res.status !== 200) console.log(`${colors.red("[ERROR]")} NTFY failed for ${config.ntfy.prefix}${fromChannel} with status ${res.status} ${res.statusText}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -523,7 +522,6 @@ xmpp.on("stanza", (stanza) => {
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
console.log(`${colors.red("[ERROR]")} Failed to send message to ${channel.guild.ownerId}`);
|
|
|
|
|
}).then(() => {
|
|
|
|
|
if (channel.guildId == config.discord.mainGuild) return;
|
|
|
|
|
db.run(`DELETE FROM channels WHERE channelid = ? AND iemchannel = ?`, [channel.id, fromChannel], (err) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
console.error(err.message);
|
|
|
|
@ -577,27 +575,6 @@ xmpp.on("stanza", (stanza) => {
|
|
|
|
|
thisMsg.content = row.custommessage || null;
|
|
|
|
|
user.send(thisMsg).catch((err) => {
|
|
|
|
|
console.error(err);
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
console.log(`${colors.yellow("[WARN]")} Failed to send message to ${user.tag} (${user.id})`);
|
|
|
|
|
const logChannel = discord.guilds.cache.get(config.discord.mainGuild).channels.cache.get(config.discord.logChannel);
|
|
|
|
|
logChannel.send({
|
|
|
|
|
embeds: [
|
|
|
|
|
{
|
|
|
|
|
title: "Failed to send DM",
|
|
|
|
|
description: `User may have DMs disabled, or bot doesnt' share a server anymore!.
|
|
|
|
|
User: ${user.tag} (${user.id})
|
|
|
|
|
Sub Info: \`\`\`json\n${JSON.stringify(row)}\`\`\``,
|
|
|
|
|
color: 0xff0000
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}).then(() => {
|
|
|
|
|
db.run(`DELETE FROM userAlerts WHERE userid = ? AND iemchannel = ?`, [user.id, fromChannel], (err) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
console.error(err.message);
|
|
|
|
|
}
|
|
|
|
|
console.log(`${colors.cyan("[INFO]")} Deleted user ${user.id} from database`);
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}).catch((err) => {
|
|
|
|
@ -704,19 +681,19 @@ discord.on('ready', async () => {
|
|
|
|
|
commands = require("./data/commands.json");
|
|
|
|
|
// Add dynamic commands (based on datas files)
|
|
|
|
|
satCommand = {
|
|
|
|
|
"name": "satellite",
|
|
|
|
|
"description": "Get the latest satellite images from a given satellite",
|
|
|
|
|
"name": "sattelite",
|
|
|
|
|
"description": "Get the latest sattelite images from a given sattelite",
|
|
|
|
|
"options": [
|
|
|
|
|
{
|
|
|
|
|
"name": "satellite",
|
|
|
|
|
"description": "The satellite to get images from",
|
|
|
|
|
"name": "sattelite",
|
|
|
|
|
"description": "The sattelite to get images from",
|
|
|
|
|
"type": 3,
|
|
|
|
|
"required": true,
|
|
|
|
|
"choices": []
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
for (const key in satellites) {
|
|
|
|
|
for (const key in sattelites) {
|
|
|
|
|
satCommand.options[0].choices.push({
|
|
|
|
|
"name": key,
|
|
|
|
|
"value": key
|
|
|
|
@ -1355,18 +1332,18 @@ discord.on("interactionCreate", async (interaction) => {
|
|
|
|
|
console.error(err);
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case "satellite": // Get satellite images
|
|
|
|
|
sat = interaction.options.getString("satellite");
|
|
|
|
|
if (!satellites[sat]) return interaction.reply({ content: "Invalid satellite", ephemeral: true });
|
|
|
|
|
case "sattelite": // Get satellite images
|
|
|
|
|
sat = interaction.options.getString("sattelite");
|
|
|
|
|
if (!sattelites[sat]) return interaction.reply({ content: "Invalid satellite", ephemeral: true });
|
|
|
|
|
// Fetch all the images
|
|
|
|
|
productOptions = []
|
|
|
|
|
await (() => {
|
|
|
|
|
for (const key in satellites[sat].products) {
|
|
|
|
|
// make a discord customid safe id for the product name, add it to the satellites object
|
|
|
|
|
satellites[sat].products[key].customid = key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
|
|
|
|
|
for (const key in sattelites[sat].products) {
|
|
|
|
|
// make a discord customid safe id for the product name, add it to the sattelites object
|
|
|
|
|
sattelites[sat].products[key].customid = key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
|
|
|
|
|
productOptions.push({
|
|
|
|
|
label: key,
|
|
|
|
|
value: satellites[sat].products[key].customid
|
|
|
|
|
value: sattelites[sat].products[key].customid
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
console.log(JSON.stringify(productOptions, null, 2))
|
|
|
|
@ -1449,7 +1426,7 @@ discord.on("interactionCreate", async (interaction) => {
|
|
|
|
|
sat = satData.sat
|
|
|
|
|
product = interaction.values[0];
|
|
|
|
|
// find the original product name
|
|
|
|
|
product_name = Object.keys(satellites[sat].products).find(key => satellites[sat].products[key].customid === product);
|
|
|
|
|
product_name = Object.keys(sattelites[sat].products).find(key => sattelites[sat].products[key].customid === product);
|
|
|
|
|
imageOptions = []
|
|
|
|
|
satMessages[interaction.customId.split("|")[1]] = {
|
|
|
|
|
sat,
|
|
|
|
@ -1458,13 +1435,13 @@ discord.on("interactionCreate", async (interaction) => {
|
|
|
|
|
images: {}
|
|
|
|
|
}
|
|
|
|
|
await (() => {
|
|
|
|
|
// for key, value in satellites[sat].products[product_name]
|
|
|
|
|
// for key, value in sattelites[sat].products[product_name]
|
|
|
|
|
console.log(product_name)
|
|
|
|
|
for (const key in satellites[sat].products[product_name]) {
|
|
|
|
|
// make a discord customid safe id for the product name, add it to the satellites object
|
|
|
|
|
//console.log(satellites[sat].products[product_name])
|
|
|
|
|
for (const key in sattelites[sat].products[product_name]) {
|
|
|
|
|
// make a discord customid safe id for the product name, add it to the sattelites object
|
|
|
|
|
//console.log(sattelites[sat].products[product_name])
|
|
|
|
|
if (key === "customid") continue;
|
|
|
|
|
satMessages[interaction.customId.split("|")[1]].images[key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()] = satellites[sat].products[product_name][key];
|
|
|
|
|
satMessages[interaction.customId.split("|")[1]].images[key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()] = sattelites[sat].products[product_name][key];
|
|
|
|
|
imageOptions.push({
|
|
|
|
|
label: key,
|
|
|
|
|
value: key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()
|
|
|
|
@ -1590,8 +1567,6 @@ discord.on("guildCreate", async (guild) => {
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
console.log(`${colors.red("[ERROR]")} Failed to send message to user ${user.id}: ${err.message}`);
|
|
|
|
|
})
|
|
|
|
|
channel.send({
|
|
|
|
|
embeds: [
|
|
|
|
@ -1670,7 +1645,5 @@ process.on("uncaughtException", (error) => {
|
|
|
|
|
return;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Login to discord
|
|
|
|
|
discord.login(config.discord.token);
|