Skip to content

Commit

Permalink
Added option for cross-subreddit dup. check
Browse files Browse the repository at this point in the history
  • Loading branch information
Rabenherz112 committed Jan 20, 2023
1 parent f227cd3 commit c15624f
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions functions/util_checkReddit.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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;
}
}
}
}
Expand All @@ -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) {
Expand Down

0 comments on commit c15624f

Please sign in to comment.