Ejemplo n.º 1
0
def handle_spam(post, reasons, why):
    datahandling.append_to_latest_questions(post.post_site, post.post_id, post.title if not post.is_answer else "")

    if len(reasons) == 1 and ("all-caps title" in reasons or
                              "repeating characters in title" in reasons or
                              "repeating characters in body" in reasons or
                              "repeating characters in answer" in reasons or
                              "repeating words in title" in reasons or
                              "repeating words in body" in reasons or
                              "repeating words in answer" in reasons):
        datahandling.add_auto_ignored_post((post.post_id, post.post_site, datetime.utcnow()))

    if why is not None and why != "":
        datahandling.add_why(post.post_site, post.post_id, why)

    if post.is_answer and post.post_id is not None and post.post_id != "":
        datahandling.add_post_site_id_link((post.post_id, post.post_site, "answer"), post.parent.post_id)

    try:
        post_url = parsing.to_protocol_relative(parsing.url_to_shortlink(post.post_url))
        poster_url = parsing.to_protocol_relative(parsing.user_url_to_shortlink(post.user_url))
        if not post.user_name.strip() or (not poster_url or poster_url.strip() == ""):
            username = ""
        else:
            username = post.user_name.strip()

        Tasks.do(metasmoke.Metasmoke.send_stats_on_post,
                 post.title_ignore_type, post_url, reasons, post.body, username,
                 post.user_link, why, post.owner_rep, post.post_score,
                 post.up_vote_count, post.down_vote_count)

        offensive_mask = 'offensive title detected' in reasons
        message = build_message(post, reasons)
        if offensive_mask:
            post.title = "(potentially offensive title -- see MS for details)"
            clean_message = build_message(post, reasons)

        log('debug', GlobalVars.parser.unescape(message).encode('ascii', errors='replace'))
        GlobalVars.deletion_watcher.subscribe(post_url)

        without_roles = tuple(["no-" + reason for reason in reasons]) + ("site-no-" + post.post_site,)

        if set(reasons) - GlobalVars.experimental_reasons == set() and \
                not why.startswith("Post manually "):
            chatcommunicate.tell_rooms(message, ("experimental-all-sites", "experimental-site-" + post.post_site),
                                       without_roles, notify_site=post.post_site, report_data=(post_url, poster_url))
        else:
            if offensive_mask:
                chatcommunicate.tell_rooms(message, ("all-sites", "site-" + post.post_site),
                                           without_roles + ("offensive-mask",), notify_site=post.post_site,
                                           report_data=(post_url, poster_url))
                chatcommunicate.tell_rooms(clean_message, ("all-sites", "site-" + post.post_site),
                                           without_roles + ("no-offensive-mask",), notify_site=post.post_site,
                                           report_data=(post_url, poster_url))
            else:
                chatcommunicate.tell_rooms(message, ("all-sites", "site-" + post.post_site),
                                           without_roles, notify_site=post.post_site,
                                           report_data=(post_url, poster_url))
    except Exception as e:
        excepthook.uncaught_exception(*sys.exc_info())
Ejemplo n.º 2
0
def handle_spam(title, body, poster, site, post_url, poster_url, post_id, reasons, is_answer, why=""):
    post_url = to_protocol_relative(url_to_shortlink(post_url))
    poster_url = to_protocol_relative(poster_url)
    reason = ", ".join(reasons).capitalize()
    if "Url" in reason:
        reason = reason.replace("Url", "URL")
    append_to_latest_questions(site, post_id, title if not is_answer else "")
    if len(reasons) == 1 and ("All-caps title" in reasons or
                              "Repeating characters in title" in reasons or
                              "Repeating characters in body" in reasons or
                              "Repeating characters in answer" in reasons or
                              "Repeating words in title" in reasons or
                              "Repeating words in body" in reasons or
                              "Repeating words in answer" in reasons):
        add_auto_ignored_post((post_id, site, datetime.now()))
    if why is not None and why != "":
        add_why(site, post_id, why)
    try:
        owner = poster_url
        users_file = open("users.txt", "a")
        users_file.write(site + " " + owner + " " + title + " " + post_url + "\n")
        users_file.close()
    except Exception as e:
        print e
    try:
        title = escape_special_chars_in_title(title)

        if not poster.strip():
            s = u"[ [SmokeDetector](https://github.com/Charcoal-SE/SmokeDetector) ] {}: [{}]({}) by a deleted user on `{}`" \
                .format(reason, title.strip(), post_url, site)
            username = ""
            user_link = ""
        else:
            s = u"[ [SmokeDetector](https://github.com/Charcoal-SE/SmokeDetector) ] {}: [{}]({}) by [{}]({}) on `{}`" \
                .format(reason, title.strip(), post_url, poster.strip(), poster_url, site)
            username = poster.strip()
            user_link = poster_url

        t_metasmoke = Thread(target=Metasmoke.send_stats_on_post,
                             args=(title, post_url, reason.split(", "), body, username, user_link))
        t_metasmoke.start()

        print GlobalVars.parser.unescape(s).encode('ascii', errors='replace')
        if time.time() >= GlobalVars.blockedTime:
            append_to_latest_questions(site, post_id, title)

            if reason not in GlobalVars.experimental_reasons:
                GlobalVars.charcoal_hq.send_message(s)
                GlobalVars.tavern_on_the_meta.send_message(s)
                if site == "stackoverflow.com":
                    GlobalVars.socvr.send_message(s)

            for specialroom in GlobalVars.specialrooms:
                sites = specialroom["sites"]
                if site in sites and reason not in specialroom["unwantedReasons"]:
                    specialroom["room"].send_message(s)
    except:
        print "NOP"
Ejemplo n.º 3
0
def handle_spam(title,
                poster,
                site,
                post_url,
                poster_url,
                post_id,
                reasons,
                is_answer,
                why=""):
    post_url = to_protocol_relative(url_to_shortlink(post_url))
    poster_url = to_protocol_relative(poster_url)
    reason = ", ".join(reasons).capitalize()
    if "Url" in reason:
        reason = reason.replace("Url", "URL")
    append_to_latest_questions(site, post_id, title if not is_answer else "")
    if len(reasons) == 1 and ("All-caps title" in reasons
                              or "Repeating characters in title" in reasons
                              or "Repeating characters in body" in reasons
                              or "Repeating characters in answer" in reasons
                              or "Repeating words in title" in reasons
                              or "Repeating words in body" in reasons
                              or "Repeating words in answer" in reasons):
        add_auto_ignored_post((post_id, site, datetime.now()))
    if why is not None and why != "":
        add_why(site, post_id, why)
    try:
        owner = poster_url
        users_file = open("users.txt", "a")
        users_file.write(site + " " + owner + " " + title + " " + post_url +
                         "\n")
        users_file.close()
    except Exception as e:
        print e
    try:
        title = escape_special_chars_in_title(title)
        if not poster.strip():
            s = "[ [SmokeDetector](https://github.com/Charcoal-SE/SmokeDetector) ] %s: [%s](%s) by a deleted user on `%s`" % \
                (reason, title.strip(), post_url, site)
        else:
            s = "[ [SmokeDetector](https://github.com/Charcoal-SE/SmokeDetector) ] %s: [%s](%s) by [%s](%s) on `%s`" % \
                (reason, title.strip(), post_url, poster.strip(), poster_url, site)
        print GlobalVars.parser.unescape(s).encode('ascii', errors='replace')
        if time.time() >= GlobalVars.blockedTime:
            append_to_latest_questions(site, post_id, title)

            if reason not in GlobalVars.experimental_reasons:
                GlobalVars.charcoal_hq.send_message(s)
                GlobalVars.tavern_on_the_meta.send_message(s)
                if site == "stackoverflow.com":
                    GlobalVars.socvr.send_message(s)

            for specialroom in GlobalVars.specialrooms:
                sites = specialroom["sites"]
                if site in sites and reason not in specialroom[
                        "unwantedReasons"]:
                    specialroom["room"].send_message(s)
    except:
        print "NOP"
Ejemplo n.º 4
0
    def _check_batch(saved):
        if time.time() < DeletionWatcher.next_request_time:
            time.sleep(DeletionWatcher.next_request_time - time.time())

        for site, posts in saved.items():
            ids = ";".join(post_id for post_id in posts if not DeletionWatcher._ignore((post_id, site)))
            uri = "https://api.stackexchange.com/2.2/posts/{}".format(ids)
            params = {
                'site': site,
                'key': 'IAkbitmze4B8KpacUfLqkw(('
            }
            res = requests.get(uri, params=params)
            json = res.json()

            if "items" not in json:
                log('warning',
                    'DeletionWatcher API request received no items in response (code {})'.format(res.status_code))
                log('warning', res.text)
                return

            if 'backoff' in json:
                DeletionWatcher.next_request_time = time.time() + json['backoff']

            for post in json['items']:
                if time.time() - post["creation_date"] < 7200:
                    yield to_protocol_relative(post["link"]).replace("/q/", "/questions/")
    def _check_batch(saved):
        if time.time() < DeletionWatcher.next_request_time:
            time.sleep(DeletionWatcher.next_request_time - time.time())

        for site, posts in saved.items():
            ids = ";".join(post_id for post_id in posts
                           if not DeletionWatcher._ignore((post_id, site)))
            uri = "https://api.stackexchange.com/2.2/posts/{}".format(ids)
            params = {'site': site, 'key': 'IAkbitmze4B8KpacUfLqkw(('}
            res = requests.get(uri, params=params)
            json = res.json()

            if "items" not in json:
                log(
                    'warning',
                    'DeletionWatcher API request received no items in response (code {})'
                    .format(res.status_code))
                log('warning', res.text)
                return

            if 'backoff' in json:
                DeletionWatcher.next_request_time = time.time(
                ) + json['backoff']

            for post in json['items']:
                if time.time() - post["creation_date"] < 7200:
                    yield to_protocol_relative(post["link"]).replace(
                        "/q/", "/questions/")
Ejemplo n.º 6
0
    def get_post_bodies_from_ms(post_url):
        if not GlobalVars.metasmoke_key:
            return None

        payload = {
            'key': GlobalVars.metasmoke_key,
            'filter':
            'GHOOIJGNLKHIIOIKGILKIJGHFMNKKGFJ',  # posts.id, posts.body, posts.created_at
            'urls': parsing.to_protocol_relative(post_url)
        }
        try:
            response = Metasmoke.get('/api/v2.0/posts/urls',
                                     params=payload).json()
        except AttributeError:
            return None
        except Exception as e:
            log('error', '{}: {}'.format(type(e).__name__, e))
            log_exception(*sys.exc_info())
            exception_only = ''.join(
                traceback.format_exception_only(type(e), e)).strip()
            chatcommunicate.tell_rooms_with(
                "debug",
                "{}: In getting MS post information, recovered from `{}`".
                format(GlobalVars.location, exception_only))
            return None

        return response['items']
Ejemplo n.º 7
0
    def _check_batch(saved):
        for site, posts in saved.items():
            ids = ";".join([post_id for post_id in posts if not DeletionWatcher._ignore((post_id, site))])
            uri = "https://api.stackexchange.com/2.2/posts/{}?site={}&key=IAkbitmze4B8KpacUfLqkw((".format(ids, site)

            for post in requests.get(uri).json()["items"]:
                if time.time() - post["creation_date"] < 7200:
                    yield to_protocol_relative(post["link"]).replace("/q/", "/questions/")
Ejemplo n.º 8
0
    def get_post_bodies_from_ms(post_url):
        if not GlobalVars.metasmoke_key:
            return None

        payload = {
            'key': GlobalVars.metasmoke_key,
            'filter': 'HNKHHGINKFKGIKGLGKIILMKNHHGHFOL',  # posts.body, posts.created_at, posts.tags
            'urls': parsing.to_protocol_relative(post_url)
        }
        response = requests.get(GlobalVars.metasmoke_host + '/api/v2.0/posts/urls', params=payload).json()

        return response['items']
Ejemplo n.º 9
0
    def get_post_bodies_from_ms(post_url):
        if not GlobalVars.metasmoke_key:
            return None

        payload = {
            'key': GlobalVars.metasmoke_key,
            'filter': 'HNKHHGINKFKGIKGLGKIILMKNHHGHFOL',  # posts.body, posts.created_at
            'urls': parsing.to_protocol_relative(post_url)
        }
        try:
            response = Metasmoke.get('/api/v2.0/posts/urls', params=payload).json()
        except AttributeError:
            return None

        return response['items']
Ejemplo n.º 10
0
    def get_post_bodies_from_ms(post_url):
        if not GlobalVars.metasmoke_key:
            return None

        payload = {
            'key': GlobalVars.metasmoke_key,
            'filter': 'GHOOIJGNLKHIIOIKGILKIJGHFMNKKGFJ',  # posts.id, posts.body, posts.created_at
            'urls': parsing.to_protocol_relative(post_url)
        }
        try:
            response = Metasmoke.get('/api/v2.0/posts/urls', params=payload).json()
        except AttributeError:
            return None

        return response['items']
Ejemplo n.º 11
0
    def get_post_bodies_from_ms(post_url):
        if not GlobalVars.metasmoke_key:
            return None

        payload = {
            'key': GlobalVars.metasmoke_key,
            'filter':
            'GHOOIJGNLKHIIOIKGILKIJGHFMNKKGFJ',  # posts.id, posts.body, posts.created_at
            'urls': parsing.to_protocol_relative(post_url)
        }
        try:
            response = Metasmoke.get('/api/v2.0/posts/urls',
                                     params=payload).json()
        except AttributeError:
            return None

        return response['items']
Ejemplo n.º 12
0
def test_checkpost(handle_spam):
    try:
        msg = Fake({
            "owner": {
                "name": "foo",
                "id": 1,
                "is_moderator": False
            },
            "room": {
                "id": 11540,
                "name": "Charcoal HQ",
                "_client": {
                    "host": "stackexchange.com"
                }
            },
            "_client": {
                "host": "stackexchange.com"
            },
            "id": 1337
        })

        assert chatcommands.checkpost("foo", original_msg=msg) == "That does not look like a valid post URL."
        assert chatcommands.checkpost("https://stackoverflow.com/q/1", original_msg=msg) == \
            "Cannot find data for this post in the API. It may have already been deleted."

        # This is the highest voted question on Stack Overflow
        good_post_url = "https://stackoverflow.com/q/11227809"
        post = api_get_post(good_post_url)
        assert chatcommands.checkpost(good_post_url, original_msg=msg) == \
            "Post [{0}]({1}) does not look like spam.".format(post.title, to_protocol_relative(post.post_url))

        # This post is found in Sandbox Archive, so it will remain intact and is a reliable test post
        # backup: https://meta.stackexchange.com/a/228635
        test_post_url = "https://meta.stackexchange.com/a/209772"
        assert chatcommands.checkpost(test_post_url, original_msg=msg) is None

        _, call = handle_spam.call_args_list[0]
        assert isinstance(call["post"], Post)
        assert call["why"].endswith("Manually triggered scan")

        # Strangely it doesn't work if scanned repeatedly
    finally:
        GlobalVars.latest_questions = []
Ejemplo n.º 13
0
def handle_spam(post, reasons, why):
    post_url = parsing.to_protocol_relative(parsing.url_to_shortlink(post.post_url))
    poster_url = parsing.to_protocol_relative(parsing.user_url_to_shortlink(post.user_url))
    reason = ", ".join(reasons[:5])
    if len(reasons) > 5:
        reason += ", +{} more".format(len(reasons) - 5)
    reason = reason[:1].upper() + reason[1:]  # reason is capitalised, unlike the entries of reasons list
    shortened_site = post.post_site.replace("stackexchange.com", "SE")  # site.stackexchange.com -> site.SE
    datahandling.append_to_latest_questions(post.post_site, post.post_id, post.title if not post.is_answer else "")
    if len(reasons) == 1 and ("all-caps title" in reasons or
                              "repeating characters in title" in reasons or
                              "repeating characters in body" in reasons or
                              "repeating characters in answer" in reasons or
                              "repeating words in title" in reasons or
                              "repeating words in body" in reasons or
                              "repeating words in answer" in reasons):
        datahandling.add_auto_ignored_post((post.post_id, post.post_site, datetime.now()))
    if why is not None and why != "":
        datahandling.add_why(post.post_site, post.post_id, why)
    if post.is_answer and post.post_id is not None and post.post_id is not "":
        datahandling.add_post_site_id_link((post.post_id, post.post_site, "answer"), post.parent.post_id)
    try:
        post._title = parsing.escape_special_chars_in_title(post.title)
        if post.is_answer:
            # If the post is an answer type post, the 'title' is going to be blank, so when posting the
            # message contents we need to set the post title to the *parent* title, so the message in the
            # chat is properly constructed with parent title instead. This will make things 'print'
            # in a proper way in chat messages.
            sanitized_title = regex.sub('(https?://|\n)', '', post.parent.title)
        else:
            sanitized_title = regex.sub('(https?://|\n)', '', post.title)

        sanitized_title = regex.sub(r'([\]*`])', r'\\\1', sanitized_title).replace('\n', u'\u23CE')

        prefix = u"[ [SmokeDetector](//goo.gl/eLDYqh) ]"
        if GlobalVars.metasmoke_key:
            prefix_ms = u"[ [SmokeDetector](//goo.gl/eLDYqh) | [MS](//m.erwaysoftware.com/posts/by-url?url=" + \
                        post_url + ") ]"
        else:
            prefix_ms = prefix

        if not post.user_name.strip() or (not poster_url or poster_url.strip() == ""):
            s = u" {}: [{}]({}) by a deleted user on `{}`".format(reason, sanitized_title.strip(), post_url,
                                                                  shortened_site)
            username = ""
        else:
            s = u" {}: [{}]({}) by [{}]({}) on `{}`".format(reason, sanitized_title.strip(), post_url,
                                                            post.user_name.strip(), poster_url, shortened_site)
            username = post.user_name.strip()

        Tasks.do(metasmoke.Metasmoke.send_stats_on_post,
                 post.title_ignore_type, post_url, reasons, post.body, username,
                 post.user_link, why, post.owner_rep, post.post_score,
                 post.up_vote_count, post.down_vote_count)

        log('debug', GlobalVars.parser.unescape(s).encode('ascii', errors='replace'))
        datahandling.append_to_latest_questions(post.post_site, post.post_id, post.title)

        message = prefix_ms + s
        if len(message) > 500:
            message = (prefix + s)[:500]

        without_roles = tuple("no-" + reason for reason in reasons)

        if set(reason) & GlobalVars.experimental_reasons == {}:
            chatcommunicate.tell_rooms(message, ("experimental"),
                                       without_roles, notify_site=post.post_site, report_data=(post_url, poster_url))
        else:
            chatcommunicate.tell_rooms(message, ("all", "site-" + post.post_site),
                                       without_roles, notify_site=post.post_site, report_data=(post_url, poster_url))
    except:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        excepthook.uncaught_exception(exc_type, exc_obj, exc_tb)
Ejemplo n.º 14
0
def handle_spam(post, reasons, why):
    post_url = parsing.to_protocol_relative(parsing.url_to_shortlink(post.post_url))
    poster_url = parsing.to_protocol_relative(parsing.user_url_to_shortlink(post.user_url))
    reason = ", ".join(reasons[:5])
    if len(reasons) > 5:
        reason += ", +{} more".format(len(reasons) - 5)
    reason = reason[:1].upper() + reason[1:]  # reason is capitalised, unlike the entries of reasons list
    shortened_site = post.post_site.replace("stackexchange.com", "SE")  # site.stackexchange.com -> site.SE
    datahandling.append_to_latest_questions(post.post_site, post.post_id, post.title if not post.is_answer else "")
    if len(reasons) == 1 and ("all-caps title" in reasons or
                              "repeating characters in title" in reasons or
                              "repeating characters in body" in reasons or
                              "repeating characters in answer" in reasons or
                              "repeating words in title" in reasons or
                              "repeating words in body" in reasons or
                              "repeating words in answer" in reasons):
        datahandling.add_auto_ignored_post((post.post_id, post.post_site, datetime.now()))
    if why is not None and why != "":
        datahandling.add_why(post.post_site, post.post_id, why)
    if post.is_answer and post.post_id is not None and post.post_id is not "":
        datahandling.add_post_site_id_link((post.post_id, post.post_site, "answer"), post.parent.post_id)
    try:
        post._title = parsing.escape_special_chars_in_title(post.title)
        if post.is_answer:
            # If the post is an answer type post, the 'title' is going to be blank, so when posting the
            # message contents we need to set the post title to the *parent* title, so the message in the
            # chat is properly constructed with parent title instead. This will make things 'print'
            # in a proper way in chat messages.
            sanitized_title = regex.sub('(https?://|\n)', '', post.parent.title)
        else:
            sanitized_title = regex.sub('(https?://|\n)', '', post.title)

        sanitized_title = regex.sub(r'([\]*`])', r'\\$1', sanitized_title).replace('\n', u'\u23CE')

        prefix = u"[ [SmokeDetector](//goo.gl/eLDYqh) ]"
        if GlobalVars.metasmoke_key:
            prefix_ms = u"[ [SmokeDetector](//goo.gl/eLDYqh) | [MS](//m.erwaysoftware.com/posts/by-url?url=" + \
                        post_url + ") ]"
        else:
            prefix_ms = prefix

        if not post.user_name.strip() or (not poster_url or poster_url.strip() == ""):
            s = u" {}: [{}]({}) by a deleted user on `{}`".format(reason, sanitized_title.strip(), post_url,
                                                                  shortened_site)
            username = ""
        else:
            s = u" {}: [{}]({}) by [{}]({}) on `{}`".format(reason, sanitized_title.strip(), post_url,
                                                            post.user_name.strip(), poster_url, shortened_site)
            username = post.user_name.strip()

        t_metasmoke = Thread(name="metasmoke send post",
                             target=metasmoke.Metasmoke.send_stats_on_post,
                             args=(post.title_ignore_type, post_url, reasons, post.body, username,
                                   post.user_link, why, post.owner_rep, post.post_score,
                                   post.up_vote_count, post.down_vote_count))
        t_metasmoke.start()

        log('debug', GlobalVars.parser.unescape(s).encode('ascii', errors='replace'))
        if time.time() >= GlobalVars.blockedTime["all"]:
            datahandling.append_to_latest_questions(post.post_site, post.post_id, post.title)
            if set(reasons).intersection(GlobalVars.experimental_reasons) != set(reasons):
                if time.time() >= GlobalVars.blockedTime[GlobalVars.charcoal_room_id]:
                    chq_pings = datahandling.get_user_names_on_notification_list("stackexchange.com",
                                                                                 GlobalVars.charcoal_room_id,
                                                                                 post.post_site,
                                                                                 GlobalVars.wrap)
                    chq_msg = prefix + s
                    chq_msg_pings = prefix + datahandling.append_pings(s, chq_pings)
                    chq_msg_pings_ms = prefix_ms + datahandling.append_pings(s, chq_pings)
                    msg_to_send = chq_msg_pings_ms if len(chq_msg_pings_ms) <= 500 else chq_msg_pings \
                        if len(chq_msg_pings) <= 500 else chq_msg[0:500]
                    try:
                        GlobalVars.charcoal_hq.send_message(msg_to_send)
                    except AttributeError:  # In our Test Suite
                        pass
                if not should_reasons_prevent_tavern_posting(reasons) \
                        and post.post_site not in GlobalVars.non_tavern_sites \
                        and time.time() >= GlobalVars.blockedTime[GlobalVars.meta_tavern_room_id]:
                    tavern_pings = datahandling.get_user_names_on_notification_list("meta.stackexchange.com",
                                                                                    GlobalVars.meta_tavern_room_id,
                                                                                    post.post_site, GlobalVars.wrapm)
                    tavern_msg = prefix + s
                    tavern_msg_pings = prefix + datahandling.append_pings(s, tavern_pings)
                    tavern_msg_pings_ms = prefix_ms + datahandling.append_pings(s, tavern_pings)
                    msg_to_send = tavern_msg_pings_ms if len(tavern_msg_pings_ms) <= 500 else tavern_msg_pings \
                        if len(tavern_msg_pings) <= 500 else tavern_msg[0:500]
                    t_check_websocket = Thread(name="deletionwatcher post message if not deleted",
                                               target=deletionwatcher.DeletionWatcher.post_message_if_not_deleted,
                                               args=((post.post_id, post.post_site,
                                                      "answer" if post.is_answer else "question"),
                                                     post_url, msg_to_send, GlobalVars.tavern_on_the_meta))
                    t_check_websocket.daemon = True
                    t_check_websocket.start()
                if post.post_site == "stackoverflow.com" and reason not in GlobalVars.non_socvr_reasons \
                        and time.time() >= GlobalVars.blockedTime[GlobalVars.socvr_room_id]:
                    socvr_pings = datahandling.get_user_names_on_notification_list("stackoverflow.com",
                                                                                   GlobalVars.socvr_room_id,
                                                                                   post.post_site,
                                                                                   GlobalVars.wrapso)
                    socvr_msg = prefix + s
                    socvr_msg_pings = prefix + datahandling.append_pings(s, socvr_pings)
                    socvr_msg_pings_ms = prefix_ms + datahandling.append_pings(s, socvr_pings)
                    msg_to_send = socvr_msg_pings_ms if len(socvr_msg_pings_ms) <= 500 else socvr_msg_pings \
                        if len(socvr_msg_pings) <= 500 else socvr_msg[0:500]
                    try:
                        GlobalVars.socvr.send_message(msg_to_send)
                    except AttributeError:  # In test Suite
                        pass

            for specialroom in GlobalVars.specialrooms:
                sites = specialroom["sites"]
                if post.post_site in sites and reason not in specialroom["unwantedReasons"]:
                    room = specialroom["room"]
                    if room.id not in GlobalVars.blockedTime or time.time() >= GlobalVars.blockedTime[room.id]:
                        room_site = room._client.host
                        room_id = int(room.id)
                        room_pings = datahandling.get_user_names_on_notification_list(room_site, room_id,
                                                                                      post.post_site, room._client)
                        room_msg = prefix + s
                        room_msg_pings = prefix + datahandling.append_pings(s, room_pings)
                        room_msg_pings_ms = prefix_ms + datahandling.append_pings(s, room_pings)
                        msg_to_send = room_msg_pings_ms if len(room_msg_pings_ms) <= 500 else room_msg_pings \
                            if len(room_msg_pings) <= 500 else room_msg[0:500]
                        specialroom["room"].send_message(msg_to_send)
    except:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        excepthook.uncaught_exception(exc_type, exc_obj, exc_tb)
Ejemplo n.º 15
0
def handle_spam(title,
                body,
                poster,
                site,
                post_url,
                poster_url,
                post_id,
                reasons,
                is_answer,
                why="",
                owner_rep=None,
                post_score=None,
                up_vote_count=None,
                down_vote_count=None):
    post_url = to_protocol_relative(url_to_shortlink(post_url))
    poster_url = to_protocol_relative(poster_url)
    reason = ", ".join(reasons)
    reason = reason[:1].upper() + reason[
        1:]  # reason is capitalised, unlike the entries of reasons list
    append_to_latest_questions(site, post_id, title if not is_answer else "")
    if len(reasons) == 1 and ("all-caps title" in reasons
                              or "repeating characters in title" in reasons
                              or "repeating characters in body" in reasons
                              or "repeating characters in answer" in reasons
                              or "repeating words in title" in reasons
                              or "repeating words in body" in reasons
                              or "repeating words in answer" in reasons):
        add_auto_ignored_post((post_id, site, datetime.now()))
    if why is not None and why != "":
        add_why(site, post_id, why)
    try:
        title = escape_special_chars_in_title(title)

        if not poster.strip():
            s = u"[ [SmokeDetector](https://github.com/Charcoal-SE/SmokeDetector) ] {}: [{}]({}) by a deleted user on `{}`" \
                .format(reason, title.strip(), post_url, site)
            username = ""
            user_link = ""
        else:
            s = u"[ [SmokeDetector](https://github.com/Charcoal-SE/SmokeDetector) ] {}: [{}]({}) by [{}]({}) on `{}`" \
                .format(reason, title.strip(), post_url, poster.strip(), poster_url + "?tab=topactivity", site)
            username = poster.strip()
            user_link = poster_url

        t_metasmoke = Thread(target=Metasmoke.send_stats_on_post,
                             args=(title, post_url, reason.split(", "), body,
                                   username, user_link, why, owner_rep,
                                   post_score, up_vote_count, down_vote_count))
        t_metasmoke.start()

        print GlobalVars.parser.unescape(s).encode('ascii', errors='replace')
        if time.time() >= GlobalVars.blockedTime:
            append_to_latest_questions(site, post_id, title)

            if reason not in GlobalVars.experimental_reasons:
                chq_pings = get_user_names_on_notification_list(
                    "stackexchange.com", GlobalVars.charcoal_room_id, site,
                    GlobalVars.wrap)
                chq_msg = append_pings(s, chq_pings)
                GlobalVars.charcoal_hq.send_message(
                    chq_msg if len(chq_msg) <= 500 else s)
                if reason not in GlobalVars.non_tavern_reasons and site not in GlobalVars.non_tavern_sites:
                    tavern_pings = get_user_names_on_notification_list(
                        "meta.stackexchange.com",
                        GlobalVars.meta_tavern_room_id, site, GlobalVars.wrapm)
                    tavern_msg = append_pings(s, tavern_pings)
                    GlobalVars.tavern_on_the_meta.send_message(
                        tavern_msg if len(tavern_msg) <= 500 else s)
                if site == "stackoverflow.com":
                    socvr_pings = get_user_names_on_notification_list(
                        "stackoverflow.com", GlobalVars.socvr_room_id, site,
                        GlobalVars.wrapso)
                    socvr_msg = append_pings(s, socvr_pings)
                    GlobalVars.socvr.send_message(
                        socvr_msg if len(socvr_msg) <= 500 else s)

            for specialroom in GlobalVars.specialrooms:
                sites = specialroom["sites"]
                if site in sites and reason not in specialroom[
                        "unwantedReasons"]:
                    room = specialroom["room"]
                    room_site = room._client.host
                    room_id = int(room.id)
                    room_pings = get_user_names_on_notification_list(
                        room_site, room_id, site, room._client)
                    room_msg = append_pings(s, room_pings)
                    specialroom["room"].send_message(
                        room_msg if len(room_msg) <= 500 else s)
    except:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        excepthook.uncaught_exception(exc_type, exc_obj, exc_tb)
Ejemplo n.º 16
0
def handle_spam(title,
                body,
                poster,
                site,
                post_url,
                poster_url,
                post_id,
                reasons,
                is_answer,
                why="",
                owner_rep=None,
                post_score=None,
                up_vote_count=None,
                down_vote_count=None,
                question_id=None):
    post_url = to_protocol_relative(url_to_shortlink(post_url))
    poster_url = to_protocol_relative(user_url_to_shortlink(poster_url))
    reason = ", ".join(reasons)
    reason = reason[:1].upper() + reason[
        1:]  # reason is capitalised, unlike the entries of reasons list
    append_to_latest_questions(site, post_id, title if not is_answer else "")
    if len(reasons) == 1 and ("all-caps title" in reasons
                              or "repeating characters in title" in reasons
                              or "repeating characters in body" in reasons
                              or "repeating characters in answer" in reasons
                              or "repeating words in title" in reasons
                              or "repeating words in body" in reasons
                              or "repeating words in answer" in reasons):
        add_auto_ignored_post((post_id, site, datetime.now()))
    if why is not None and why != "":
        add_why(site, post_id, why)
    if is_answer and question_id is not None:
        add_post_site_id_link((post_id, site, "answer"), question_id)
    try:
        title = escape_special_chars_in_title(title)

        if not poster.strip():
            s = u"[ [SmokeDetector](//git.io/vgx7b) ] {}: [{}]({}) by a deleted user on `{}`" \
                .format(reason, title.strip(), post_url, site)
            username = ""
            user_link = ""
        else:
            s = u"[ [SmokeDetector](//git.io/vgx7b) ] {}: [{}]({}) by [{}]({}) on `{}`" \
                .format(reason, title.strip(), post_url, poster.strip(), poster_url, site)
            username = poster.strip()
            user_link = poster_url

        t_metasmoke = Thread(target=Metasmoke.send_stats_on_post,
                             args=(title, post_url, reason.split(", "), body,
                                   username, user_link, why, owner_rep,
                                   post_score, up_vote_count, down_vote_count))
        t_metasmoke.start()

        print GlobalVars.parser.unescape(s).encode('ascii', errors='replace')
        if time.time() >= GlobalVars.blockedTime["all"]:
            append_to_latest_questions(site, post_id, title)

            if reason not in GlobalVars.experimental_reasons:
                metasmoke_link = u" [\u2026](//metasmoke.erwaysoftware.com/posts/by-url?url=" + post_url + ")"
                if time.time() >= GlobalVars.blockedTime[
                        GlobalVars.charcoal_room_id]:
                    chq_pings = get_user_names_on_notification_list(
                        "stackexchange.com", GlobalVars.charcoal_room_id, site,
                        GlobalVars.wrap)
                    chq_msg = append_pings(s, chq_pings)
                    chq_msg_ms = chq_msg + metasmoke_link
                    GlobalVars.charcoal_hq.send_message(
                        chq_msg_ms if len(chq_msg_ms) <= 500 else
                        chq_msg if len(chq_msg) <= 500 else s[0:500])
                if reason not in GlobalVars.non_tavern_reasons and site not in GlobalVars.non_tavern_sites and time.time(
                ) >= GlobalVars.blockedTime[GlobalVars.meta_tavern_room_id]:
                    tavern_pings = get_user_names_on_notification_list(
                        "meta.stackexchange.com",
                        GlobalVars.meta_tavern_room_id, site, GlobalVars.wrapm)
                    tavern_msg = append_pings(s, tavern_pings)
                    tavern_msg_ms = tavern_msg + metasmoke_link
                    msg_to_send = tavern_msg_ms if len(
                        tavern_msg_ms) <= 500 else tavern_msg if len(
                            tavern_msg) <= 500 else s[0:500]
                    t_check_websocket = Thread(
                        target=DeletionWatcher.post_message_if_not_deleted,
                        args=((post_id, site,
                               "answer" if is_answer else "question"),
                              post_url, msg_to_send,
                              GlobalVars.tavern_on_the_meta))
                    t_check_websocket.daemon = True
                    t_check_websocket.start()
                if site == "stackoverflow.com" and reason not in GlobalVars.non_socvr_reasons and time.time(
                ) >= GlobalVars.blockedTime[GlobalVars.socvr_room_id]:
                    socvr_pings = get_user_names_on_notification_list(
                        "stackoverflow.com", GlobalVars.socvr_room_id, site,
                        GlobalVars.wrapso)
                    socvr_msg = append_pings(s, socvr_pings)
                    socvr_msg_ms = socvr_msg + metasmoke_link
                    GlobalVars.socvr.send_message(
                        socvr_msg_ms if len(socvr_msg_ms) <= 500 else
                        socvr_msg if len(socvr_msg) <= 500 else s[0:500])

            for specialroom in GlobalVars.specialrooms:
                sites = specialroom["sites"]
                if site in sites and reason not in specialroom[
                        "unwantedReasons"]:
                    room = specialroom["room"]
                    if room.id not in GlobalVars.blockedTime or time.time(
                    ) >= GlobalVars.blockedTime[room.id]:
                        room_site = room._client.host
                        room_id = int(room.id)
                        room_pings = get_user_names_on_notification_list(
                            room_site, room_id, site, room._client)
                        room_msg = append_pings(s, room_pings)
                        room_msg_ms = room_msg + metasmoke_link
                        specialroom["room"].send_message(
                            room_msg_ms if len(room_msg_ms) <= 500 else
                            room_msg if len(room_msg) <= 500 else s[0:500])
    except:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        excepthook.uncaught_exception(exc_type, exc_obj, exc_tb)
Ejemplo n.º 17
0
def handle_spam(post, reasons, why):
    post_url = parsing.to_protocol_relative(
        parsing.url_to_shortlink(post.post_url))
    poster_url = parsing.to_protocol_relative(
        parsing.user_url_to_shortlink(post.user_url))
    shortened_site = post.post_site.replace(
        "stackexchange.com", "SE")  # site.stackexchange.com -> site.SE
    datahandling.append_to_latest_questions(
        post.post_site, post.post_id, post.title if not post.is_answer else "")
    if len(reasons) == 1 and ("all-caps title" in reasons
                              or "repeating characters in title" in reasons
                              or "repeating characters in body" in reasons
                              or "repeating characters in answer" in reasons
                              or "repeating words in title" in reasons
                              or "repeating words in body" in reasons
                              or "repeating words in answer" in reasons):
        datahandling.add_auto_ignored_post(
            (post.post_id, post.post_site, datetime.now()))
    if why is not None and why != "":
        datahandling.add_why(post.post_site, post.post_id, why)
    if post.is_answer and post.post_id is not None and post.post_id is not "":
        datahandling.add_post_site_id_link(
            (post.post_id, post.post_site, "answer"), post.parent.post_id)
    if GlobalVars.reason_weights or GlobalVars.metasmoke_key:
        reason_weight = sum_weight(reasons)
        if reason_weight >= 1000:
            reason_weight_s = " (**{:,}**)".format(reason_weight)
        else:
            reason_weight_s = " ({:,})".format(reason_weight)
    else:  # No reason weight if neither cache nor MS
        reason_weight_s = ""
    try:
        # If the post is an answer type post, the 'title' is going to be blank, so when posting the
        # message contents we need to set the post title to the *parent* title, so the message in the
        # chat is properly constructed with parent title instead. This will make things 'print'
        # in a proper way in chat messages.
        sanitized_title = parsing.sanitize_title(
            post.title if not post.is_answer else post.parent.title)
        sanitized_title = escape_format(sanitized_title).strip()

        prefix = u"[ [SmokeDetector](//goo.gl/eLDYqh) ]"
        if GlobalVars.metasmoke_key:
            prefix_ms = u"[ [SmokeDetector](//goo.gl/eLDYqh) | [MS]({}) ]".format(
                to_metasmoke_link(post_url, protocol=False))
        else:
            prefix_ms = prefix

        # We'll insert reason list later
        edited = '' if not post.edited else ' \u270F\uFE0F'
        if not post.user_name.strip() or (not poster_url
                                          or poster_url.strip() == ""):
            s = " {{}}{}: [{}]({}){} by a deleted user on `{}`".format(
                reason_weight_s, sanitized_title, post_url, edited,
                shortened_site)
            username = ""
        else:
            username = post.user_name.strip()
            escaped_username = escape_format(parsing.escape_markdown(username))
            s = " {{}}{}: [{}]({}){} by [{}]({}) on `{}`".format(
                reason_weight_s, sanitized_title, post_url, edited,
                escaped_username, poster_url, shortened_site)

        Tasks.do(metasmoke.Metasmoke.send_stats_on_post,
                 post.title_ignore_type, post_url, reasons, post.body,
                 username, post.user_link, why, post.owner_rep,
                 post.post_score, post.up_vote_count, post.down_vote_count)

        log('debug',
            GlobalVars.parser.unescape(s).encode('ascii', errors='replace'))
        GlobalVars.deletion_watcher.subscribe(post_url)

        reason = message = None
        for reason_count in range(
                5, 0, -1):  # Try 5 reasons and all the way down to 1
            reason = ", ".join(reasons[:reason_count])
            if len(reasons) > reason_count:
                reason += ", +{} more".format(len(reasons) - reason_count)
            reason = reason.capitalize()
            message = prefix_ms + s.format(reason)  # Insert reason list
            if len(message) <= 500:
                break  # Problem solved, stop attempting

        s = s.format(reason)  # Later code needs this variable
        if len(message) > 500:
            message = (prefix_ms +
                       s)[:500]  # Truncate directly and keep MS link

        without_roles = tuple(["no-" + reason for reason in reasons
                               ]) + ("site-no-" + post.post_site, )

        if set(reasons) - GlobalVars.experimental_reasons == set() and \
                not why.startswith("Post manually "):
            chatcommunicate.tell_rooms(message, ("experimental", ),
                                       without_roles,
                                       notify_site=post.post_site,
                                       report_data=(post_url, poster_url))
        else:
            chatcommunicate.tell_rooms(message,
                                       ("all", "site-" + post.post_site),
                                       without_roles,
                                       notify_site=post.post_site,
                                       report_data=(post_url, poster_url))
    except Exception as e:
        excepthook.uncaught_exception(*sys.exc_info())
Ejemplo n.º 18
0
def build_message(post, reasons):
    # This is the main report format. Username and user link are deliberately not separated as with title and post
    # link, because we may want to use "by a deleted user" rather than a username+link.
    message_format = "{prefix_ms} {{reasons}} ({reason_weight}): [{title}]({post_url}) by {user} on `{site}`"

    # Post URL, user URL, and site details are all easy - just data from the post object, transformed a bit
    # via datahandling.
    post_url = parsing.to_protocol_relative(
        parsing.url_to_shortlink(post.post_url))
    poster_url = parsing.to_protocol_relative(
        parsing.user_url_to_shortlink(post.user_url))
    shortened_site = post.post_site.replace(
        "stackexchange.com", "SE")  # site.stackexchange.com -> site.SE

    # Message prefix. There's always a link to SmokeDetector; if we have a metasmoke key, there's also a link to the
    # post's MS record. If we *don't* have a MS key, it's a fair assumption that the post won't be in metasmoke as
    # we didn't have a key to create a record for it.
    prefix = u"[ [SmokeDetector](//git.io/vyDZv) ]"
    if GlobalVars.metasmoke_key:
        prefix = u"[ [SmokeDetector](//git.io/vyDZv) | [MS]({}) ]".format(
            to_metasmoke_link(post_url, protocol=False))

    # If we have reason weights cached (GlobalVars.reason_weights) we can calculate total weight for this report;
    # likewise, if we have a MS key, we can fetch the weights and then calculate. If we have neither, tough luck.
    if GlobalVars.reason_weights or GlobalVars.metasmoke_key:
        reason_weight = sum_weight(reasons)
        if reason_weight >= 1000:
            reason_weight = "**{}**".format(reason_weight)
        else:
            reason_weight = "{}".format(reason_weight)
    else:
        reason_weight = ""

    # If the post is an answer, it doesn't have a title, so we use the question's title instead. Either way, we
    # make sure it's escaped. We also add the edited indicator here.
    sanitized_title = parsing.sanitize_title(
        post.title if not post.is_answer else post.parent.title)
    sanitized_title = escape_format(sanitized_title).strip()
    if post.edited:  # Append a pencil emoji for edited posts
        sanitized_title += ' \u270F\uFE0F'

    # If we have user details available, we'll linkify the username. If we don't, we call it a deleted user.
    if not post.user_name.strip() or (not poster_url
                                      or poster_url.strip() == ""):
        user = "******"
    else:
        username = post.user_name.strip()
        escaped_username = escape_format(parsing.escape_markdown(username))
        user = "******".format(escaped_username, poster_url)

    # Build the main body of the message. The next step is to insert the reason list while keeping the message
    # under 500 characters long.
    message = message_format.format(prefix_ms=prefix,
                                    reason_weight=reason_weight,
                                    title=sanitized_title,
                                    post_url=post_url,
                                    user=user,
                                    site=shortened_site)

    for reason_count in range(5, 0, -1):
        reason = ", ".join(reasons[:reason_count])
        if len(reasons) > reason_count:
            reason += ", +{} more".format(len(reasons) - reason_count)
        reason = reason.capitalize()
        attempt = message.format(reasons=reason)
        if len(attempt) <= 500:
            message = attempt
            break

    # If the message is still longer than 500 chars after trying to reduce the reason list, we're out of options,
    # so just cut the end of the message off.
    if len(message) > 500:
        message = message[:500]

    return message
Ejemplo n.º 19
0
def handle_spam(title, body, poster, site, post_url, poster_url, post_id, reasons, is_answer, why="", owner_rep=None, post_score=None, up_vote_count=None, down_vote_count=None):
    post_url = to_protocol_relative(url_to_shortlink(post_url))
    poster_url = to_protocol_relative(poster_url)
    reason = ", ".join(reasons)
    reason = reason[:1].upper() + reason[1:]  # reason is capitalised, unlike the entries of reasons list
    append_to_latest_questions(site, post_id, title if not is_answer else "")
    if len(reasons) == 1 and ("all-caps title" in reasons or
                              "repeating characters in title" in reasons or
                              "repeating characters in body" in reasons or
                              "repeating characters in answer" in reasons or
                              "repeating words in title" in reasons or
                              "repeating words in body" in reasons or
                              "repeating words in answer" in reasons):
        add_auto_ignored_post((post_id, site, datetime.now()))
    if why is not None and why != "":
        add_why(site, post_id, why)
    try:
        title = escape_special_chars_in_title(title)

        if not poster.strip():
            s = u"[ [SmokeDetector](https://github.com/Charcoal-SE/SmokeDetector) ] {}: [{}]({}) by a deleted user on `{}`" \
                .format(reason, title.strip(), post_url, site)
            username = ""
            user_link = ""
        else:
            s = u"[ [SmokeDetector](https://github.com/Charcoal-SE/SmokeDetector) ] {}: [{}]({}) by [{}]({}) on `{}`" \
                .format(reason, title.strip(), post_url, poster.strip(), poster_url + "?tab=topactivity", site)
            username = poster.strip()
            user_link = poster_url

        t_metasmoke = Thread(target=Metasmoke.send_stats_on_post,
                             args=(title, post_url, reason.split(", "), body, username, user_link, why, owner_rep, post_score, up_vote_count, down_vote_count))
        t_metasmoke.start()

        print GlobalVars.parser.unescape(s).encode('ascii', errors='replace')
        if time.time() >= GlobalVars.blockedTime:
            append_to_latest_questions(site, post_id, title)

            if reason not in GlobalVars.experimental_reasons:
                chq_pings = get_user_names_on_notification_list("stackexchange.com", GlobalVars.charcoal_room_id, site, GlobalVars.wrap)
                chq_msg = append_pings(s, chq_pings)
                GlobalVars.charcoal_hq.send_message(chq_msg if len(chq_msg) <= 500 else s)
                if reason not in GlobalVars.non_tavern_reasons and site not in GlobalVars.non_tavern_sites:
                    tavern_pings = get_user_names_on_notification_list("meta.stackexchange.com", GlobalVars.meta_tavern_room_id, site, GlobalVars.wrapm)
                    tavern_msg = append_pings(s, tavern_pings)
                    GlobalVars.tavern_on_the_meta.send_message(tavern_msg if len(tavern_msg) <= 500 else s)
                if site == "stackoverflow.com":
                    socvr_pings = get_user_names_on_notification_list("stackoverflow.com", GlobalVars.socvr_room_id, site, GlobalVars.wrapso)
                    socvr_msg = append_pings(s, socvr_pings)
                    GlobalVars.socvr.send_message(socvr_msg if len(socvr_msg) <= 500 else s)

            for specialroom in GlobalVars.specialrooms:
                sites = specialroom["sites"]
                if site in sites and reason not in specialroom["unwantedReasons"]:
                    room = specialroom["room"]
                    room_site = room._client.host
                    room_id = int(room.id)
                    room_pings = get_user_names_on_notification_list(room_site, room_id, site, room._client)
                    room_msg = append_pings(s, room_pings)
                    specialroom["room"].send_message(room_msg if len(room_msg) <= 500 else s)
    except:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        excepthook.uncaught_exception(exc_type, exc_obj, exc_tb)
Ejemplo n.º 20
0
def handle_spam(post, reasons, why):
    post_url = parsing.to_protocol_relative(parsing.url_to_shortlink(post.post_url))
    poster_url = parsing.to_protocol_relative(parsing.user_url_to_shortlink(post.user_url))
    shortened_site = post.post_site.replace("stackexchange.com", "SE")  # site.stackexchange.com -> site.SE
    datahandling.append_to_latest_questions(post.post_site, post.post_id, post.title if not post.is_answer else "")
    if len(reasons) == 1 and ("all-caps title" in reasons or
                              "repeating characters in title" in reasons or
                              "repeating characters in body" in reasons or
                              "repeating characters in answer" in reasons or
                              "repeating words in title" in reasons or
                              "repeating words in body" in reasons or
                              "repeating words in answer" in reasons):
        datahandling.add_auto_ignored_post((post.post_id, post.post_site, datetime.now()))
    if why is not None and why != "":
        datahandling.add_why(post.post_site, post.post_id, why)
    if post.is_answer and post.post_id is not None and post.post_id is not "":
        datahandling.add_post_site_id_link((post.post_id, post.post_site, "answer"), post.parent.post_id)
    if GlobalVars.reason_weights or GlobalVars.metasmoke_key:
        reason_weight = sum_weight(reasons)
        if reason_weight >= 1000:
            reason_weight_s = " (**{}**)".format(reason_weight)
        else:
            reason_weight_s = " ({})".format(reason_weight)
    else:  # No reason weight if neither cache nor MS
        reason_weight_s = ""
    try:
        # If the post is an answer type post, the 'title' is going to be blank, so when posting the
        # message contents we need to set the post title to the *parent* title, so the message in the
        # chat is properly constructed with parent title instead. This will make things 'print'
        # in a proper way in chat messages.
        sanitized_title = parsing.sanitize_title(post.title if not post.is_answer else post.parent.title)
        sanitized_title = escape_format(sanitized_title).strip()

        prefix = u"[ [SmokeDetector](//git.io/vyDZv) ]"
        if GlobalVars.metasmoke_key:
            prefix_ms = u"[ [SmokeDetector](//git.io/vyDZv) | [MS]({}) ]".format(
                to_metasmoke_link(post_url, protocol=False))
        else:
            prefix_ms = prefix

        # We'll insert reason list later
        edited = '' if not post.edited else ' \u270F\uFE0F'
        if not post.user_name.strip() or (not poster_url or poster_url.strip() == ""):
            s = " {{}}{}: [{}]({}){} by a deleted user on `{}`".format(
                reason_weight_s, sanitized_title, post_url, edited, shortened_site)
            username = ""
        else:
            username = post.user_name.strip()
            escaped_username = escape_format(parsing.escape_markdown(username))
            s = " {{}}{}: [{}]({}){} by [{}]({}) on `{}`".format(
                reason_weight_s, sanitized_title, post_url, edited, escaped_username, poster_url, shortened_site)

        Tasks.do(metasmoke.Metasmoke.send_stats_on_post,
                 post.title_ignore_type, post_url, reasons, post.body, username,
                 post.user_link, why, post.owner_rep, post.post_score,
                 post.up_vote_count, post.down_vote_count)

        log('debug', GlobalVars.parser.unescape(s).encode('ascii', errors='replace'))
        GlobalVars.deletion_watcher.subscribe(post_url)

        reason = message = None
        for reason_count in range(5, 0, -1):  # Try 5 reasons and all the way down to 1
            reason = ", ".join(reasons[:reason_count])
            if len(reasons) > reason_count:
                reason += ", +{} more".format(len(reasons) - reason_count)
            reason = reason.capitalize()
            message = prefix_ms + s.format(reason)  # Insert reason list
            if len(message) <= 500:
                break  # Problem solved, stop attempting

        s = s.format(reason)  # Later code needs this variable
        if len(message) > 500:
            message = (prefix_ms + s)[:500]  # Truncate directly and keep MS link

        without_roles = tuple(["no-" + reason for reason in reasons]) + ("site-no-" + post.post_site,)

        if set(reasons) - GlobalVars.experimental_reasons == set() and \
                not why.startswith("Post manually "):
            chatcommunicate.tell_rooms(message, ("experimental",),
                                       without_roles, notify_site=post.post_site, report_data=(post_url, poster_url))
        else:
            chatcommunicate.tell_rooms(message, ("all", "site-" + post.post_site),
                                       without_roles, notify_site=post.post_site, report_data=(post_url, poster_url))
    except Exception as e:
        excepthook.uncaught_exception(*sys.exc_info())
Ejemplo n.º 21
0
def handle_spam(title, body, poster, site, post_url, poster_url, post_id, reasons, is_answer, why="", owner_rep=None, post_score=None, up_vote_count=None, down_vote_count=None, question_id=None):
    post_url = parsing.to_protocol_relative(parsing.url_to_shortlink(post_url))
    poster_url = parsing.to_protocol_relative(parsing.user_url_to_shortlink(poster_url))
    reason = ", ".join(reasons)
    reason = reason[:1].upper() + reason[1:]  # reason is capitalised, unlike the entries of reasons list
    datahandling.append_to_latest_questions(site, post_id, title if not is_answer else "")
    if len(reasons) == 1 and ("all-caps title" in reasons or
                              "repeating characters in title" in reasons or
                              "repeating characters in body" in reasons or
                              "repeating characters in answer" in reasons or
                              "repeating words in title" in reasons or
                              "repeating words in body" in reasons or
                              "repeating words in answer" in reasons):
        datahandling.add_auto_ignored_post((post_id, site, datetime.now()))
    if why is not None and why != "":
        datahandling.add_why(site, post_id, why)
    if is_answer and question_id is not None:
        datahandling.add_post_site_id_link((post_id, site, "answer"), question_id)
    try:
        title = parsing.escape_special_chars_in_title(title)
        sanitized_title = regex.sub('https?://', '', title)

        prefix = u"[ [SmokeDetector](//git.io/vgx7b) ]"
        if GlobalVars.metasmoke_key:
            prefix_ms = u"[ [SmokeDetector](//git.io/vgx7b) | [MS](//m.erwaysoftware.com/posts/by-url?url=" + post_url + ") ]"
        else:
            prefix_ms = prefix

        if not poster.strip():
            s = u" {}: [{}]({}) by a deleted user on `{}`".format(reason, sanitized_title.strip(), post_url, site)
            username = ""
            user_link = ""
        else:
            s = u" {}: [{}]({}) by [{}]({}) on `{}`" .format(reason, sanitized_title.strip(), post_url, poster.strip(), poster_url, site)
            username = poster.strip()
            user_link = poster_url

        t_metasmoke = Thread(target=metasmoke.Metasmoke.send_stats_on_post,
                             args=(title, post_url, reason.split(", "), body, username, user_link, why, owner_rep, post_score, up_vote_count, down_vote_count))
        t_metasmoke.start()

        print GlobalVars.parser.unescape(s).encode('ascii', errors='replace')
        if time.time() >= GlobalVars.blockedTime["all"]:
            datahandling.append_to_latest_questions(site, post_id, title)
            if reason not in GlobalVars.experimental_reasons:
                if time.time() >= GlobalVars.blockedTime[GlobalVars.charcoal_room_id]:
                    chq_pings = datahandling.get_user_names_on_notification_list("stackexchange.com", GlobalVars.charcoal_room_id, site, GlobalVars.wrap)
                    chq_msg = prefix + s
                    chq_msg_pings = prefix + datahandling.append_pings(s, chq_pings)
                    chq_msg_pings_ms = prefix_ms + datahandling.append_pings(s, chq_pings)
                    msg_to_send = chq_msg_pings_ms if len(chq_msg_pings_ms) <= 500 else chq_msg_pings if len(chq_msg_pings) <= 500 else chq_msg[0:500]
                    GlobalVars.charcoal_hq.send_message(msg_to_send)
                if not should_reasons_prevent_tavern_posting(reasons) and site not in GlobalVars.non_tavern_sites and time.time() >= GlobalVars.blockedTime[GlobalVars.meta_tavern_room_id]:
                    tavern_pings = datahandling.get_user_names_on_notification_list("meta.stackexchange.com", GlobalVars.meta_tavern_room_id, site, GlobalVars.wrapm)
                    tavern_msg = prefix + s
                    tavern_msg_pings = prefix + datahandling.append_pings(s, tavern_pings)
                    tavern_msg_pings_ms = prefix_ms + datahandling.append_pings(s, tavern_pings)
                    msg_to_send = tavern_msg_pings_ms if len(tavern_msg_pings_ms) <= 500 else tavern_msg_pings if len(tavern_msg_pings) <= 500 else tavern_msg[0:500]
                    t_check_websocket = Thread(target=deletionwatcher.DeletionWatcher.post_message_if_not_deleted, args=((post_id, site, "answer" if is_answer else "question"), post_url, msg_to_send, GlobalVars.tavern_on_the_meta))
                    t_check_websocket.daemon = True
                    t_check_websocket.start()
                if site == "stackoverflow.com" and reason not in GlobalVars.non_socvr_reasons and time.time() >= GlobalVars.blockedTime[GlobalVars.socvr_room_id]:
                    socvr_pings = datahandling.get_user_names_on_notification_list("stackoverflow.com", GlobalVars.socvr_room_id, site, GlobalVars.wrapso)
                    socvr_msg = prefix + s
                    socvr_msg_pings = prefix + datahandling.append_pings(s, socvr_pings)
                    socvr_msg_pings_ms = prefix_ms + datahandling.append_pings(s, socvr_pings)
                    msg_to_send = socvr_msg_pings_ms if len(socvr_msg_pings_ms) <= 500 else socvr_msg_pings if len(socvr_msg_pings) <= 500 else socvr_msg[0:500]
                    GlobalVars.socvr.send_message(msg_to_send)

            for specialroom in GlobalVars.specialrooms:
                sites = specialroom["sites"]
                if site in sites and reason not in specialroom["unwantedReasons"]:
                    room = specialroom["room"]
                    if room.id not in GlobalVars.blockedTime or time.time() >= GlobalVars.blockedTime[room.id]:
                        room_site = room._client.host
                        room_id = int(room.id)
                        room_pings = datahandling.get_user_names_on_notification_list(room_site, room_id, site, room._client)
                        room_msg = prefix + s
                        room_msg_pings = prefix + datahandling.append_pings(s, room_pings)
                        room_msg_pings_ms = prefix_ms + datahandling.append_pings(s, room_pings)
                        msg_to_send = room_msg_pings_ms if len(room_msg_pings_ms) <= 500 else room_msg_pings if len(room_msg_pings) <= 500 else room_msg[0:500]
                        specialroom["room"].send_message(msg_to_send)
    except:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        excepthook.uncaught_exception(exc_type, exc_obj, exc_tb)
Ejemplo n.º 22
0
def handle_spam(title,
                body,
                poster,
                site,
                post_url,
                poster_url,
                post_id,
                reasons,
                is_answer,
                why="",
                owner_rep=None,
                post_score=None,
                up_vote_count=None,
                down_vote_count=None,
                question_id=None):
    post_url = parsing.to_protocol_relative(parsing.url_to_shortlink(post_url))
    poster_url = parsing.to_protocol_relative(
        parsing.user_url_to_shortlink(poster_url))
    reason = ", ".join(reasons[:5])
    if len(reasons) > 5:
        reason += ", +{} more".format(len(reasons) - 5)
    reason = reason[:1].upper() + reason[
        1:]  # reason is capitalised, unlike the entries of reasons list
    shortened_site = site.replace("stackexchange.com",
                                  "SE")  # site.stackexchange.com -> site.SE
    datahandling.append_to_latest_questions(site, post_id,
                                            title if not is_answer else "")
    if len(reasons) == 1 and ("all-caps title" in reasons
                              or "repeating characters in title" in reasons
                              or "repeating characters in body" in reasons
                              or "repeating characters in answer" in reasons
                              or "repeating words in title" in reasons
                              or "repeating words in body" in reasons
                              or "repeating words in answer" in reasons):
        datahandling.add_auto_ignored_post((post_id, site, datetime.now()))
    if why is not None and why != "":
        datahandling.add_why(site, post_id, why)
    if is_answer and question_id is not None:
        datahandling.add_post_site_id_link((post_id, site, "answer"),
                                           question_id)
    try:
        title = parsing.escape_special_chars_in_title(title)
        sanitized_title = regex.sub('(https?://|\n)', '', title)

        prefix = u"[ [SmokeDetector](//goo.gl/eLDYqh) ]"
        if GlobalVars.metasmoke_key:
            prefix_ms = u"[ [SmokeDetector](//goo.gl/eLDYqh) | [MS](//m.erwaysoftware.com/posts/by-url?url=" + \
                        post_url + ") ]"
        else:
            prefix_ms = prefix

        if not poster.strip():
            s = u" {}: [{}]({}) by a deleted user on `{}`".format(
                reason, sanitized_title.strip(), post_url, shortened_site)
            username = ""
            user_link = ""
        else:
            s = u" {}: [{}]({}) by [{}]({}) on `{}`".format(
                reason, sanitized_title.strip(), post_url, poster.strip(),
                poster_url, shortened_site)
            username = poster.strip()
            user_link = poster_url

        t_metasmoke = Thread(name="metasmoke send post",
                             target=metasmoke.Metasmoke.send_stats_on_post,
                             args=(title, post_url, reasons, body, username,
                                   user_link, why, owner_rep, post_score,
                                   up_vote_count, down_vote_count))
        t_metasmoke.start()

        print GlobalVars.parser.unescape(s).encode('ascii', errors='replace')
        if time.time() >= GlobalVars.blockedTime["all"]:
            datahandling.append_to_latest_questions(site, post_id, title)
            if reason not in GlobalVars.experimental_reasons:
                if time.time() >= GlobalVars.blockedTime[
                        GlobalVars.charcoal_room_id]:
                    chq_pings = datahandling.get_user_names_on_notification_list(
                        "stackexchange.com", GlobalVars.charcoal_room_id, site,
                        GlobalVars.wrap)
                    chq_msg = prefix + s
                    chq_msg_pings = prefix + datahandling.append_pings(
                        s, chq_pings)
                    chq_msg_pings_ms = prefix_ms + datahandling.append_pings(
                        s, chq_pings)
                    msg_to_send = chq_msg_pings_ms if len(chq_msg_pings_ms) <= 500 else chq_msg_pings \
                        if len(chq_msg_pings) <= 500 else chq_msg[0:500]
                    GlobalVars.charcoal_hq.send_message(msg_to_send)
                if not should_reasons_prevent_tavern_posting(reasons) and site not in GlobalVars.non_tavern_sites \
                        and time.time() >= GlobalVars.blockedTime[GlobalVars.meta_tavern_room_id]:
                    tavern_pings = datahandling.get_user_names_on_notification_list(
                        "meta.stackexchange.com",
                        GlobalVars.meta_tavern_room_id, site, GlobalVars.wrapm)
                    tavern_msg = prefix + s
                    tavern_msg_pings = prefix + datahandling.append_pings(
                        s, tavern_pings)
                    tavern_msg_pings_ms = prefix_ms + datahandling.append_pings(
                        s, tavern_pings)
                    msg_to_send = tavern_msg_pings_ms if len(tavern_msg_pings_ms) <= 500 else tavern_msg_pings \
                        if len(tavern_msg_pings) <= 500 else tavern_msg[0:500]
                    t_check_websocket = Thread(
                        name="deletionwatcher post message if not deleted",
                        target=deletionwatcher.DeletionWatcher.
                        post_message_if_not_deleted,
                        args=((post_id, site,
                               "answer" if is_answer else "question"),
                              post_url, msg_to_send,
                              GlobalVars.tavern_on_the_meta))
                    t_check_websocket.daemon = True
                    t_check_websocket.start()
                if site == "stackoverflow.com" and reason not in GlobalVars.non_socvr_reasons \
                        and time.time() >= GlobalVars.blockedTime[GlobalVars.socvr_room_id]:
                    socvr_pings = datahandling.get_user_names_on_notification_list(
                        "stackoverflow.com", GlobalVars.socvr_room_id, site,
                        GlobalVars.wrapso)
                    socvr_msg = prefix + s
                    socvr_msg_pings = prefix + datahandling.append_pings(
                        s, socvr_pings)
                    socvr_msg_pings_ms = prefix_ms + datahandling.append_pings(
                        s, socvr_pings)
                    msg_to_send = socvr_msg_pings_ms if len(socvr_msg_pings_ms) <= 500 else socvr_msg_pings \
                        if len(socvr_msg_pings) <= 500 else socvr_msg[0:500]
                    GlobalVars.socvr.send_message(msg_to_send)

            for specialroom in GlobalVars.specialrooms:
                sites = specialroom["sites"]
                if site in sites and reason not in specialroom[
                        "unwantedReasons"]:
                    room = specialroom["room"]
                    if room.id not in GlobalVars.blockedTime or time.time(
                    ) >= GlobalVars.blockedTime[room.id]:
                        room_site = room._client.host
                        room_id = int(room.id)
                        room_pings = datahandling.get_user_names_on_notification_list(
                            room_site, room_id, site, room._client)
                        room_msg = prefix + s
                        room_msg_pings = prefix + datahandling.append_pings(
                            s, room_pings)
                        room_msg_pings_ms = prefix_ms + datahandling.append_pings(
                            s, room_pings)
                        msg_to_send = room_msg_pings_ms if len(room_msg_pings_ms) <= 500 else room_msg_pings \
                            if len(room_msg_pings) <= 500 else room_msg[0:500]
                        specialroom["room"].send_message(msg_to_send)
    except:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        excepthook.uncaught_exception(exc_type, exc_obj, exc_tb)
Ejemplo n.º 23
0
def handle_spam(post, reasons, why):
    post_url = parsing.to_protocol_relative(
        parsing.url_to_shortlink(post.post_url))
    poster_url = parsing.to_protocol_relative(
        parsing.user_url_to_shortlink(post.user_url))
    shortened_site = post.post_site.replace(
        "stackexchange.com", "SE")  # site.stackexchange.com -> site.SE
    datahandling.append_to_latest_questions(
        post.post_site, post.post_id, post.title if not post.is_answer else "")
    if len(reasons) == 1 and ("all-caps title" in reasons
                              or "repeating characters in title" in reasons
                              or "repeating characters in body" in reasons
                              or "repeating characters in answer" in reasons
                              or "repeating words in title" in reasons
                              or "repeating words in body" in reasons
                              or "repeating words in answer" in reasons):
        datahandling.add_auto_ignored_post(
            (post.post_id, post.post_site, datetime.now()))
    if why is not None and why != "":
        datahandling.add_why(post.post_site, post.post_id, why)
    if post.is_answer and post.post_id is not None and post.post_id is not "":
        datahandling.add_post_site_id_link(
            (post.post_id, post.post_site, "answer"), post.parent.post_id)
    try:
        # If the post is an answer type post, the 'title' is going to be blank, so when posting the
        # message contents we need to set the post title to the *parent* title, so the message in the
        # chat is properly constructed with parent title instead. This will make things 'print'
        # in a proper way in chat messages.
        sanitized_title = parsing.sanitize_title(
            post.title if not post.is_answer else post.parent.title)

        prefix = u"[ [SmokeDetector](//goo.gl/eLDYqh) ]"
        if GlobalVars.metasmoke_key:
            prefix_ms = u"[ [SmokeDetector](//goo.gl/eLDYqh) | [MS](//m.erwaysoftware.com/posts/uid/{}/{}) ]".format(
                api_parameter_from_link(post_url), post.post_id)
        else:
            prefix_ms = prefix

        # We'll insert reason list later
        if not post.user_name.strip() or (not poster_url
                                          or poster_url.strip() == ""):
            s = u" {{}}: [{}]({}) by a deleted user on `{}`".format(
                sanitized_title, post_url, shortened_site)
            username = ""
        else:
            s = u" {{}}: [{}]({}) by [{}]({}) on `{}`".format(
                sanitized_title, post_url, post.user_name.strip(), poster_url,
                shortened_site)
            username = post.user_name.strip()

        Tasks.do(metasmoke.Metasmoke.send_stats_on_post,
                 post.title_ignore_type, post_url, reasons, post.body,
                 username, post.user_link, why, post.owner_rep,
                 post.post_score, post.up_vote_count, post.down_vote_count)

        log('debug',
            GlobalVars.parser.unescape(s).encode('ascii', errors='replace'))
        GlobalVars.deletion_watcher.subscribe(post_url)

        reason = message = None
        for reason_count in range(5, 2, -1):  # Try 5 reasons, then 4, then 3
            reason = ", ".join(reasons[:reason_count])
            if len(reasons) > reason_count:
                reason += ", +{} more".format(len(reasons) - reason_count)
            reason = reason[:1].upper() + reason[
                1:]  # reason is capitalised, unlike the entries of reasons list
            message = prefix_ms + s.format(reason)  # Insert reason list
            if len(message) <= 500:
                break  # Problem solved, stop attempting

        s = s.format(reason)  # Later code needs this variable
        if len(message) > 500:
            message = (prefix_ms +
                       s)[:500]  # Truncate directly and keep MS link

        without_roles = tuple(
            "no-" + reason
            for reason in reasons) + ("site-no-" + post.post_site, )

        if set(reasons) - GlobalVars.experimental_reasons == set():
            chatcommunicate.tell_rooms(message, ("experimental", ),
                                       without_roles,
                                       notify_site=post.post_site,
                                       report_data=(post_url, poster_url))
        else:
            chatcommunicate.tell_rooms(message,
                                       ("all", "site-" + post.post_site),
                                       without_roles,
                                       notify_site=post.post_site,
                                       report_data=(post_url, poster_url))
    except:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        excepthook.uncaught_exception(exc_type, exc_obj, exc_tb)
Ejemplo n.º 24
0
def handle_spam(post, reasons, why):
    post_url = parsing.to_protocol_relative(
        parsing.url_to_shortlink(post.post_url))
    poster_url = parsing.to_protocol_relative(
        parsing.user_url_to_shortlink(post.user_url))
    reason = ", ".join(reasons[:5])
    if len(reasons) > 5:
        reason += ", +{} more".format(len(reasons) - 5)
    reason = reason[:1].upper() + reason[
        1:]  # reason is capitalised, unlike the entries of reasons list
    shortened_site = post.post_site.replace(
        "stackexchange.com", "SE")  # site.stackexchange.com -> site.SE
    datahandling.append_to_latest_questions(
        post.post_site, post.post_id, post.title if not post.is_answer else "")
    if len(reasons) == 1 and ("all-caps title" in reasons
                              or "repeating characters in title" in reasons
                              or "repeating characters in body" in reasons
                              or "repeating characters in answer" in reasons
                              or "repeating words in title" in reasons
                              or "repeating words in body" in reasons
                              or "repeating words in answer" in reasons):
        datahandling.add_auto_ignored_post(
            (post.post_id, post.post_site, datetime.now()))
    if why is not None and why != "":
        datahandling.add_why(post.post_site, post.post_id, why)
    if post.is_answer and post.post_id is not None and post.post_id is not "":
        datahandling.add_post_site_id_link(
            (post.post_id, post.post_site, "answer"), post.parent.post_id)
    try:
        post._title = parsing.escape_special_chars_in_title(post.title)
        if post.is_answer:
            # If the post is an answer type post, the 'title' is going to be blank, so when posting the
            # message contents we need to set the post title to the *parent* title, so the message in the
            # chat is properly constructed with parent title instead. This will make things 'print'
            # in a proper way in chat messages.
            sanitized_title = regex.sub('(https?://|\n)', '',
                                        post.parent.title)
        else:
            sanitized_title = regex.sub('(https?://|\n)', '', post.title)

        sanitized_title = regex.sub(r'([\]*`])', r'\\\1',
                                    sanitized_title).replace('\n', u'\u23CE')

        prefix = u"[ [SmokeDetector](//goo.gl/eLDYqh) ]"
        if GlobalVars.metasmoke_key:
            prefix_ms = u"[ [SmokeDetector](//goo.gl/eLDYqh) | [MS](//m.erwaysoftware.com/posts/by-url?url=" + \
                        post_url + ") ]"
        else:
            prefix_ms = prefix

        if not post.user_name.strip() or (not poster_url
                                          or poster_url.strip() == ""):
            s = u" {}: [{}]({}) by a deleted user on `{}`".format(
                reason, sanitized_title.strip(), post_url, shortened_site)
            username = ""
        else:
            s = u" {}: [{}]({}) by [{}]({}) on `{}`".format(
                reason, sanitized_title.strip(), post_url,
                post.user_name.strip(), poster_url, shortened_site)
            username = post.user_name.strip()

        Tasks.do(metasmoke.Metasmoke.send_stats_on_post,
                 post.title_ignore_type, post_url, reasons, post.body,
                 username, post.user_link, why, post.owner_rep,
                 post.post_score, post.up_vote_count, post.down_vote_count)

        log('debug',
            GlobalVars.parser.unescape(s).encode('ascii', errors='replace'))
        datahandling.append_to_latest_questions(post.post_site, post.post_id,
                                                post.title)

        message = prefix_ms + s
        if len(message) > 500:
            message = (prefix + s)[:500]

        without_roles = tuple(
            "no-" + reason
            for reason in reasons) + ("site-no-" + post.post_site, )

        if set(reason) & GlobalVars.experimental_reasons == {}:
            chatcommunicate.tell_rooms(message, ("experimental"),
                                       without_roles,
                                       notify_site=post.post_site,
                                       report_data=(post_url, poster_url))
        else:
            chatcommunicate.tell_rooms(message,
                                       ("all", "site-" + post.post_site),
                                       without_roles,
                                       notify_site=post.post_site,
                                       report_data=(post_url, poster_url))
    except:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        excepthook.uncaught_exception(exc_type, exc_obj, exc_tb)
Ejemplo n.º 25
0
def handle_spam(post, reasons, why):
    post_url = parsing.to_protocol_relative(
        parsing.url_to_shortlink(post.post_url))
    poster_url = parsing.to_protocol_relative(
        parsing.user_url_to_shortlink(post.user_url))
    reason = ", ".join(reasons[:5])
    if len(reasons) > 5:
        reason += ", +{} more".format(len(reasons) - 5)
    reason = reason[:1].upper() + reason[
        1:]  # reason is capitalised, unlike the entries of reasons list
    shortened_site = post.post_site.replace(
        "stackexchange.com", "SE")  # site.stackexchange.com -> site.SE
    datahandling.append_to_latest_questions(
        post.post_site, post.post_id, post.title if not post.is_answer else "")
    if len(reasons) == 1 and ("all-caps title" in reasons
                              or "repeating characters in title" in reasons
                              or "repeating characters in body" in reasons
                              or "repeating characters in answer" in reasons
                              or "repeating words in title" in reasons
                              or "repeating words in body" in reasons
                              or "repeating words in answer" in reasons):
        datahandling.add_auto_ignored_post(
            (post.post_id, post.post_site, datetime.now()))
    if why is not None and why != "":
        datahandling.add_why(post.post_site, post.post_id, why)
    if post.is_answer and post.post_id is not None and post.post_id is not "":
        datahandling.add_post_site_id_link(
            (post.post_id, post.post_site, "answer"), post.parent.post_id)
    try:
        post._title = parsing.escape_special_chars_in_title(post.title)
        if post.is_answer:
            # If the post is an answer type post, the 'title' is going to be blank, so when posting the
            # message contents we need to set the post title to the *parent* title, so the message in the
            # chat is properly constructed with parent title instead. This will make things 'print'
            # in a proper way in chat messages.
            sanitized_title = regex.sub('(https?://|\n)', '',
                                        post.parent.title)
        else:
            sanitized_title = regex.sub('(https?://|\n)', '', post.title)

        sanitized_title = regex.sub(r'([\]*`])', r'\\$1',
                                    sanitized_title).replace('\n', u'\u23CE')

        prefix = u"[ [SmokeDetector](//goo.gl/eLDYqh) ]"
        if GlobalVars.metasmoke_key:
            prefix_ms = u"[ [SmokeDetector](//goo.gl/eLDYqh) | [MS](//m.erwaysoftware.com/posts/by-url?url=" + \
                        post_url + ") ]"
        else:
            prefix_ms = prefix

        if not post.user_name.strip() or (not poster_url
                                          or poster_url.strip() == ""):
            s = u" {}: [{}]({}) by a deleted user on `{}`".format(
                reason, sanitized_title.strip(), post_url, shortened_site)
            username = ""
        else:
            s = u" {}: [{}]({}) by [{}]({}) on `{}`".format(
                reason, sanitized_title.strip(), post_url,
                post.user_name.strip(), poster_url, shortened_site)
            username = post.user_name.strip()

        t_metasmoke = Thread(name="metasmoke send post",
                             target=metasmoke.Metasmoke.send_stats_on_post,
                             args=(post.title_ignore_type, post_url, reasons,
                                   post.body, username, post.user_link, why,
                                   post.owner_rep, post.post_score,
                                   post.up_vote_count, post.down_vote_count))
        t_metasmoke.start()

        log('debug',
            GlobalVars.parser.unescape(s).encode('ascii', errors='replace'))
        if time.time() >= GlobalVars.blockedTime["all"]:
            datahandling.append_to_latest_questions(post.post_site,
                                                    post.post_id, post.title)
            if set(reasons).intersection(
                    GlobalVars.experimental_reasons) != set(reasons):
                if time.time() >= GlobalVars.blockedTime[
                        GlobalVars.charcoal_room_id]:
                    chq_pings = datahandling.get_user_names_on_notification_list(
                        "stackexchange.com", GlobalVars.charcoal_room_id,
                        post.post_site, GlobalVars.wrap)
                    chq_msg = prefix + s
                    chq_msg_pings = prefix + datahandling.append_pings(
                        s, chq_pings)
                    chq_msg_pings_ms = prefix_ms + datahandling.append_pings(
                        s, chq_pings)
                    msg_to_send = chq_msg_pings_ms if len(chq_msg_pings_ms) <= 500 else chq_msg_pings \
                        if len(chq_msg_pings) <= 500 else chq_msg[0:500]
                    try:
                        GlobalVars.charcoal_hq.send_message(msg_to_send)
                    except AttributeError:  # In our Test Suite
                        pass
                if not should_reasons_prevent_tavern_posting(reasons) \
                        and post.post_site not in GlobalVars.non_tavern_sites \
                        and time.time() >= GlobalVars.blockedTime[GlobalVars.meta_tavern_room_id]:
                    tavern_pings = datahandling.get_user_names_on_notification_list(
                        "meta.stackexchange.com",
                        GlobalVars.meta_tavern_room_id, post.post_site,
                        GlobalVars.wrapm)
                    tavern_msg = prefix + s
                    tavern_msg_pings = prefix + datahandling.append_pings(
                        s, tavern_pings)
                    tavern_msg_pings_ms = prefix_ms + datahandling.append_pings(
                        s, tavern_pings)
                    msg_to_send = tavern_msg_pings_ms if len(tavern_msg_pings_ms) <= 500 else tavern_msg_pings \
                        if len(tavern_msg_pings) <= 500 else tavern_msg[0:500]
                    t_check_websocket = Thread(
                        name="deletionwatcher post message if not deleted",
                        target=deletionwatcher.DeletionWatcher.
                        post_message_if_not_deleted,
                        args=((post.post_id, post.post_site,
                               "answer" if post.is_answer else "question"),
                              post_url, msg_to_send,
                              GlobalVars.tavern_on_the_meta))
                    t_check_websocket.daemon = True
                    t_check_websocket.start()
                if post.post_site == "stackoverflow.com" and reason not in GlobalVars.non_socvr_reasons \
                        and time.time() >= GlobalVars.blockedTime[GlobalVars.socvr_room_id]:
                    socvr_pings = datahandling.get_user_names_on_notification_list(
                        "stackoverflow.com", GlobalVars.socvr_room_id,
                        post.post_site, GlobalVars.wrapso)
                    socvr_msg = prefix + s
                    socvr_msg_pings = prefix + datahandling.append_pings(
                        s, socvr_pings)
                    socvr_msg_pings_ms = prefix_ms + datahandling.append_pings(
                        s, socvr_pings)
                    msg_to_send = socvr_msg_pings_ms if len(socvr_msg_pings_ms) <= 500 else socvr_msg_pings \
                        if len(socvr_msg_pings) <= 500 else socvr_msg[0:500]
                    try:
                        GlobalVars.socvr.send_message(msg_to_send)
                    except AttributeError:  # In test Suite
                        pass

            for specialroom in GlobalVars.specialrooms:
                sites = specialroom["sites"]
                if post.post_site in sites and reason not in specialroom[
                        "unwantedReasons"]:
                    room = specialroom["room"]
                    if room.id not in GlobalVars.blockedTime or time.time(
                    ) >= GlobalVars.blockedTime[room.id]:
                        room_site = room._client.host
                        room_id = int(room.id)
                        room_pings = datahandling.get_user_names_on_notification_list(
                            room_site, room_id, post.post_site, room._client)
                        room_msg = prefix + s
                        room_msg_pings = prefix + datahandling.append_pings(
                            s, room_pings)
                        room_msg_pings_ms = prefix_ms + datahandling.append_pings(
                            s, room_pings)
                        msg_to_send = room_msg_pings_ms if len(room_msg_pings_ms) <= 500 else room_msg_pings \
                            if len(room_msg_pings) <= 500 else room_msg[0:500]
                        specialroom["room"].send_message(msg_to_send)
    except:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        excepthook.uncaught_exception(exc_type, exc_obj, exc_tb)