From 486a59715d50a894cd9813dab30f8802fd86ee84 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Mon, 10 Jul 2023 19:46:30 -0400 Subject: [PATCH] vastly improved error handling --- modules/dbfn.js | 2 +- modules/functions.js | 29 ++++++++++++++--------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/modules/dbfn.js b/modules/dbfn.js index 4d127ea..ae900ce 100755 --- a/modules/dbfn.js +++ b/modules/dbfn.js @@ -117,7 +117,7 @@ module.exports = { .setCompareMessage(row.compare_channel_id, row.compare_message_id) ); } - console.log(res.length + " // " + guildInfos.length); + // console.log(res.length + " // " + guildInfos.length); db.end(); resolve(guildInfos); diff --git a/modules/functions.js b/modules/functions.js index a54b446..6dcb693 100755 --- a/modules/functions.js +++ b/modules/functions.js @@ -879,13 +879,12 @@ const functions = { // if (isDev) console.log("Set up a collector in " + guildInfo.guildId); collector.on('collect', message => { // 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" 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; } 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; } // 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; // 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)) { - 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)) { - 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)); }); }).catch(err => { - console.error(err); + console.error(`[${err.code}]: ${err.message}`); }); }, async sendFruitReminder(guildInfo, message, channelId, guild) { @@ -1067,7 +1066,7 @@ const functions = { await m.delete().catch(e => console.error(e)); }); }).catch(err => { - console.error(err); + console.error(`[${err.code}]: ${err.message}`); }); }, async setupCollectors(client) { @@ -1084,19 +1083,19 @@ const functions = { const collector = channel.createMessageCollector({ filter }); collector.on('collect', message => { 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; } 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; } if (message.embeds == undefined) return; if (message.embeds.length == 0) return; guildInfo = client.guildInfos.get(guild.id); 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)) { - 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); collector.on('collect', message => { 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; } 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; } if (message.embeds == undefined) return; if (message.embeds.length == 0) return; 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)) { - 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 {