From c15624f0b148c6ede7c812cdb58e1992d1eb6923 Mon Sep 17 00:00:00 2001 From: Rabenherz112 Date: Fri, 20 Jan 2023 17:34:16 +0100 Subject: [PATCH] Added option for cross-subreddit dup. check --- functions/util_checkReddit.js | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/functions/util_checkReddit.js b/functions/util_checkReddit.js index cf63a1c..76295a7 100644 --- a/functions/util_checkReddit.js +++ b/functions/util_checkReddit.js @@ -1,4 +1,4 @@ -const { subreddits, lookuptime, limit, Embed, colors, blacklistedURLs, blacklistedUsers } = require("../config.json"); +const { subreddits, lookuptime, limit, Embed, colors, blacklistedURLs, blacklistedUsers, dublicateCheck, dublicateCheckCrossSubreddits } = require("../config.json"); const { EmbedBuilder } = require("discord.js"); const { ChannelType } = require("discord-api-types/v10"); const { decode } = require("html-entities"); @@ -102,12 +102,25 @@ async function getPostsData(allPosts) { continue; } // Check if Post is a duplicate - let latestPosts = await client.db.get(`${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; + if (dublicateCheck == true && dublicateCheckCrossSubreddits == false) { + let latestPosts = await client.db.get(`${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; + } + } + } + } + if (dublicateCheck == true && dublicateCheckCrossSubreddits == true) { + let latestPosts = await client.db.get(`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; + } } } } @@ -118,6 +131,12 @@ async function getPostsData(allPosts) { // Remove the oldest Post Title from the subreddit DB await client.db.pull(`${post.data.subreddit}.latestPosts`, latestPosts[0]); } + await client.db.push(`latestPosts`, postDataTitel.toLowerCase()); + latestPosts = await client.db.get(`latestPosts`); + if (latestPosts.length > 12) { + // Remove the oldest Post Title from the subreddit DB + await client.db.pull(`latestPosts`, latestPosts[0]); + } // Check for Launcher let postDataLauncher = post.data.title.match(/^\[([a-zA-Z0-9 \.]+)(?:[\/, ]*[a-zA-Z0-9\. ]*)*\]+.*$/mi); if (postDataLauncher != null && typeof postDataLauncher === 'object' && postDataLauncher.length > 1) {