scrapinghub / slackbot

A chat bot for Slack (https://slack.com).
MIT License
1.26k stars 396 forks source link

Limit slackbot responce to certain channel #152

Closed q0u04bj3 closed 6 years ago

q0u04bj3 commented 7 years ago

I know how to use "listen_to" when anyone mentions certain words in a comment. Is it possible to limit this to certain channels?

roidayan commented 7 years ago

I have not started using this bot yet so there might be a better and/or cleaner way but I think you can check the channel name in the callback like this:

message.channel._body['name']

jtatum commented 6 years ago

I use a decorator like this:


def in_allowed_channel(func):
    def allowed_channel(message, *args, **kwargs):
        if message.body['channel'] not in ALLOWED_CHANNELS:
            message.reply('Please ask that in <#C12345|#botchannel>'
            return
        return func(message, *args, **kwargs)

    # Copy the docstring to the decorated func so help works
    allowed_channel.__doc__ = func.__doc__
    return allowed_channel```