Skip to content

Commit

Permalink
Merge pull request #24 from Rabenherz112/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Rabenherz112 authored Dec 27, 2022
2 parents 1dfe2c8 + fa4600d commit 90c5ee5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions functions/util_checkReddit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 90c5ee5

Please sign in to comment.