Skip to content

Commit

Permalink
Merge pull request #178 from AWegnerGitHub/branch_commandfixes
Browse files Browse the repository at this point in the history
Decorator fix to return response
  • Loading branch information
normalhuman committed Jul 20, 2016
2 parents e943093 + 12fa31a commit c5c2676
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion chatcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def run_command(ev_room, ev_user_id, wrap2, *args, **kwargs):
kwargs['wrap2'] = wrap2
return function(*args, **kwargs)
else:
return False
return Response(command_status=False,
message="Permission Denied. See [the Privileges wiki page](" + GlobalVars.bot_repository +
"/wiki/Privileges) for information on what privileges are and what is expected.")

return run_command

Expand Down
13 changes: 8 additions & 5 deletions chatcommunicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,13 @@ def watcher(ev, wrap2):
result = Response(command_status=True, message=None)
if result.command_status and result.message:
reply += result.message + os.linesep
if result.message is None:
reply += "<processed without return value>" + os.linesep
amount_none += 1
if result.command_status is False:
reply += "<unrecognized command>" + os.linesep
amount_unrecognized += 1
if result.message is None and result.command_status is not False:
reply += "<processed without return value>" + os.linesep
amount_none += 1

else:
reply += "<skipped>" + os.linesep
amount_skipped += 1
Expand Down Expand Up @@ -209,8 +210,10 @@ def handle_commands(content_lower, message_parts, ev_room, ev_room_name, ev_user
'second_part_lower': second_part_lower,
'wrap2': wrap2,
}
if second_part_lower in subcmds:
return subcmds[second_part_lower](**subcommand_parameters)
if second_part_lower not in subcmds:
return Response(command_status=False, message=None) # Unrecognized subcommand

return subcmds[second_part_lower](**subcommand_parameters)

# Process additional commands
command_parameters = {
Expand Down
7 changes: 7 additions & 0 deletions test/test_chatcommunicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ def test_privileged_users():
assert reply_value == "No, you are not a privileged user. See [the Privileges wiki page](//github.com/Charcoal-SE/SmokeDetector/wiki/Privileges) for information on what privileges are and what is expected."


def test_unprivileged_denial():
event = mock_event("!!/rmwlu http://meta.stackexchange.com/users/237685/hichris123", 1, 11540, "Charcoal HQ", -5, u"Some bot")
watcher(event, client.Client())
assert reply_value == "Permission Denied. See [the Privileges wiki page](" + GlobalVars.bot_repository +\
"/wiki/Privileges) for information on what privileges are and what is expected."


def test_test_command():
event = mock_event("!!/test", 1, 11540, "Charcoal HQ", 59776, u"Doorknob 冰")
watcher(event, client.Client())
Expand Down

0 comments on commit c5c2676

Please sign in to comment.