vastly improved error handling

This commit is contained in:
Skylar Grant 2023-07-10 19:46:30 -04:00
parent 25859d364d
commit 486a59715d
2 changed files with 15 additions and 16 deletions

View File

@ -117,7 +117,7 @@ module.exports = {
.setCompareMessage(row.compare_channel_id, row.compare_message_id) .setCompareMessage(row.compare_channel_id, row.compare_message_id)
); );
} }
console.log(res.length + " // " + guildInfos.length); // console.log(res.length + " // " + guildInfos.length);
db.end(); db.end();
resolve(guildInfos); resolve(guildInfos);

View File

@ -879,13 +879,12 @@ const functions = {
// if (isDev) console.log("Set up a collector in " + guildInfo.guildId); // if (isDev) console.log("Set up a collector in " + guildInfo.guildId);
collector.on('collect', message => { collector.on('collect', message => {
// if (isDev) console.log("Collected a message in " + message.guild.id); // if (isDev) console.log("Collected a message in " + message.guild.id);
if (message.guild.id === "1113951253949599844") console.log(JSON.stringify(message));
// Check for manual relay use with "water ping" and "fruit ping" // Check for manual relay use with "water ping" and "fruit ping"
if (message.content.toLowerCase().includes("water ping")) { if (message.content.toLowerCase().includes("water ping")) {
functions.sendWaterReminder(guildInfo, guildInfo.waterMessage, guildInfo.reminderChannelId, guild); functions.sendWaterReminder(guildInfo, guildInfo.waterMessage, guildInfo.reminderChannelId, guild).catch(e => console.error(`[${e.code}]: ${e.message}`));
return; return;
} else if (message.content.toLowerCase().includes("fruit ping")) { } else if (message.content.toLowerCase().includes("fruit ping")) {
functions.sendFruitReminder(guildInfo, guildInfo.fruitMessage, guildInfo.reminderChannelId, guild); functions.sendFruitReminder(guildInfo, guildInfo.fruitMessage, guildInfo.reminderChannelId, guild).catch(e => console.error(`[${e.code}]: ${e.message}`));
return; return;
} }
// If the message doesn't contain an embed, we can ignore it // If the message doesn't contain an embed, we can ignore it
@ -895,9 +894,9 @@ const functions = {
if (message.embeds[0].data.description == undefined) return; if (message.embeds[0].data.description == undefined) return;
// Check the description field of the embed to determine if it matches Grow A Tree's notification texts // Check the description field of the embed to determine if it matches Grow A Tree's notification texts
if (message.embeds[0].data.description.includes(strings.notifications.water)) { if (message.embeds[0].data.description.includes(strings.notifications.water)) {
functions.sendWaterReminder(guildInfo, guildInfo.waterMessage, guildInfo.reminderChannelId, guild); functions.sendWaterReminder(guildInfo, guildInfo.waterMessage, guildInfo.reminderChannelId, guild).catch(e => console.error(`[${e.code}]: ${e.message}`));
} else if (message.embeds[0].data.description.includes(strings.notifications.fruit)) { } else if (message.embeds[0].data.description.includes(strings.notifications.fruit)) {
functions.sendFruitReminder(guildInfo, guildInfo.fruitMessage, guildInfo.reminderChannelId, guild); functions.sendFruitReminder(guildInfo, guildInfo.fruitMessage, guildInfo.reminderChannelId, guild).catch(e => console.error(`[${e.code}]: ${e.message}`));
} }
}); });
} }
@ -1054,7 +1053,7 @@ const functions = {
await m.delete().catch(e => console.error(e)); await m.delete().catch(e => console.error(e));
}); });
}).catch(err => { }).catch(err => {
console.error(err); console.error(`[${err.code}]: ${err.message}`);
}); });
}, },
async sendFruitReminder(guildInfo, message, channelId, guild) { async sendFruitReminder(guildInfo, message, channelId, guild) {
@ -1067,7 +1066,7 @@ const functions = {
await m.delete().catch(e => console.error(e)); await m.delete().catch(e => console.error(e));
}); });
}).catch(err => { }).catch(err => {
console.error(err); console.error(`[${err.code}]: ${err.message}`);
}); });
}, },
async setupCollectors(client) { async setupCollectors(client) {
@ -1084,19 +1083,19 @@ const functions = {
const collector = channel.createMessageCollector({ filter }); const collector = channel.createMessageCollector({ filter });
collector.on('collect', message => { collector.on('collect', message => {
if (message.content.toLowerCase().includes("water ping")) { if (message.content.toLowerCase().includes("water ping")) {
this.sendWaterReminder(guildInfo, guildInfo.waterMessage, guildInfo.reminderChannelId, guild); this.sendWaterReminder(guildInfo, guildInfo.waterMessage, guildInfo.reminderChannelId, guild).catch(e => console.error(`[${e.code}]: ${e.message}`));
return; return;
} else if (message.content.toLowerCase().includes("fruit ping")) { } else if (message.content.toLowerCase().includes("fruit ping")) {
this.sendFruitReminder(guildInfo, guildInfo.fruitMessage, guildInfo.reminderChannelId, guild); this.sendFruitReminder(guildInfo, guildInfo.fruitMessage, guildInfo.reminderChannelId, guild).catch(e => console.error(`[${e.code}]: ${e.message}`));
return; return;
} }
if (message.embeds == undefined) return; if (message.embeds == undefined) return;
if (message.embeds.length == 0) return; if (message.embeds.length == 0) return;
guildInfo = client.guildInfos.get(guild.id); guildInfo = client.guildInfos.get(guild.id);
if (message.embeds[0].data.description.includes(strings.notifications.water)) { if (message.embeds[0].data.description.includes(strings.notifications.water)) {
this.sendWaterReminder(guildInfo, guildInfo.waterMessage, guildInfo.reminderChannelId, guild); this.sendWaterReminder(guildInfo, guildInfo.waterMessage, guildInfo.reminderChannelId, guild).catch(e => console.error(`[${e.code}]: ${e.message}`));
} else if (message.embeds[0].data.description.includes(strings.notifications.fruit)) { } else if (message.embeds[0].data.description.includes(strings.notifications.fruit)) {
this.sendFruitReminder(guildInfo, guildInfo.fruitMessage, guildInfo.reminderChannelId, guild); this.sendFruitReminder(guildInfo, guildInfo.fruitMessage, guildInfo.reminderChannelId, guild).catch(e => console.error(`[${e.code}]: ${e.message}`));
} }
}); });
} }
@ -1114,18 +1113,18 @@ const functions = {
collectors.push(collector); collectors.push(collector);
collector.on('collect', message => { collector.on('collect', message => {
if (message.content.toLowerCase().includes("water ping")) { if (message.content.toLowerCase().includes("water ping")) {
this.sendWaterReminder(guildInfo, guildInfo.waterMessage, guildInfo.reminderChannelId, guild); this.sendWaterReminder(guildInfo, guildInfo.waterMessage, guildInfo.reminderChannelId, guild).catch(e => console.error(`[${e.code}]: ${e.message}`));
return; return;
} else if (message.content.toLowerCase().includes("fruit ping")) { } else if (message.content.toLowerCase().includes("fruit ping")) {
this.sendFruitReminder(guildInfo, guildInfo.fruitMessage, guildInfo.reminderChannelId, guild); this.sendFruitReminder(guildInfo, guildInfo.fruitMessage, guildInfo.reminderChannelId, guild).catch(e => console.error(`[${e.code}]: ${e.message}`));
return; return;
} }
if (message.embeds == undefined) return; if (message.embeds == undefined) return;
if (message.embeds.length == 0) return; if (message.embeds.length == 0) return;
if (message.embeds[0].data.description.includes(strings.notifications.water)) { if (message.embeds[0].data.description.includes(strings.notifications.water)) {
this.sendWaterReminder(guildInfo, guildInfo.waterMessage, guildInfo.reminderChannelId, guild); this.sendWaterReminder(guildInfo, guildInfo.waterMessage, guildInfo.reminderChannelId, guild).catch(e => console.error(`[${e.code}]: ${e.message}`));
} else if (message.embeds[0].data.description.includes(strings.notifications.fruit)) { } else if (message.embeds[0].data.description.includes(strings.notifications.fruit)) {
this.sendFruitReminder(guildInfo, guildInfo.fruitMessage, guildInfo.reminderChannelId, guild); this.sendFruitReminder(guildInfo, guildInfo.fruitMessage, guildInfo.reminderChannelId, guild).catch(e => console.error(`[${e.code}]: ${e.message}`));
} }
}); });
} else { } else {