From 20df735b402cfc5c802797c86a33d42e95a9a4ef Mon Sep 17 00:00:00 2001 From: quartata Date: Sat, 14 Oct 2017 16:42:29 -0700 Subject: [PATCH] Fixed quite a lot of commands --- chatcommands.py | 35 ++++++++++++++++++----------------- parsing.py | 15 ++++++++------- test/test_parsing.py | 15 ++++++--------- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/chatcommands.py b/chatcommands.py index 6db63b1cc4..891aa0f75b 100644 --- a/chatcommands.py +++ b/chatcommands.py @@ -92,7 +92,9 @@ def addblu(msg, user): uid, val = get_user_from_list_command(user) if int(uid) > -1 and val != "": - add_blacklisted_user((uid, val), msg.url, "") + message_url = "https://chat.{}/transcript/{}?m={}".format(msg._client.host, msg.room.id, msg.id) + + add_blacklisted_user((uid, val), message_url, "") return "User blacklisted (`{}` on `{}`).".format(uid, val) elif int(uid) == -2: raise Exception("Error: {}".format(val)) @@ -533,8 +535,8 @@ def alive(): # noinspection PyIncorrectDocstring -@command(str, privileged=True, aliases=["reportuser"]) -def allspam(url): +@command(str, whole_msg=True, privileged=True, aliases=["reportuser"]) +def allspam(msg, url): """ Reports all of a user's posts as spam :param url: @@ -545,7 +547,7 @@ def allspam(url): if user is None: raise Exception("That doesn't look like a valid user URL.") - why = u"User manually reported by *{}* in room *{}*.\n".format(ev_user_name, ev_room_name.decode('utf-8')) + why = u"User manually reported by *{}* in room *{}*.\n".format(msg.owner.name, msg.room.name) handle_user_with_all_spam(user, why) @@ -642,7 +644,7 @@ def amiprivileged(msg): :param msg: :return: A string """ - if is_privileged(msg.room, msg.owner): + if is_privileged(msg.owner, msg.room): return "\u2713 You are a privileged user." return "\u2573 " + GlobalVars.not_privileged_warning @@ -761,7 +763,7 @@ def standby(msg, location): # noinspection PyIncorrectDocstring -@command(str, aliases=["test-q, test-a, test-u, test-t"], give_name=True) +@command(str, aliases=["test-q", "test-a", "test-u", "test-t"], give_name=True) def test(content, alias_used="test"): """ Test an answer to determine if it'd be automatically reported @@ -1121,15 +1123,11 @@ def delete_force(msg): # noinspection PyIncorrectDocstring,PyUnusedLocal,PyBroadException -@command(message, reply=True, aliases=DELETE_ALIASES) +@command(message, reply=True, privileged=True, aliases=DELETE_ALIASES) def delete(msg): """ Delete a post from a chatroom, with an override for Charcoal HQ. :param msg: - :param wrap2: - :param ev_user_id: - :param ev_room: - :param kwargs: No additional arguments expected :return: None """ @@ -1140,7 +1138,10 @@ def delete(msg): "(https://charcoal-se.org/smokey/Commands"\ "#a-note-on-message-deletion) for more details." else: - return delete_force(msg) + try: + msg.delete() + except: + pass # noinspection PyIncorrectDocstring,PyUnusedLocal @@ -1285,13 +1286,14 @@ def true(feedback, msg, alias_used=["true"]): 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 alias_used == "k": - add_blacklisted_user(user) + add_blacklisted_user(user, message_url, post_url) return elif alias_used[-1] == "u": - add_blacklisted_user(user) + add_blacklisted_user(user, message_url, post_url) return "Registered " + post_type + " as true positive and blacklisted user." else: return "Registered " + post_type + " as true positive. If you want to "\ @@ -1313,12 +1315,11 @@ def why(msg): if not post_data: raise Exception("That's not a report.") - *post, _ = fetch_post_id_and_site_from_url(post_data[0]) - why = get_why_allspam(post) + why = get_why_allspam(post_data) return why if why else "" else: *post, _ = fetch_post_id_and_site_from_url(post_data[0]) - why = get_why(post) + why = get_why(post[1], post[0]) return why if why else "" raise Exception("There is no `why` data for that user (anymore).") diff --git a/parsing.py b/parsing.py index 77536cc7c5..6df008a540 100644 --- a/parsing.py +++ b/parsing.py @@ -146,16 +146,17 @@ def escape_special_chars_in_title(title_unescaped): def get_user_from_list_command(cmd): # for example, !!/addblu is a list command cmd_merged_spaces = regex.sub("\\s+", " ", cmd) cmd_parts = cmd_merged_spaces.split(" ") + uid = -1 site = "" - if len(cmd_parts) == 2: - uid_site = get_user_from_url(cmd_parts[1]) + + if len(cmd_parts) == 1: + uid_site = get_user_from_url(cmd_parts[0]) if uid_site is not None: - uid = uid_site[0] - site = uid_site[1] - elif len(cmd_parts) == 3: - uid = cmd_parts[1] - site = cmd_parts[2] + uid, site = uid_site + elif len(cmd_parts) == 2: + uid = cmd_parts[0] + site = cmd_parts[1] digit_re = regex.compile("^[0-9]+$") site_re = regex.compile(r"^(\w+\.stackexchange\.com|\w+\.(com|net))$") if not digit_re.match(uid): diff --git a/test/test_parsing.py b/test/test_parsing.py index 52f3ec4e31..ba4ddf0958 100644 --- a/test/test_parsing.py +++ b/test/test_parsing.py @@ -27,15 +27,12 @@ ('http://codegolf.stackexchange.com/users/9275', get_user_from_url, ('9275', 'codegolf.stackexchange.com')), ('http://codegolf.stackexchange.com/users/9275/', get_user_from_url, ('9275', 'codegolf.stackexchange.com')), ('//stackoverflow.com/users/1/jeff-atwood', get_user_from_url, ('1', 'stackoverflow.com')), - ('!!/addblu http://stackoverflow.com/users/0/test', get_user_from_list_command, ('0', 'stackoverflow.com')), - ('!!/rmblu http://stackoverflow.com/users/0/test', get_user_from_list_command, ('0', 'stackoverflow.com')), - ('!!/addwlu http://stackoverflow.com/users/0/test', get_user_from_list_command, ('0', 'stackoverflow.com')), - ('!!/rmwlu http://stackoverflow.com/users/0/test', get_user_from_list_command, ('0', 'stackoverflow.com')), - ('!!/addwlu http://codegolf.stackexchange.com/users/9275/programfox', get_user_from_list_command, ('9275', 'codegolf.stackexchange.com')), - ('!!/addwlu http://mathoverflow.net/users/66/ben-webster', get_user_from_list_command, ('66', 'mathoverflow.net')), - ('!!/rmblu 1234 stackoverflow.com', get_user_from_list_command, ('1234', 'stackoverflow.com')), - ('!!/rmwlu 4321 communitybuilding.stackexchange.com', get_user_from_list_command, ('4321', 'communitybuilding.stackexchange.com')), - ('!!/addblu 1 stackoverflow', get_user_from_list_command, ('1', 'stackoverflow.com')), + ('http://stackoverflow.com/users/0/test', get_user_from_list_command, ('0', 'stackoverflow.com')), + ('http://codegolf.stackexchange.com/users/9275/programfox', get_user_from_list_command, ('9275', 'codegolf.stackexchange.com')), + ('http://mathoverflow.net/users/66/ben-webster', get_user_from_list_command, ('66', 'mathoverflow.net')), + ('1234 stackoverflow.com', get_user_from_list_command, ('1234', 'stackoverflow.com')), + ('4321 communitybuilding.stackexchange.com', get_user_from_list_command, ('4321', 'communitybuilding.stackexchange.com')), + ('1 stackoverflow', get_user_from_list_command, ('1', 'stackoverflow.com')), ('http://stackoverflow.com/questions/1/title-here', url_to_shortlink, 'http://stackoverflow.com/questions/1'), ('http://stackoverflow.com/questions/1/title-here/2#2', url_to_shortlink, 'http://stackoverflow.com/a/2'), ('http://writers.stackexchange.com/questions/1/%2f%2f', url_to_shortlink, 'http://writers.stackexchange.com/questions/1'),