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

Changing allowed channels functionality to ignore direct messages #98

Merged
merged 2 commits into from
Feb 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mmpy_bot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def wrapper(message, *args, **kw):
# Check display_name first
disp_name = message.get_channel_display_name()
url_name = message.get_channel_name()
if not {disp_name, url_name} & set(allowed_channels_list):
is_direct_message = message.is_direct_message()
if (not is_direct_message) and (not {disp_name, url_name} & set(allowed_channels_list)):
return message.reply(
"`This plugin only allowed in these channels:{}`"
.format(list(allowed_channels_list)))
Expand Down
6 changes: 6 additions & 0 deletions tests/behavior_tests/test_allowed_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@


def test_allowed_channels(driver): # noqa: F811

driver.send_direct_message('allowed_channel', tobot=True)
driver.wait_for_bot_direct_message(
'Driver in channel allowed!')

driver.send_private_channel_message('allowed_channel', tobot=True)
driver.wait_for_bot_private_channel_message(
'Driver in channel allowed!', tosender=True)

driver.send_private_channel_message('not_allowed_channel', tobot=True)
try:
driver.wait_for_bot_private_channel_message(
Expand Down