From 08b965d13ef5887790782355be84e5c94d1f5eec Mon Sep 17 00:00:00 2001 From: Rabenherz112 Date: Tue, 27 Dec 2022 13:58:56 +0100 Subject: [PATCH 1/2] Reworked Duplicate Dectection --- functions/util_checkReddit.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/functions/util_checkReddit.js b/functions/util_checkReddit.js index bc5432c..26981dd 100644 --- a/functions/util_checkReddit.js +++ b/functions/util_checkReddit.js @@ -93,7 +93,7 @@ async function getPostsData(allPosts) { } } // Check if postDataAuthor is a blacklistedUsers - for(let buser of blacklistedUsers) { + for (let buser of blacklistedUsers) { if (postDataAuthor.toLowerCase() == (buser)) { blacklisted = true; break; @@ -102,16 +102,22 @@ async function getPostsData(allPosts) { if (blacklisted) { continue; } - // Put the 3 latest Post Titles into the subreddit DB - await client.db.push(`${post.data.subreddit}.latestPosts`, postDataTitel.toLowerCase()); + // Check if Post is a duplicate let latestPosts = await client.db.get(`${post.data.subreddit}.latestPosts`); - if (latestPosts.length > 3) { - await client.db.shift(`${post.data.subreddit}.latestPosts`); + if (latestPosts != null) { + for (let i = latestPosts.length; i >= 0; i--) { + if (latestPosts[i] == postDataTitel.toLowerCase()) { + console.log(`[REDDIT] Found ${postDataTitel} at ${new Date().toLocaleString()}, however it is a duplicate. Skipping...`); + continue; + } + } } - // Check if current Post Data Title is already in the DB - latestPosts = await client.db.get(`${post.data.subreddit}.latestPost`); - if (latestPosts.includes(postDataTitel.toLowerCase())) { - continue; + // Put the latest Post Titles into the subreddit DB + await client.db.push(`${post.data.subreddit}.latestPosts`, postDataTitel.toLowerCase()); + latestPosts = await client.db.get(`${post.data.subreddit}.latestPosts`); + if (latestPosts.length > 12) { + // Remove the oldest Post Title from the subreddit DB + await client.db.pull(`${post.data.subreddit}.latestPosts`, latestPosts[0]); } // Check for Launcher let postDataLauncher = post.data.title.match(/^\[([a-zA-Z0-9 \.]+)(?:[\/, ]*[a-zA-Z0-9\. ]*)*\]+.*$/mi); From 6d00208fef8eddec5a4b530583430ea17971bd14 Mon Sep 17 00:00:00 2001 From: Rabenherz112 Date: Tue, 27 Dec 2022 13:59:16 +0100 Subject: [PATCH 2/2] Upgraded to Version 1.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9287fdd..5b922f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord-bot-free-games-finder", - "version": "1.0.1", + "version": "1.1.0", "description": "Find your free Games and let them send you to Discord", "main": "index.js", "scripts": {