Skip to content

Commit

Permalink
Fixed quite a lot of commands
Browse files Browse the repository at this point in the history
  • Loading branch information
quartata committed Oct 14, 2017
1 parent a911a39 commit 20df735
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
35 changes: 18 additions & 17 deletions chatcommands.py
Expand Up @@ -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))
Expand Down Expand Up @@ -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:
Expand All @@ -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)


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
"""

Expand All @@ -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
Expand Down Expand Up @@ -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 "\
Expand All @@ -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).")
Expand Down
15 changes: 8 additions & 7 deletions parsing.py
Expand Up @@ -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):
Expand Down
15 changes: 6 additions & 9 deletions test/test_parsing.py
Expand Up @@ -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'),
Expand Down

0 comments on commit 20df735

Please sign in to comment.