diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 5f2ac5f..f2abc4c 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -8,7 +8,7 @@ from utils import settings from utils.ai_methods import sort_by_similarity from utils.console import print_step, print_substep from utils.posttextparser import posttextparser -from utils.subreddit import get_subreddit_undone +from utils.subreddit import get_subreddit_undone, _contains_blocked_words from utils.videos import check_done from utils.voice import sanitize_text @@ -134,6 +134,8 @@ def get_subreddit_threads(POST_ID: str): if top_level_comment.body in ["[removed]", "[deleted]"]: continue # # see https://github.com/JasonLovesDoggo/RedditVideoMakerBot/issues/78 + if _contains_blocked_words(top_level_comment.body): + continue if not top_level_comment.stickied: sanitised = sanitize_text(top_level_comment.body) if not sanitised or sanitised == " ": diff --git a/utils/.config.template.toml b/utils/.config.template.toml index 9185a29..9b13657 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -14,6 +14,7 @@ max_comment_length = { default = 500, optional = false, nmin = 10, nmax = 10000, 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" } 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'] } 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" } +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" } [ai] 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"} diff --git a/utils/subreddit.py b/utils/subreddit.py index 403b6d3..6eb68a8 100644 --- a/utils/subreddit.py +++ b/utils/subreddit.py @@ -6,6 +6,16 @@ from utils.ai_methods import sort_by_similarity from utils.console import print_substep +def _contains_blocked_words(text: str) -> bool: + """Returns True if the text contains any blocked words from config.""" + blocked_raw = settings.config["reddit"]["thread"].get("blocked_words", "") + if not blocked_raw: + return False + blocked = [w.strip().lower() for w in blocked_raw.split(",") if w.strip()] + text_lower = text.lower() + return any(word in text_lower for word in blocked) + + def get_subreddit_undone(submissions: list, subreddit, times_checked=0, similarity_scores=None): """_summary_ @@ -42,6 +52,9 @@ def get_subreddit_undone(submissions: list, subreddit, times_checked=0, similari if submission.stickied: print_substep("This post was pinned by moderators. Skipping...") continue + if _contains_blocked_words(submission.title + " " + (submission.selftext or "")): + print_substep("Post contains a blocked word. Skipping...") + continue if ( submission.num_comments <= int(settings.config["reddit"]["thread"]["min_comments"]) and not settings.config["settings"]["storymode"]