Skip to content

Commit

Permalink
labhub: Maintain a list of invited users
Browse files Browse the repository at this point in the history
Closes #225
  • Loading branch information
meetmangukiya committed Jul 25, 2017
1 parent 319fd50 commit 6d14a83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion plugins/labhub.py
Expand Up @@ -78,6 +78,8 @@ def __init__(self, bot, name=None):
else:
self.REPOS.update(self.gl_repos)

self.invited_users = set()

@property
def TEAMS(self):
return self._teams
Expand Down Expand Up @@ -121,11 +123,13 @@ def callback_message(self, msg):
"""Invite the user whose message includes the holy 'hello world'"""
if re.search(r'hello\s*,?\s*world', msg.body, flags=re.IGNORECASE):
user = msg.frm.nick
if not self.TEAMS[self.GH_ORG_NAME + ' newcomers'].is_member(user):
if (not self.TEAMS[self.GH_ORG_NAME + ' newcomers'].is_member(user)
and user not in self.invited_users):
# send the invite
self.send(msg.frm,
self.INVITE_SUCCESS['newcomers'].format(user))
self.TEAMS[self.GH_ORG_NAME + ' newcomers'].invite(user)
self.invited_users.add(user)

@re_botcmd(pattern=r'(?:new|file) issue ([\w-]+?)(?: |\n)(.+?)(?:$|\n((?:.|\n)*))', # Ignore LineLengthBear, PyCodeStyleBear
flags=re.IGNORECASE)
Expand Down
6 changes: 5 additions & 1 deletion tests/labhub_test.py
@@ -1,5 +1,6 @@
import logging
import os
import queue
import unittest
from unittest.mock import Mock, MagicMock, create_autospec, PropertyMock

Expand Down Expand Up @@ -67,7 +68,10 @@ def test_hello_world_callback(self):
labhub.TEAMS = teams
self.mock_team.is_member.return_value = False
testbot.assertCommand('hello, world', 'newcomer')
testbot.assertCommand('helloworld', 'newcomer')
# Since the user won't be invited again, it'll timeout waiting for a
# response.
with self.assertRaises(queue.Empty):
testbot.assertCommand('helloworld', 'newcomer')
self.mock_team.invite.assert_called_with(None)

def test_create_issue_cmd(self):
Expand Down

0 comments on commit 6d14a83

Please sign in to comment.