Skip to content

Commit

Permalink
Commands with invalid args can be edited later
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-daniels committed Dec 16, 2015
1 parent bfc0e6b commit d41d646
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions chatcommunicate.py
Expand Up @@ -105,13 +105,15 @@ def watcher(ev, wrap2):
ev.message.reply(reply)
else:
r = handle_commands(content_source.lower(), message_parts, ev_room, ev_room_name, ev_user_id, ev_user_name, wrap2, content_source, message_id)
if r is not None and r is not False:
if type(r) != tuple:
r = (True, r)
if r[1] is not None and r[0] is not False:
if wrap2.host + str(message_id) in GlobalVars.listen_to_these_if_edited:
GlobalVars.listen_to_these_if_edited.remove(wrap2.host + str(message_id))
message_with_reply = u":{} {}".format(message_id, r)
if len(message_with_reply) <= 500 or "\n" in r:
ev.message.reply(r, False)
elif r is False:
message_with_reply = u":{} {}".format(message_id, r[1])
if len(message_with_reply) <= 500 or "\n" in r[1]:
ev.message.reply(r[1], False)
elif r[0] is False:
if wrap2.host + str(message_id) not in GlobalVars.listen_to_these_if_edited:
GlobalVars.listen_to_these_if_edited.append(wrap2.host + str(message_id))
if len(GlobalVars.listen_to_these_if_edited) > 500:
Expand Down Expand Up @@ -251,7 +253,7 @@ def handle_commands(content_lower, message_parts, ev_room, ev_room_name, ev_user
elif uid == -2:
return "Error: {}".format(val)
else:
return "Invalid format. Valid format: `!!/rmblu profileurl` *or* `!!/rmblu userid sitename`."
return False, "Invalid format. Valid format: `!!/rmblu profileurl` *or* `!!/rmblu userid sitename`."
if content_lower.startswith("!!/isblu"):
uid, val = get_user_from_list_command(content_lower)
if uid > -1 and val != "":
Expand All @@ -262,7 +264,7 @@ def handle_commands(content_lower, message_parts, ev_room, ev_room_name, ev_user
elif uid == -2:
return "Error: {}".format(val)
else:
return "Invalid format. Valid format: `!!/isblu profileurl` *or* `!!/isblu userid sitename`."
return False, "Invalid format. Valid format: `!!/isblu profileurl` *or* `!!/isblu userid sitename`."
if content_lower.startswith("!!/addwlu") \
and is_privileged(ev_room, ev_user_id, wrap2):
uid, val = get_user_from_list_command(content_lower)
Expand All @@ -272,7 +274,7 @@ def handle_commands(content_lower, message_parts, ev_room, ev_room_name, ev_user
elif uid == -2:
return "Error: {}".format(val)
else:
return "Invalid format. Valid format: `!!/addwlu profileurl` *or* `!!/addwlu userid sitename`."
return False, "Invalid format. Valid format: `!!/addwlu profileurl` *or* `!!/addwlu userid sitename`."
if content_lower.startswith("!!/rmwlu") \
and is_privileged(ev_room, ev_user_id, wrap2):
uid, val = get_user_from_list_command(content_lower)
Expand All @@ -284,7 +286,7 @@ def handle_commands(content_lower, message_parts, ev_room, ev_room_name, ev_user
elif uid == -2:
return "Error: {}".format(val)
else:
return "Invalid format. Valid format: `!!/rmwlu profileurl` *or* `!!/rmwlu userid sitename`."
return False, "Invalid format. Valid format: `!!/rmwlu profileurl` *or* `!!/rmwlu userid sitename`."
if content_lower.startswith("!!/iswlu"):
uid, val = get_user_from_list_command(content_lower)
if uid > -1 and val != "":
Expand All @@ -295,15 +297,15 @@ def handle_commands(content_lower, message_parts, ev_room, ev_room_name, ev_user
elif uid == -2:
return "Error: {}".format(val)
else:
return "Invalid format. Valid format: `!!/iswlu profileurl` *or* `!!/iswlu userid sitename`."
return False, "Invalid format. Valid format: `!!/iswlu profileurl` *or* `!!/iswlu userid sitename`."
if content_lower.startswith("!!/report") \
and is_privileged(ev_room, ev_user_id, wrap2):
if len(message_parts) < 2:
return "Not enough arguments."
url = message_parts[1]
post_data = api_get_post(url)
if post_data is None:
return "That does not look like a valid post URL."
return False, "That does not look like a valid post URL."
if post_data is False:
return "Could not find data for this post in the API. Check whether the post is not deleted yet."
user = get_user_from_url(post_data.owner_url)
Expand Down Expand Up @@ -465,12 +467,12 @@ def handle_commands(content_lower, message_parts, ev_room, ev_room_name, ev_user
return "No, you are not a privileged user."
if content_lower.startswith("!!/notify"):
if len(message_parts) != 3:
return "2 arguments expected"
return False, "2 arguments expected"
user_id = int(ev_user_id)
chat_site = wrap2.host
room_id = message_parts[1]
if not room_id.isdigit():
return "Room ID is invalid."
return False, "Room ID is invalid."
else:
room_id = int(room_id)
quiet_action = ("-" in message_parts[2])
Expand All @@ -484,15 +486,15 @@ def handle_commands(content_lower, message_parts, ev_room, ev_room_name, ev_user
elif r == -1:
return "That notification configuration is already registered."
elif r == -2:
return "The given SE site does not exist."
return False, "The given SE site does not exist."
if content_lower.startswith("!!/unnotify"):
if len(message_parts) != 3:
return "2 arguments expected"
return False, "2 arguments expected"
user_id = int(ev_user_id)
chat_site = wrap2.host
room_id = message_parts[1]
if not room_id.isdigit():
return "Room ID is invalid."
return False, "Room ID is invalid."
else:
room_id = int(room_id)
quiet_action = ("-" in message_parts[2])
Expand All @@ -506,4 +508,4 @@ def handle_commands(content_lower, message_parts, ev_room, ev_room_name, ev_user
else:
return "That configuration doesn't exist."

return False # Unrecognized command, can be edited later.
return False, False # Unrecognized command, can be edited later.

0 comments on commit d41d646

Please sign in to comment.