Example #1
0
def test_ignore():
    mocked_client = mock_client_get_message(client.Client())

    assert is_user_currently_whitelisted("http://stackoverflow.com/users/1", "1", "stackoverflow.com") is False
    assert is_user_currently_blacklisted("http://stackoverflow.com/users/1", "1", "stackoverflow.com") is False

    assert not is_ignored_post(("1000", "stackoverflow.com"))
    event = mock_event(":1234 ignore", 1, 11540, "Charcoal HQ", 59776, u"Doorknob 冰")
    mock_previous_messages({1234: '[ [SmokeDetector](https://github.com/Charcoal-SE/SmokeDetector) ] All-caps title: [TEST](//stackoverflow.com/questions/1000) by [Community](//stackoverflow.com/users/1) on `stackoverflow.com`'})
    watcher(event, mocked_client)
    assert reply_value == "Post ignored; alerts about it will no longer be posted."
    assert is_ignored_post(("1000", "stackoverflow.com"))
    assert is_user_currently_whitelisted("http://stackoverflow.com/users/1", "1", "stackoverflow.com") is False
    assert is_user_currently_blacklisted("http://stackoverflow.com/users/1", "1", "stackoverflow.com") is False
    GlobalVars.ignored_posts = []

    assert not is_ignored_post(("1000", "stackoverflow.com"))
    event = mock_event(":1234 ignore-", 1, 11540, "Charcoal HQ", 59776, u"Doorknob 冰")
    mock_previous_messages({1234: '[ [SmokeDetector](https://github.com/Charcoal-SE/SmokeDetector) ] All-caps title: [TEST](//stackoverflow.com/questions/1000) by [Community](//stackoverflow.com/users/1) on `stackoverflow.com`'})
    watcher(event, mocked_client)
    assert reply_value == ""
    assert is_ignored_post(("1000", "stackoverflow.com"))
    assert is_user_currently_whitelisted("http://stackoverflow.com/users/1", "1", "stackoverflow.com") is False
    assert is_user_currently_blacklisted("http://stackoverflow.com/users/1", "1", "stackoverflow.com") is False
    GlobalVars.ignored_posts = []

    event = mock_event(":1234 ignore-", 1, 11540, "Charcoal HQ", 59776, u"Doorknob 冰")
    mock_previous_messages({1234: 'Not a report yay for bots'})
    watcher(event, mocked_client)
    assert reply_value == "That message is not a report."

    # cleanup
    os.remove("ignoredPosts.p")
Example #2
0
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 = "http:" + 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 {} (" \
                       u"https://m.erwaysoftware.com/posts/by-url?url={}) by {}".format(blacklisted_post_url, 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)):
            return False, None, ""  # Don't repost. Reddit will hate you.
        return True, test, why
    return False, None, ""
 def post_message_if_not_deleted(self, post_site_id, post_url, message_text,
                                 room):
     was_report_deleted = self.check_websocket_for_deletion(
         post_site_id, post_url, 300)
     if not was_report_deleted and not datahandling.is_false_positive(post_site_id[0:2]) and not \
             datahandling.is_ignored_post(post_site_id[0:2]):
         room.send_message(message_text)
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 = "http:" + 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 {} (" \
                       u"https://m.erwaysoftware.com/posts/by-url?url={}) by {}".format(blacklisted_post_url, 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)):
            return False, None, ""  # Don't repost. Reddit will hate you.
        return True, test, why
    return False, None, ""
Example #5
0
                    def callback(room=room, msg=msg_pings):
                        post = fetch_post_id_and_site_from_url(
                            report_data[0])[0:2]

                        if not datahandling.is_false_positive(
                                post) and not datahandling.is_ignored_post(
                                    post):
                            _msg_queue.put((room, msg, report_data))
    def post_message_if_not_deleted(self, message_text, room, report_data):
        post_url = report_data[0]

        post_site_id = fetch_post_id_and_site_from_url(post_url)
        was_report_deleted = self.check_websocket_for_deletion(post_site_id, post_url, 300)

        if not was_report_deleted and not datahandling.is_false_positive(post_site_id[0:2]) and not \
                datahandling.is_ignored_post(post_site_id[0:2]):

            chatcommunicate._msg_queue.put((room, message_text, report_data))
Example #7
0
    def post_message_if_not_deleted(self, message_text, room, report_data):
        post_url = report_data[0]

        post_site_id = fetch_post_id_and_site_from_url(post_url)
        was_report_deleted = self.check_websocket_for_deletion(
            post_site_id, post_url, 300)

        if not was_report_deleted and not datahandling.is_false_positive(post_site_id[0:2]) and not \
                datahandling.is_ignored_post(post_site_id[0:2]):

            chatcommunicate._msg_queue.put((room, message_text, report_data))
Example #8
0
def check_if_spam(title, body, user_name, user_url, post_site, post_id, is_answer, body_is_summary):
    if not body:
        body = ""
    test = FindSpam.test_post(title, body, user_name, post_site, is_answer, body_is_summary)
    if is_blacklisted_user(get_user_from_url(user_url)):
        test.append("Blacklisted user")
    if 0 < len(test):
        if has_already_been_posted(post_site, post_id, title) or is_false_positive((post_id, post_site)) \
                or should_whitelist_prevent_alert(user_url, test) \
                or is_ignored_post((post_id, post_site)) \
                or is_auto_ignored_post((post_id, post_site)):
            return False, None  # Don't repost. Reddit will hate you.
        return True, test
    return False, None
Example #9
0
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, ""
Example #10
0
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, ""
 def _ignore(post_site_id):
     return datahandling.is_false_positive(post_site_id) or datahandling.is_ignored_post(post_site_id) or \
         datahandling.is_auto_ignored_post(post_site_id)
Example #12
0
 def post_message_if_not_deleted(self, post_site_id, message_text, room):
     was_report_deleted = self.check_websocket_for_deletion(post_site_id, 300)
     if not was_report_deleted and not is_false_positive(post_site_id[0:2]) and not is_ignored_post(post_site_id[0:2]):
         room.send_message(message_text)
                def callback(room=room, msg=msg_pings):
                    post = fetch_post_id_and_site_from_url(report_data[0])[0:2]

                    if not datahandling.is_false_positive(post) and not datahandling.is_ignored_post(post):
                        _msg_queue.put((room, msg, report_data))
 def _ignore(post_site_id):
     return datahandling.is_false_positive(post_site_id) or datahandling.is_ignored_post(post_site_id) or \
         datahandling.is_auto_ignored_post(post_site_id)