Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add role changing for custom commands #292

Closed
wants to merge 5 commits into from

Conversation

Innectic
Copy link
Member

@Innectic Innectic commented May 3, 2017

What does this change?

This adds a new command !command permission <command> [role] to set the role of the command.

Closes #249

DO NOT MERGE UNTIL THE API SUPPORTS THIS! *stares at @RPiAwesomeness *

Requirements

  • Only PG-rated language used (code, commits, etc.)
  • Descriptive commit messages
  • Changes have been tested
  • Changes do not break any existing functionalities

@Innectic Innectic added this to the v0.4.1 milestone May 3, 2017
@Innectic Innectic requested review from RPiAwesomeness and 2Cubed May 3, 2017 04:23
@Innectic
Copy link
Member Author

Innectic commented May 3, 2017

I don't have any idea why this is failing, seems to be a TLS issue with beam.

Copy link
Member

@2Cubed 2Cubed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. Would like to see a few changes, though, especially in relation to the rename syntax discussed on #249. 🙂

"""Update command attributes."""

return await self.api.patch("/user/{token}/command/{command}".format(
token=self.api.token, command=command), data=json.dumps(value))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if the type signature was based more on values, rather than just json.dumpsing value.

For example, something like:

async def update(self, command, name=None, role=None):

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - I copied this update function from configs. Keeping it the way it is incase we ever want to update something else about the command, say the name.

@@ -91,3 +117,30 @@ class Meta(Command):
response = await self.api.command.update_count(command, action_string)
if response.status == 200:
return "Count updated."

@Command.command(role="moderator")
async def permission(self, command: r'?command', role=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we want to use the rename syntax (in discussion on #249), rather than permission?

!command rename stuff things
!command rename test +test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did, but not using that for permissions. That becomes a problem of having to readd the command to change both, and right now I would prefer if the two were separated.

async def permission(self, command: r'?command', role=None):
"""Change the role of a command."""

if role is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. If we switch to rename, we should do something similar.

> !command rename highfive
< Command !highfive (User): "You get a highfive, %ARGS%!"



def _role_id(role_name):
return _REVERSED_ROLES[role_name] if role_name in _REVERSED_ROLES else -1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use None rather than -1 here, in case -1 becomes an actual thing at some point™. (Global banned, or muted, or whatever.)

@@ -87,3 +87,21 @@ Otherwise, `action` may begin with either a `+` or `-`, to increase or decrease
[MindlessPuppetz] !command count derp +12
[CactusBot] Count updated.
```

## `!command role <command> [role]`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay, docs! (Nice choices for usernames, BTW.)

@2Cubed
Copy link
Member

2Cubed commented May 3, 2017

P.S. Unit tests are trying to connect to Beam in the spam handler... that's badsauce. We should fix that in another PR and merge it in.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 58.581% when pulling 6282f16 on feature/command-permission-change into 4df8373 on develop.

@Innectic Innectic closed this Jul 15, 2017
@Innectic Innectic deleted the feature/command-permission-change branch July 15, 2017 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants