From d34c3847f4e8c5049fa402f75dbd2ad666c20a27 Mon Sep 17 00:00:00 2001 From: abhishalya Date: Tue, 23 Oct 2018 10:29:31 +0530 Subject: [PATCH] labhub.py: Alert when @mention is not in room The fix introduces removal of is_room_member function and instead uses callback_message to warn whenever `@mention` is not in room. Closes https://github.com/coala/corobo/issues/603 --- plugins/labhub.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/plugins/labhub.py b/plugins/labhub.py index 1d702b71..7c78a888 100644 --- a/plugins/labhub.py +++ b/plugins/labhub.py @@ -108,10 +108,6 @@ def is_team_member(self, user, team): teams = self.team_mapping() return teams[team].is_member(user) - @staticmethod - def is_room_member(invitee, msg): - return invitee in msg.frm.room.occupants - # Ignore LineLengthBear, PycodestyleBear @re_botcmd(pattern=r'^(?:(?:welcome)|(?:inv)|(?:invite))\s+@?([\w-]+)(?:\s+(?:to)\s+(\w+))?$', re_cmd_name_help='invite ([@] [to ]|me)') @@ -140,10 +136,6 @@ def invite_cmd(self, msg, match): def invite(invitee, team): self.team_mapping()[team].invite(invitee) - if not self.is_room_member(invitee, msg): - yield '@{} is not a member of this room.'.format(invitee) - return - if is_maintainer: invite(invitee, team) yield tenv().get_template( @@ -190,6 +182,26 @@ def callback_message(self, msg): self.send(msg.frm, response) self.hello_world_users.add(user) + mentioned = [] + room_members = msg.frm.room.occupants + words = msg.body.split() + for word in words: + if word.startswith('@'): + mentioned.append(word[1:]) + + warn = False + for mention in mentioned: + is_member = False + for room_member in room_members: + if room_member.username == mention: + is_member = True + if not is_member: + warn = True + + if warn: + self.send(msg.frm, 'WARNING: Someone mentioned is ' + 'not a member of this room.') + @re_botcmd(pattern=r'(?:new|file) issue ([\w\-\.]+?)(?: |\n)(.+?)(?:$|\n((?:.|\n)*))', # Ignore LineLengthBear, PyCodeStyleBear re_cmd_name_help='new issue repo-name title\n[description]', flags=re.IGNORECASE)