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

Feature request: @allowed_channels decorator similar to @allowed_users #88

Closed
ghbacct opened this issue Dec 27, 2018 · 2 comments
Closed
Assignees
Labels
enhancement New feature or request

Comments

@ghbacct
Copy link

ghbacct commented Dec 27, 2018

Feature request:
To introduce a decorator @allowed_channels that takes a list of white-listed channels, similarly to the @allowed_users decorator.

Something similar to the following pseudocode:

def allowed_channels(*channels):
    """Decorator that limits the bot to the specified list of channels."""
    def plugin(func):
        def wrapper(message, *args, **kw):
            is_direct_message = message.is_direct_message()
            is_in_allowed_channel = message.get_channel_name() in channels
            if not is_direct_message and not is_in_allowed_channel:
                return message.reply(f'This bot can only be used inside the following channel(s): {", ".join(channels)}.')
            return func(message, *args, **kw)

        return wrapper

    return plugin
@ghbacct ghbacct changed the title Feature request: @allowed_channels decorator similar to @allowed_users Feature request: @allowed_channels decorator similar to @allowed_users Dec 27, 2018
@seLain seLain added the enhancement New feature or request label Jan 1, 2019
@attzonko attzonko self-assigned this Jan 20, 2019
attzonko added a commit that referenced this issue Jan 21, 2019
As per enhancement request #88 I am adding the ability to limit
bot plugin functions so specific channels. You can use either the
channel display name or the url name.
attzonko added a commit that referenced this issue Jan 22, 2019
* Adding new decorator allowed_channels

As per enhancement request #88 I am adding the ability to limit
bot plugin functions so specific channels. You can use either the
channel display name or the url name.

* Doing some flake8 cleanup
* Reducing complexity score flagged by codeclimate
@ghbacct
Copy link
Author

ghbacct commented Jan 31, 2019

@attzonko thank you for the enhancement!

There's one issue however: using @allowed_channels prevents the plugin from being used in DMs.
Is that intentional? Seems to me like an edge case that just slipped by.

@attzonko
Copy link
Owner

Yes edge case indeed. DMs are uniquely named channels. Depending on how we want this enhancement to work, we can update the code to allow the plugin to work in DMs regardless of allowed_channels(), either way we should document the intent.

@attzonko attzonko reopened this Feb 3, 2019
@attzonko attzonko closed this as completed Feb 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants