From 60c6860089b40574a19efd1dd9c54b7baac1d53d Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Fri, 17 May 2024 13:00:56 -0600 Subject: [PATCH] First attempt at auto-purging database --- index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/index.js b/index.js index 92ce934..ddb0ed3 100644 --- a/index.js +++ b/index.js @@ -763,6 +763,25 @@ discord.on('ready', async () => { process.exit(1); } }, 10000) + + // Check all channels in DB, fetch them, if they dont exist, delete all subscriptions + db.all(`SELECT channelid FROM channels`, (err, rows) => { + if (err) { + console.error(err.message); + } + rows.forEach((row) => { + const channel = discord.channels.cache.get(row.channelid); + if (!channel) { + // Delete the channel from the database and return + return db.run(`DELETE FROM channels WHERE channelid = ?`, [row.channelid], (err) => { + if (err) { + console.error(err.message); + } + console.log(`${colors.cyan("[INFO]")} Deleted channel ${row.channelid} from database`); + }); + }; + }); + }); }); discord.on("interactionCreate", async (interaction) => {