Skip to content

Commit 569f250

Browse files
authored
Merge pull request #2473 from elebumm/blocked-words
Add blocking words
2 parents 902ff00 + 1fe6aea commit 569f250

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

reddit/subreddit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from utils.ai_methods import sort_by_similarity
99
from utils.console import print_step, print_substep
1010
from utils.posttextparser import posttextparser
11-
from utils.subreddit import get_subreddit_undone
11+
from utils.subreddit import _contains_blocked_words, get_subreddit_undone
1212
from utils.videos import check_done
1313
from utils.voice import sanitize_text
1414

@@ -134,6 +134,8 @@ def get_subreddit_threads(POST_ID: str):
134134

135135
if top_level_comment.body in ["[removed]", "[deleted]"]:
136136
continue # # see https://github.com/JasonLovesDoggo/RedditVideoMakerBot/issues/78
137+
if _contains_blocked_words(top_level_comment.body):
138+
continue
137139
if not top_level_comment.stickied:
138140
sanitised = sanitize_text(top_level_comment.body)
139141
if not sanitised or sanitised == " ":

utils/.config.template.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ max_comment_length = { default = 500, optional = false, nmin = 10, nmax = 10000,
1414
min_comment_length = { default = 1, optional = true, nmin = 0, nmax = 10000, type = "int", explanation = "min_comment_length number of characters a comment can have. default is 0", example = 50, oob_error = "the max comment length should be between 1 and 100" }
1515
post_lang = { default = "", optional = true, explanation = "The language you would like to translate to.", example = "es-cr", options = ['','af', 'ak', 'am', 'ar', 'as', 'ay', 'az', 'be', 'bg', 'bho', 'bm', 'bn', 'bs', 'ca', 'ceb', 'ckb', 'co', 'cs', 'cy', 'da', 'de', 'doi', 'dv', 'ee', 'el', 'en', 'en-US', 'eo', 'es', 'et', 'eu', 'fa', 'fi', 'fr', 'fy', 'ga', 'gd', 'gl', 'gn', 'gom', 'gu', 'ha', 'haw', 'hi', 'hmn', 'hr', 'ht', 'hu', 'hy', 'id', 'ig', 'ilo', 'is', 'it', 'iw', 'ja', 'jw', 'ka', 'kk', 'km', 'kn', 'ko', 'kri', 'ku', 'ky', 'la', 'lb', 'lg', 'ln', 'lo', 'lt', 'lus', 'lv', 'mai', 'mg', 'mi', 'mk', 'ml', 'mn', 'mni-Mtei', 'mr', 'ms', 'mt', 'my', 'ne', 'nl', 'no', 'nso', 'ny', 'om', 'or', 'pa', 'pl', 'ps', 'pt', 'qu', 'ro', 'ru', 'rw', 'sa', 'sd', 'si', 'sk', 'sl', 'sm', 'sn', 'so', 'sq', 'sr', 'st', 'su', 'sv', 'sw', 'ta', 'te', 'tg', 'th', 'ti', 'tk', 'tl', 'tr', 'ts', 'tt', 'ug', 'uk', 'ur', 'uz', 'vi', 'xh', 'yi', 'yo', 'zh-CN', 'zh-TW', 'zu'] }
1616
min_comments = { default = 20, optional = false, nmin = 10, type = "int", explanation = "The minimum number of comments a post should have to be included. default is 20", example = 29, oob_error = "the minimum number of comments should be between 15 and 999999" }
17+
blocked_words = { optional = true, default = "", type = "str", explanation = "Comma-separated list of words/phrases. Posts and comments containing any of these will be skipped.", example = "nsfw, spoiler, politics" }
1718

1819
[ai]
1920
ai_similarity_enabled = {optional = true, option = [true, false], default = false, type = "bool", explanation = "Threads read from Reddit are sorted based on their similarity to the keywords given below"}

utils/subreddit.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
from utils.console import print_substep
77

88

9+
def _contains_blocked_words(text: str) -> bool:
10+
"""Returns True if the text contains any blocked words from config."""
11+
blocked_raw = settings.config["reddit"]["thread"].get("blocked_words", "")
12+
if not blocked_raw:
13+
return False
14+
blocked = [w.strip().lower() for w in blocked_raw.split(",") if w.strip()]
15+
text_lower = text.lower()
16+
return any(word in text_lower for word in blocked)
17+
18+
919
def get_subreddit_undone(submissions: list, subreddit, times_checked=0, similarity_scores=None):
1020
"""_summary_
1121
@@ -42,6 +52,9 @@ def get_subreddit_undone(submissions: list, subreddit, times_checked=0, similari
4252
if submission.stickied:
4353
print_substep("This post was pinned by moderators. Skipping...")
4454
continue
55+
if _contains_blocked_words(submission.title + " " + (submission.selftext or "")):
56+
print_substep("Post contains a blocked word. Skipping...")
57+
continue
4558
if (
4659
submission.num_comments <= int(settings.config["reddit"]["thread"]["min_comments"])
4760
and not settings.config["settings"]["storymode"]

0 commit comments

Comments
 (0)