Skip to content

Commit a8c009b

Browse files
committed
filters.py: Filter required users
If RESP_ONLY_REQ_USERS configuration is true, then stop responding to users other than those in the REQUIRED_USERS list in config. Closes #515
1 parent ce9cf18 commit a8c009b

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
IGNORE_USERNAMES = os.environ.get("IGNORE_USERNAMES",
8888
'co-robo coala-bot').split()
8989

90+
RESP_ONLY_REQ_USERS = False
91+
92+
REQUIRED_USERS = []
93+
9094
DIVERT_TO_PRIVATE = ('help', )
9195

9296
ROOMS_TO_JOIN = (

tests/filters_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import queue
2+
3+
from tests.isolated_testcase import IsolatedTestCase
4+
5+
6+
class FiltersTest(IsolatedTestCase):
7+
8+
def test_filter_users(self):
9+
self.bot_config.RESP_ONLY_REQ_USERS = False
10+
self.bot_config.REQUIRED_USERS = []
11+
self.assertCommand('!help', 'All commands')
12+
self.bot_config.RESP_ONLY_REQ_USERS = True
13+
self.bot_config.REQUIRED_USERS = ['testuser']
14+
self.bot_config.BOT_IDENTITY['nickname'] = 'testuser'
15+
with self.assertRaises(queue.Empty):
16+
self.assertCommand('!help', 'All commands')

utils/filters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def filters(self, msg, cmd, args, dry_run):
2323
return msg, cmd, args
2424

2525
@cmdfilter
26-
def filter_ignored_users(self, msg, cmd, args, dry_run):
26+
def filter_users(self, msg, cmd, args, dry_run):
2727
if msg.frm.nick in self.bot_config.IGNORE_USERNAMES:
2828
return None, None, None
29+
if (msg.frm.nick not in self.bot_config.REQUIRED_USERS and
30+
self.bot_config.RESP_ONLY_REQ_USER):
31+
return None, None, None
2932
return msg, cmd, args

0 commit comments

Comments
 (0)