forked from ChrisChrome/weather-bot
Compare commits
29 commits
debug-10-2
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
664e00b7f4 | ||
|
cce9b12645 | ||
|
c82ab68c1e | ||
|
a543386394 | ||
|
1ae72ac979 | ||
|
1a7c1735f4 | ||
|
5b487125aa | ||
|
770813b4a7 | ||
|
ded7a2373c | ||
|
79ae2f4c25 | ||
|
e02faaab18 | ||
|
bd275403e9 | ||
|
9b80f79436 | ||
|
4bb679cef8 | ||
|
e952ec60e7 | ||
|
0227979176 | ||
|
9f31d18a6f | ||
|
d491fda5c8 | ||
|
96912d325a | ||
|
00f97fd6e6 | ||
|
09f3fc957c | ||
|
cbb1842100 | ||
|
f763a95472 | ||
|
d88188182c | ||
|
8b94e7e3f8 | ||
|
d653bc3e90 | ||
|
b5bf06a38d | ||
|
ae63a0d52d | ||
|
73e42e2288 |
|
@ -91,6 +91,4 @@
|
||||||
"zsechat@conference.weather.im",
|
"zsechat@conference.weather.im",
|
||||||
"zdcchat@conference.weather.im",
|
"zdcchat@conference.weather.im",
|
||||||
"znychat@conference.weather.im"
|
"znychat@conference.weather.im"
|
||||||
|
|
||||||
|
|
||||||
]
|
]
|
|
@ -365,7 +365,7 @@
|
||||||
},
|
},
|
||||||
"FFW": {
|
"FFW": {
|
||||||
"text": "Flash Flood Warning",
|
"text": "Flash Flood Warning",
|
||||||
"priority": 4
|
"priority": 5
|
||||||
},
|
},
|
||||||
"FLN": {
|
"FLN": {
|
||||||
"priority": 1,
|
"priority": 1,
|
||||||
|
@ -1164,7 +1164,7 @@
|
||||||
"text": "Tropical Cyclone Watch/Warning Break Points"
|
"text": "Tropical Cyclone Watch/Warning Break Points"
|
||||||
},
|
},
|
||||||
"TIB": {
|
"TIB": {
|
||||||
"priority": 4,
|
"priority": 3,
|
||||||
"text": "Tsunami Bulletin"
|
"text": "Tsunami Bulletin"
|
||||||
},
|
},
|
||||||
"TID": {
|
"TID": {
|
||||||
|
@ -1308,7 +1308,7 @@
|
||||||
"text": "Routine Space Environment Product Issued Weekly"
|
"text": "Routine Space Environment Product Issued Weekly"
|
||||||
},
|
},
|
||||||
"WOU": {
|
"WOU": {
|
||||||
"priority": 4,
|
"priority": 5,
|
||||||
"text": "Tornado/Severe Thunderstorm Watch"
|
"text": "Tornado/Severe Thunderstorm Watch"
|
||||||
},
|
},
|
||||||
"WS1": {
|
"WS1": {
|
||||||
|
@ -1345,7 +1345,7 @@
|
||||||
},
|
},
|
||||||
"WSW": {
|
"WSW": {
|
||||||
"text": "Winter Storm Warning",
|
"text": "Winter Storm Warning",
|
||||||
"priority": 5
|
"priority": 4
|
||||||
},
|
},
|
||||||
"WWA": {
|
"WWA": {
|
||||||
"priority": 1,
|
"priority": 1,
|
||||||
|
@ -1365,11 +1365,11 @@
|
||||||
},
|
},
|
||||||
"CFA": {
|
"CFA": {
|
||||||
"text": "Coastal Flood Watch",
|
"text": "Coastal Flood Watch",
|
||||||
"priority": 4
|
"priority": 3
|
||||||
},
|
},
|
||||||
"FLA": {
|
"FLA": {
|
||||||
"text": "Flood Watch",
|
"text": "Flood Watch",
|
||||||
"priority": 2
|
"priority": 3
|
||||||
},
|
},
|
||||||
"HWA": {
|
"HWA": {
|
||||||
"text": "High Wind Watch",
|
"text": "High Wind Watch",
|
||||||
|
@ -1389,7 +1389,7 @@
|
||||||
},
|
},
|
||||||
"SVA": {
|
"SVA": {
|
||||||
"text": "Severe Thunderstorm Watch",
|
"text": "Severe Thunderstorm Watch",
|
||||||
"priority": 4
|
"priority": 5
|
||||||
},
|
},
|
||||||
"TOA": {
|
"TOA": {
|
||||||
"text": "Tornado Watch",
|
"text": "Tornado Watch",
|
||||||
|
@ -1405,7 +1405,7 @@
|
||||||
},
|
},
|
||||||
"TSA": {
|
"TSA": {
|
||||||
"text": "Tsunami Watch",
|
"text": "Tsunami Watch",
|
||||||
"priority": 4
|
"priority": 5
|
||||||
},
|
},
|
||||||
"TSW": {
|
"TSW": {
|
||||||
"text": "Tsunami Warning",
|
"text": "Tsunami Warning",
|
||||||
|
@ -1522,6 +1522,9 @@
|
||||||
"REP": {
|
"REP": {
|
||||||
"text": "RECCO Observations (tropical cyclone)",
|
"text": "RECCO Observations (tropical cyclone)",
|
||||||
"priority": 3
|
"priority": 3
|
||||||
|
},
|
||||||
|
"PIR": {
|
||||||
|
"text": "Pilot Reports",
|
||||||
|
"priority": 1
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
{
|
{
|
||||||
"convective": [
|
"convective": [
|
||||||
"https://www.spc.noaa.gov/products/outlook/day1otlk.gif",
|
"https://weather.cod.edu/cdata/text/images/spc/co/day1/categorical/spccoday1.categorical.latest.png",
|
||||||
"https://www.spc.noaa.gov/products/outlook/day2otlk.gif",
|
"https://climate.cod.edu/data/text/images/spc/co/day2/categorical/spccoday2.categorical.latest.png",
|
||||||
"https://www.spc.noaa.gov/products/outlook/day3otlk.gif",
|
"https://climate.cod.edu/data/text/images/spc/co/day3/categorical/spccoday3.categorical.latest.png",
|
||||||
"https://www.spc.noaa.gov/products/exper/day4-8/day4prob.gif",
|
"https://climate.cod.edu/data/text/images/spc/co/day4/severe/spccoday4.severe.latest.png",
|
||||||
"https://www.spc.noaa.gov/products/exper/day4-8/day5prob.gif",
|
"https://climate.cod.edu/data/text/images/spc/co/day5/severe/spccoday5.severe.latest.png",
|
||||||
"https://www.spc.noaa.gov/products/exper/day4-8/day6prob.gif",
|
"https://climate.cod.edu/data/text/images/spc/co/day6/severe/spccoday6.severe.latest.png",
|
||||||
"https://www.spc.noaa.gov/products/exper/day4-8/day7prob.gif",
|
"https://climate.cod.edu/data/text/images/spc/co/day7/severe/spccoday7.severe.latest.png",
|
||||||
"https://www.spc.noaa.gov/products/exper/day4-8/day8prob.gif"
|
"https://climate.cod.edu/data/text/images/spc/co/day8/severe/spccoday8.severe.latest.png"
|
||||||
],
|
],
|
||||||
"fire": [
|
"fire": [
|
||||||
"https://www.spc.noaa.gov/products/exper/fire_wx/imgs/day1otlk_fire.gif",
|
"https://www.spc.noaa.gov/products/exper/fire_wx/imgs/day1otlk_fire.gif",
|
||||||
|
|
157
index.js
157
index.js
|
@ -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");
|
||||||
|
@ -21,6 +21,7 @@ satMessages = {};
|
||||||
|
|
||||||
// Setup Discord
|
// Setup Discord
|
||||||
const discord = new Discord.Client({
|
const discord = new Discord.Client({
|
||||||
|
|
||||||
intents: [
|
intents: [
|
||||||
"Guilds",
|
"Guilds",
|
||||||
"GuildVoiceStates",
|
"GuildVoiceStates",
|
||||||
|
@ -35,7 +36,6 @@ const rest = new REST({
|
||||||
version: '10'
|
version: '10'
|
||||||
}).setToken(config.discord.token);
|
}).setToken(config.discord.token);
|
||||||
|
|
||||||
|
|
||||||
// Setup SQlite DB
|
// Setup SQlite DB
|
||||||
const db = new sqlite3.Database("channels.db", (err) => {
|
const db = new sqlite3.Database("channels.db", (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -360,6 +360,16 @@ xmpp.on("stanza", (stanza) => {
|
||||||
evt = { name: "Unknown", priority: 3 }
|
evt = { name: "Unknown", priority: 3 }
|
||||||
console.log(`${colors.red("[ERROR]")} Unknown event type: ${product_id.pil.substring(0, 3)}. Fix me`);
|
console.log(`${colors.red("[ERROR]")} Unknown event type: ${product_id.pil.substring(0, 3)}. Fix me`);
|
||||||
console.log(`${colors.magenta("[DEBUG]")} ${bodyData.string}`)
|
console.log(`${colors.magenta("[DEBUG]")} ${bodyData.string}`)
|
||||||
|
const logChannel = discord.guilds.cache.get(config.discord.mainGuild).channels.cache.get(config.discord.logChannel);
|
||||||
|
logChannel.send({
|
||||||
|
embeds: [
|
||||||
|
{
|
||||||
|
title: "Unknown Event Type",
|
||||||
|
description: `Unknown event type: ${product_id.pil.substring(0, 3)}. Please check the logs for more details.`,
|
||||||
|
color: 0xff0000
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
evt.code = product_id.pil.substring(0, 3);
|
evt.code = product_id.pil.substring(0, 3);
|
||||||
|
@ -367,13 +377,14 @@ xmpp.on("stanza", (stanza) => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const diff = (now - product_id.timestamp) / 1000 / 60;
|
const diff = (now - product_id.timestamp) / 1000 / 60;
|
||||||
if (diff > 3) return;
|
if (diff > 3) return;
|
||||||
if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} New message from ${fromChannel}`);
|
// 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}`);
|
||||||
messages++;
|
messages++;
|
||||||
|
|
||||||
|
|
||||||
// Handle NTFY
|
// Handle NTFY
|
||||||
if (config.ntfy.enabled) {
|
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 = {
|
ntfyBody = {
|
||||||
"topic": `${config.ntfy.prefix}${fromChannel}`,
|
"topic": `${config.ntfy.prefix}${fromChannel}`,
|
||||||
"message": bodyData.string,
|
"message": bodyData.string,
|
||||||
|
@ -391,7 +402,7 @@ xmpp.on("stanza", (stanza) => {
|
||||||
'Authorization': `Bearer ${config.ntfy.token}`
|
'Authorization': `Bearer ${config.ntfy.token}`
|
||||||
}
|
}
|
||||||
}).then((res) => {
|
}).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}`);
|
if (res.status !== 200) console.log(`${colors.red("[ERROR]")} NTFY failed for ${config.ntfy.prefix}${fromChannel} with status ${res.status} ${res.statusText}`);
|
||||||
|
|
||||||
|
|
||||||
|
@ -447,7 +458,7 @@ xmpp.on("stanza", (stanza) => {
|
||||||
console.log(`${colors.red("[ERROR]")} ${err.message}`);
|
console.log(`${colors.red("[ERROR]")} ${err.message}`);
|
||||||
}
|
}
|
||||||
if (!rows) return; // No channels to alert
|
if (!rows) return; // No channels to alert
|
||||||
rows.forEach((row) => {
|
rows.forEach(async (row) => {
|
||||||
// Get Filters as arrays
|
// Get Filters as arrays
|
||||||
if (!row.filterEvt) row.filterEvt = "";
|
if (!row.filterEvt) row.filterEvt = "";
|
||||||
if (!row.filter) row.filter = "";
|
if (!row.filter) row.filter = "";
|
||||||
|
@ -473,6 +484,54 @@ xmpp.on("stanza", (stanza) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}).then((msg) => {
|
}).then((msg) => {
|
||||||
if (msg.channel.type === Discord.ChannelType.GuildAnnouncement) msg.crosspost();
|
if (msg.channel.type === Discord.ChannelType.GuildAnnouncement) msg.crosspost();
|
||||||
|
}).catch((err) => {
|
||||||
|
console.log(`${colors.yellow("[WARN]")} Failed to send message to ${channel.guild.name}/${channel.name} (${channel.guild.id}/${channel.id})`);
|
||||||
|
const logChannel = discord.guilds.cache.get(config.discord.mainGuild).channels.cache.get(config.discord.logChannel);
|
||||||
|
logChannel.send({
|
||||||
|
embeds: [
|
||||||
|
{
|
||||||
|
title: "Failed to send message",
|
||||||
|
description: `There is likely an issue with permissions. Please notify the server owner if possible.
|
||||||
|
Guild: ${channel.guild.name} (${channel.guild.id})
|
||||||
|
Channel: ${channel.name} (${channel.id})
|
||||||
|
Guild Owner: <@${channel.guild.ownerId}> (${channel.guild.ownerId})
|
||||||
|
Sub Info: \`\`\`json\n${JSON.stringify(row)}\`\`\``,
|
||||||
|
color: 0xff0000
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
discord.users.fetch(channel.guild.ownerId).then((user) => {
|
||||||
|
user.send({
|
||||||
|
embeds: [
|
||||||
|
{
|
||||||
|
title: "Issue with your subscribed channel.",
|
||||||
|
description: `There is likely an issue with permissions. Please check that I can send messages in <#${channel.id}>\nYour subscription has been removed, and you will need to resubscribe to get alerts.`,
|
||||||
|
color: 0xff0000,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: "Guild",
|
||||||
|
value: `${channel.guild.name} (${channel.guild.id})`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Channel",
|
||||||
|
value: `${channel.name} (${channel.id})`
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}).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);
|
||||||
|
}
|
||||||
|
console.log(`${colors.cyan("[INFO]")} Deleted channel ${channel.id} from database`);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
|
@ -518,6 +577,27 @@ xmpp.on("stanza", (stanza) => {
|
||||||
thisMsg.content = row.custommessage || null;
|
thisMsg.content = row.custommessage || null;
|
||||||
user.send(thisMsg).catch((err) => {
|
user.send(thisMsg).catch((err) => {
|
||||||
console.error(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) => {
|
}).catch((err) => {
|
||||||
|
@ -624,19 +704,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
|
||||||
|
@ -785,21 +865,26 @@ discord.on("interactionCreate", async (interaction) => {
|
||||||
filterEvt = interaction.options.getString("filterevt") || null;
|
filterEvt = interaction.options.getString("filterevt") || null;
|
||||||
message = interaction.options.getString("message") || null;
|
message = interaction.options.getString("message") || null;
|
||||||
if (interaction.inGuild()) {
|
if (interaction.inGuild()) {
|
||||||
db.get(`SELECT * FROM channels WHERE channelid = ? AND iemchannel = ?`, [interaction.channel.id, room], (err, row) => {
|
interaction.channel.send("Permission check").then((msg) => {
|
||||||
if (err) {
|
msg.delete();
|
||||||
console.error(err.message);
|
db.get(`SELECT * FROM channels WHERE channelid = ? AND iemchannel = ?`, [interaction.channel.id, room], (err, row) => {
|
||||||
interaction.reply({ content: "Failed to subscribe to room", ephemeral: true });
|
|
||||||
} else if (row) {
|
|
||||||
return interaction.reply({ content: `Already subscribed to \`${getWFOByRoom(room).location}\`\nIf you want to update a subscribtion, please unsubscribe and resubscribe. This will be made a command eventually.`, ephemeral: true });
|
|
||||||
}
|
|
||||||
db.run(`INSERT INTO channels (channelid, iemchannel, custommessage, filter, filterEvt, minPriority) VALUES (?, ?, ?, ? ,? ,?)`, [interaction.channel.id, room, message, filter, filterEvt, minPriority], (err) => {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
interaction.reply({ content: "Failed to subscribe to room", ephemeral: true });
|
interaction.reply({ content: "Failed to subscribe to room", ephemeral: true });
|
||||||
} else {
|
} else if (row) {
|
||||||
interaction.reply({ content: `Subscribed to \`${getWFOByRoom(room).location}\``, ephemeral: true });
|
return interaction.reply({ content: `Already subscribed to \`${getWFOByRoom(room).location}\`\nIf you want to update a subscribtion, please unsubscribe and resubscribe. This will be made a command eventually.`, ephemeral: true });
|
||||||
}
|
}
|
||||||
|
db.run(`INSERT INTO channels (channelid, iemchannel, custommessage, filter, filterEvt, minPriority) VALUES (?, ?, ?, ? ,? ,?)`, [interaction.channel.id, room, message, filter, filterEvt, minPriority], (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err.message);
|
||||||
|
interaction.reply({ content: "Failed to subscribe to room", ephemeral: true });
|
||||||
|
} else {
|
||||||
|
interaction.reply({ content: `Subscribed to \`${getWFOByRoom(room).location}\``, ephemeral: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
}).catch((err) => {
|
||||||
|
interaction.reply({ content: "Failed to subscribe to room. Bot does not have send message permissions here!", ephemeral: true });
|
||||||
});
|
});
|
||||||
} else { // We're in a DM
|
} else { // We're in a DM
|
||||||
db.get(`SELECT * FROM userAlerts WHERE userid = ? AND iemchannel = ?`, [interaction.user.id, room], (err, row) => {
|
db.get(`SELECT * FROM userAlerts WHERE userid = ? AND iemchannel = ?`, [interaction.user.id, room], (err, row) => {
|
||||||
|
@ -1270,18 +1355,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))
|
||||||
|
@ -1364,7 +1449,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,
|
||||||
|
@ -1373,13 +1458,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()
|
||||||
|
@ -1505,6 +1590,8 @@ discord.on("guildCreate", async (guild) => {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}).catch((err) => {
|
||||||
|
console.log(`${colors.red("[ERROR]")} Failed to send message to user ${user.id}: ${err.message}`);
|
||||||
})
|
})
|
||||||
channel.send({
|
channel.send({
|
||||||
embeds: [
|
embeds: [
|
||||||
|
@ -1583,5 +1670,7 @@ process.on("uncaughtException", (error) => {
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Login to discord
|
// Login to discord
|
||||||
discord.login(config.discord.token);
|
discord.login(config.discord.token);
|
Loading…
Reference in a new issue