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

filters.py: Filter required users #517

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
IGNORE_USERNAMES = os.environ.get("IGNORE_USERNAMES",
'co-robo coala-bot').split()

RESP_ONLY_REQ_USERS = False

REQUIRED_USERS = []

DIVERT_TO_PRIVATE = ('help', )

ROOMS_TO_JOIN = (
Expand Down
16 changes: 16 additions & 0 deletions tests/filters_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import queue

from tests.isolated_testcase import IsolatedTestCase


class FiltersTest(IsolatedTestCase):

def test_filter_users(self):
self.bot_config.RESP_ONLY_REQ_USERS = False
Copy link
Member Author

Choose a reason for hiding this comment

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

@nvzard Am I doing anything wrong here?

Copy link
Member

@nvzard nvzard Aug 21, 2018

Choose a reason for hiding this comment

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

@Vamshi99 IsolatedTestCase loads all the plugins present in plugins/ directory except LabHub, hence this filter is not loaded by the bot since it is in utils/ dir.

self.bot_config.REQUIRED_USERS = []
self.assertCommand('!help', 'All commands')
self.bot_config.RESP_ONLY_REQ_USERS = True
self.bot_config.REQUIRED_USERS = ['testuser']
self.bot_config.BOT_IDENTITY['nickname'] = 'testuser'
with self.assertRaises(queue.Empty):
self.assertCommand('!help', 'All commands')
5 changes: 4 additions & 1 deletion utils/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def filters(self, msg, cmd, args, dry_run):
return msg, cmd, args

@cmdfilter
def filter_ignored_users(self, msg, cmd, args, dry_run):
def filter_users(self, msg, cmd, args, dry_run):
if msg.frm.nick in self.bot_config.IGNORE_USERNAMES:
return None, None, None
if (msg.frm.nick not in self.bot_config.REQUIRED_USERS and
self.bot_config.RESP_ONLY_REQ_USER):
return None, None, None
return msg, cmd, args