dziban303-patch-1 #22

Open
dziban303 wants to merge 2 commits from dziban303/weather-bot:dziban303-patch-1 into main
Showing only changes of commit 310daf37f9 - Show all commits

View file

@ -6,7 +6,7 @@ const wfos = require("./data/wfos.json");
const blacklist = require("./data/blacklist.json"); const blacklist = require("./data/blacklist.json");
const events = require("./data/events.json"); const events = require("./data/events.json");
const outlookURLs = require("./data/outlook.json"); const outlookURLs = require("./data/outlook.json");
const sattelites = require("./data/sattelites.json"); const satellites = require("./data/satellites.json");
const nwrstreams = {callsigns:{}}; const nwrstreams = {callsigns:{}};
const Jimp = require("jimp"); const Jimp = require("jimp");
const { client, xml } = require("@xmpp/client"); const { client, xml } = require("@xmpp/client");
@ -681,19 +681,19 @@ discord.on('ready', async () => {
commands = require("./data/commands.json"); commands = require("./data/commands.json");
// Add dynamic commands (based on datas files) // Add dynamic commands (based on datas files)
satCommand = { satCommand = {
"name": "sattelite", "name": "satellite",
"description": "Get the latest sattelite images from a given sattelite", "description": "Get the latest satellite images from a given satellite",
"options": [ "options": [
{ {
"name": "sattelite", "name": "satellite",
"description": "The sattelite to get images from", "description": "The satellite to get images from",
"type": 3, "type": 3,
"required": true, "required": true,
"choices": [] "choices": []
} }
] ]
} }
for (const key in sattelites) { for (const key in satellites) {
satCommand.options[0].choices.push({ satCommand.options[0].choices.push({
"name": key, "name": key,
"value": key "value": key
@ -1332,18 +1332,18 @@ discord.on("interactionCreate", async (interaction) => {
console.error(err); console.error(err);
}); });
break; break;
case "sattelite": // Get satellite images case "satellite": // Get satellite images
sat = interaction.options.getString("sattelite"); sat = interaction.options.getString("satellite");
if (!sattelites[sat]) return interaction.reply({ content: "Invalid satellite", ephemeral: true }); if (!satellites[sat]) return interaction.reply({ content: "Invalid satellite", ephemeral: true });
// Fetch all the images // Fetch all the images
productOptions = [] productOptions = []
await (() => { await (() => {
for (const key in sattelites[sat].products) { for (const key in satellites[sat].products) {
// make a discord customid safe id for the product name, add it to the sattelites object // make a discord customid safe id for the product name, add it to the satellites object
sattelites[sat].products[key].customid = key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase(); satellites[sat].products[key].customid = key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
productOptions.push({ productOptions.push({
label: key, label: key,
value: sattelites[sat].products[key].customid value: satellites[sat].products[key].customid
}) })
} }
console.log(JSON.stringify(productOptions, null, 2)) console.log(JSON.stringify(productOptions, null, 2))
@ -1426,7 +1426,7 @@ discord.on("interactionCreate", async (interaction) => {
sat = satData.sat sat = satData.sat
product = interaction.values[0]; product = interaction.values[0];
// find the original product name // find the original product name
product_name = Object.keys(sattelites[sat].products).find(key => sattelites[sat].products[key].customid === product); product_name = Object.keys(satellites[sat].products).find(key => satellites[sat].products[key].customid === product);
imageOptions = [] imageOptions = []
satMessages[interaction.customId.split("|")[1]] = { satMessages[interaction.customId.split("|")[1]] = {
sat, sat,
@ -1435,13 +1435,13 @@ discord.on("interactionCreate", async (interaction) => {
images: {} images: {}
} }
await (() => { await (() => {
// for key, value in sattelites[sat].products[product_name] // for key, value in satellites[sat].products[product_name]
console.log(product_name) console.log(product_name)
for (const key in sattelites[sat].products[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 sattelites object // make a discord customid safe id for the product name, add it to the satellites object
//console.log(sattelites[sat].products[product_name]) //console.log(satellites[sat].products[product_name])
if (key === "customid") continue; if (key === "customid") continue;
satMessages[interaction.customId.split("|")[1]].images[key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()] = sattelites[sat].products[product_name][key]; satMessages[interaction.customId.split("|")[1]].images[key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()] = satellites[sat].products[product_name][key];
imageOptions.push({ imageOptions.push({
label: key, label: key,
value: key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase() value: key.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()