def true(feedback, msg, alias_used="true"): """ Marks a post as a true positive :param feedback: :param msg: :return: string """ post_data = get_report_data(msg) if not post_data: raise CmdException("That message is not a report.") post_url, owner_url = post_data feedback_type = TRUE_FEEDBACKS[alias_used] feedback_type.send(post_url, feedback) user = get_user_from_url(owner_url) _, _, post_type = fetch_post_id_and_site_from_url(post_url) message_url = "https://chat.{}/transcript/{}?m={}".format(msg._client.host, msg.room.id, msg.id) if user is not None: if feedback_type.blacklist: add_blacklisted_user(user, message_url, post_url) result = "Registered " + post_type + " as true positive and blacklisted user." else: result = "Registered " + post_type + " as true positive. If you want to "\ "blacklist the poster, use `trueu` or `tpu`." return result if not feedback_type.always_silent else ""
def why(msg): """ Returns reasons a post was reported :param msg: :return: A string """ post_data = get_report_data(msg) if not post_data: raise CmdException("That's not a report.") else: *post, _ = fetch_post_id_and_site_from_url(post_data[0]) why_info = get_why(post[1], post[0]) if why_info: return why_info else: raise CmdException("There is no `why` data for that user (anymore).")
def autoflagged(msg): """ Determines whether a post was automatically flagged by Metasmoke :param msg: :return: A string """ post_data = get_report_data(msg) if not post_data: raise CmdException("That's not a report.") is_autoflagged, names = Metasmoke.determine_if_autoflagged(post_data[0]) if is_autoflagged: return "That post was automatically flagged, using flags from: {}.".format(", ".join(names)) else: return "That post was **not** automatically flagged by metasmoke."
def ignore(feedback, msg): """ Marks a post to be ignored :param feedback: :param msg: :return: String """ post_data = get_report_data(msg) if not post_data: raise CmdException("That message is not a report.") post_url, _ = post_data Feedback.send_custom("ignore", post_url, feedback) post_id, site, _ = fetch_post_id_and_site_from_url(post_url) add_ignored_post((post_id, site)) return "Post ignored; alerts about it will no longer be posted."
def delete(msg): """ Delete a post from a chatroom, with an override for Charcoal HQ. :param msg: :return: None """ post_data = get_report_data(msg) if post_data and msg.room.id == 11540: return "Reports from SmokeDetector in Charcoal HQ are generally kept "\ "as records. If you really need to delete a report, please use "\ "`sd delete-force`. See [this note on message deletion]"\ "(https://charcoal-se.org/smokey/Commands"\ "#a-note-on-message-deletion) for more details." else: try: msg.delete() except: pass
def false(feedback, msg, alias_used="false"): """ Marks a post as a false positive :param feedback: :param msg: :return: String """ post_data = get_report_data(msg) if not post_data: raise CmdException("That message is not a report.") post_url, owner_url = post_data feedback_type = FALSE_FEEDBACKS[alias_used] feedback_type.send(post_url, feedback) post_id, site, post_type = fetch_post_id_and_site_from_url(post_url) add_false_positive((post_id, site)) user = get_user_from_url(owner_url) if user is not None: if feedback_type.blacklist: add_whitelisted_user(user) result = "Registered " + post_type + " as false positive and whitelisted user." elif is_blacklisted_user(user): remove_blacklisted_user(user) result = "Registered " + post_type + " as false positive and removed user from the blacklist." else: result = "Registered " + post_type + " as false positive." else: result = "Registered " + post_type + " as false positive." try: if int(msg.room.id) != int(GlobalVars.charcoal_hq.id): msg.delete() except: pass return result if not feedback_type.always_silent else ""
def false(feedback, msg, alias_used="false"): """ Marks a post as a false positive :param feedback: :param msg: :return: String """ post_data = get_report_data(msg) if not post_data: raise CmdException("That message is not a report.") post_url, owner_url = post_data feedback_type = FALSE_FEEDBACKS[alias_used] feedback_type.send(post_url, feedback) post_id, site, post_type = fetch_post_id_and_site_from_url(post_url) add_false_positive((post_id, site)) user = get_user_from_url(owner_url) if user is not None: if feedback_type.blacklist: add_whitelisted_user(user) result = "Registered " + post_type + " as false positive and whitelisted user." elif is_blacklisted_user(user): remove_blacklisted_user(user) result = "Registered " + post_type + " as false positive and removed user from the blacklist." else: result = "Registered " + post_type + " as false positive." try: if int(msg.room.id) != int(GlobalVars.charcoal_hq.id): msg.delete() except: pass return result if not feedback_type.always_silent else ""
def naa(feedback, msg, alias_used="naa"): """ Marks a post as NAA :param feedback: :param msg: :return: String """ post_data = get_report_data(msg) if not post_data: raise CmdException("That message is not a report.") post_url, _ = post_data post_id, site, post_type = fetch_post_id_and_site_from_url(post_url) if post_type != "answer": raise CmdException("That report was a question; questions cannot be marked as NAAs.") feedback_type = NAA_FEEDBACKS[alias_used] feedback_type.send(post_url, feedback) post_id, site, _ = fetch_post_id_and_site_from_url(post_url) add_ignored_post((post_id, site)) return "Recorded answer as an NAA in metasmoke." if not feedback_type.always_silent else ""