forked from ChrisChrome/weather-bot
Compare commits
19 commits
debug-10-2
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
d2df2a48ba | ||
|
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",
|
||||
"zdcchat@conference.weather.im",
|
||||
"znychat@conference.weather.im"
|
||||
|
||||
|
||||
]
|
|
@ -1345,7 +1345,7 @@
|
|||
},
|
||||
"WSW": {
|
||||
"text": "Winter Storm Warning",
|
||||
"priority": 5
|
||||
"priority": 4
|
||||
},
|
||||
"WWA": {
|
||||
"priority": 1,
|
||||
|
@ -1522,6 +1522,9 @@
|
|||
"REP": {
|
||||
"text": "RECCO Observations (tropical cyclone)",
|
||||
"priority": 3
|
||||
},
|
||||
"PIR": {
|
||||
"text": "Pilot Reports",
|
||||
"priority": 1
|
||||
}
|
||||
|
||||
}
|
||||
|
|
66
index.js
66
index.js
|
@ -21,6 +21,7 @@ satMessages = {};
|
|||
|
||||
// Setup Discord
|
||||
const discord = new Discord.Client({
|
||||
|
||||
intents: [
|
||||
"Guilds",
|
||||
"GuildVoiceStates",
|
||||
|
@ -35,7 +36,6 @@ const rest = new REST({
|
|||
version: '10'
|
||||
}).setToken(config.discord.token);
|
||||
|
||||
|
||||
// Setup SQlite DB
|
||||
const db = new sqlite3.Database("channels.db", (err) => {
|
||||
if (err) {
|
||||
|
@ -360,6 +360,16 @@ xmpp.on("stanza", (stanza) => {
|
|||
evt = { name: "Unknown", priority: 3 }
|
||||
console.log(`${colors.red("[ERROR]")} Unknown event type: ${product_id.pil.substring(0, 3)}. Fix me`);
|
||||
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);
|
||||
|
@ -447,7 +457,7 @@ xmpp.on("stanza", (stanza) => {
|
|||
console.log(`${colors.red("[ERROR]")} ${err.message}`);
|
||||
}
|
||||
if (!rows) return; // No channels to alert
|
||||
rows.forEach((row) => {
|
||||
rows.forEach(async (row) => {
|
||||
// Get Filters as arrays
|
||||
if (!row.filterEvt) row.filterEvt = "";
|
||||
if (!row.filter) row.filter = "";
|
||||
|
@ -473,6 +483,53 @@ xmpp.on("stanza", (stanza) => {
|
|||
console.error(err);
|
||||
}).then((msg) => {
|
||||
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(() => {
|
||||
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) => {
|
||||
|
@ -785,6 +842,8 @@ discord.on("interactionCreate", async (interaction) => {
|
|||
filterEvt = interaction.options.getString("filterevt") || null;
|
||||
message = interaction.options.getString("message") || null;
|
||||
if (interaction.inGuild()) {
|
||||
interaction.channel.send("Permission check").then((msg) => {
|
||||
msg.delete();
|
||||
db.get(`SELECT * FROM channels WHERE channelid = ? AND iemchannel = ?`, [interaction.channel.id, room], (err, row) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
|
@ -801,6 +860,9 @@ discord.on("interactionCreate", async (interaction) => {
|
|||
}
|
||||
});
|
||||
});
|
||||
}).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
|
||||
db.get(`SELECT * FROM userAlerts WHERE userid = ? AND iemchannel = ?`, [interaction.user.id, room], (err, row) => {
|
||||
if (err) {
|
||||
|
|
Loading…
Reference in a new issue