def check_if_spam(post): # if not post.body: # body = "" # test, why = FindSpam.test_post(title, body, user_name, post_site, # is_answer, body_is_summary, owner_rep, post_score) test, why = FindSpam.test_post(post) if datahandling.is_blacklisted_user( parsing.get_user_from_url(post.user_url)): test.append("blacklisted user") blacklisted_user_data = datahandling.get_blacklisted_user_data( parsing.get_user_from_url(post.user_url)) if len(blacklisted_user_data) > 1: if blacklisted_user_data[1] == "metasmoke": blacklisted_by = "the metasmoke API" else: blacklisted_by = blacklisted_user_data[1] blacklisted_post_url = blacklisted_user_data[2] if blacklisted_post_url: rel_url = blacklisted_post_url.replace("http:", "", 1) why += u"\nBlacklisted user - blacklisted for {} ({}) by {}".format( blacklisted_post_url, to_metasmoke_link(rel_url), blacklisted_by) else: why += u"\n" + u"Blacklisted user - blacklisted by {}".format( blacklisted_by) if 0 < len(test): if datahandling.has_already_been_posted(post.post_site, post.post_id, post.title) \ or datahandling.is_false_positive((post.post_id, post.post_site)) \ or should_whitelist_prevent_alert(post.user_url, test) \ or datahandling.is_ignored_post((post.post_id, post.post_site)) \ or datahandling.is_auto_ignored_post((post.post_id, post.post_site)) \ or datahandling.has_community_bumped_post(post.post_url, post.body): return False, None, "" # Don't repost. Reddit will hate you. return True, test, why return False, None, ""
def check_if_spam(post): test, why = findspam.FindSpam.test_post(post) if datahandling.is_blacklisted_user( parsing.get_user_from_url(post.user_url)): test.append("blacklisted user") blacklisted_user_data = datahandling.get_blacklisted_user_data( parsing.get_user_from_url(post.user_url)) if len(blacklisted_user_data) > 1: if blacklisted_user_data[1] == "metasmoke": blacklisted_by = "the metasmoke API" else: blacklisted_by = blacklisted_user_data[1] blacklisted_post_url = blacklisted_user_data[2] if why and why[-1] == "\n": why = why[:-1] if blacklisted_post_url: rel_url = blacklisted_post_url.replace("http:", "", 1) why += u"\nBlacklisted user - blacklisted for {} ({}) by {}".format( blacklisted_post_url, to_metasmoke_link(rel_url), blacklisted_by) else: why += u"\n" + u"Blacklisted user - blacklisted by {}".format( blacklisted_by) if test: result = None if datahandling.has_already_been_posted(post.post_site, post.post_id, post.title): result = "post has already been reported" elif datahandling.is_false_positive((post.post_id, post.post_site)): result = "post is marked as false positive" elif should_whitelist_prevent_alert(post.user_url, test): result = "user is whitelisted" elif datahandling.is_ignored_post((post.post_id, post.post_site)): result = "post is ignored" elif datahandling.is_auto_ignored_post((post.post_id, post.post_site)): result = "post is automatically ignored" elif datahandling.has_community_bumped_post(post.post_url, post.body): result = "post is bumped by Community \u2666\uFE0F" # Dirty approach if result is None: # Post not ignored return True, test, why else: return False, (test, why), result # XXX: Return an empty string for "why" if the post isn't scanned as spam # Don't touch if unsure, you'll break !!/report return False, None, ""
def check_if_spam(post): test, why = findspam.FindSpam.test_post(post) if datahandling.is_blacklisted_user(parsing.get_user_from_url(post.user_url)): test.append("blacklisted user") blacklisted_user_data = datahandling.get_blacklisted_user_data(parsing.get_user_from_url(post.user_url)) if len(blacklisted_user_data) > 1: if blacklisted_user_data[1] == "metasmoke": blacklisted_by = "the metasmoke API" else: blacklisted_by = blacklisted_user_data[1] blacklisted_post_url = blacklisted_user_data[2] if why and why[-1] == "\n": why = why[:-1] if blacklisted_post_url: rel_url = blacklisted_post_url.replace("http:", "", 1) ms_url = datahandling.resolve_ms_link(rel_url) or to_metasmoke_link(rel_url) why += "\nBlacklisted user - blacklisted for {} ({}) by {}".format( blacklisted_post_url, ms_url, blacklisted_by) else: why += "\n" + u"Blacklisted user - blacklisted by {}".format(blacklisted_by) if test: result = None if datahandling.has_already_been_posted(post.post_site, post.post_id, post.title): result = "post has already been reported" elif datahandling.is_false_positive((post.post_id, post.post_site)): result = "post is marked as false positive" elif should_whitelist_prevent_alert(post.user_url, test): result = "user is whitelisted" elif datahandling.is_ignored_post((post.post_id, post.post_site)): result = "post is ignored" elif datahandling.is_auto_ignored_post((post.post_id, post.post_site)): result = "post is automatically ignored" elif datahandling.has_community_bumped_post(post.post_url, post.body): result = "post is bumped by Community \u2666\uFE0F" # Dirty approach if result is None: # Post not ignored return True, test, why else: return False, (test, why), result return False, None, ""