-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
I don't have any idea why this is failing, seems to be a TLS issue with beam. |
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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.dumps
ing value
.
For example, something like:
async def update(self, command, name=None, role=None):
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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%!"
cactusbot/commands/magic/command.py
Outdated
|
||
|
||
def _role_id(role_name): | ||
return _REVERSED_ROLES[role_name] if role_name in _REVERSED_ROLES else -1 |
There was a problem hiding this comment.
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]` |
There was a problem hiding this comment.
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.)
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. |
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