Skip to content

Commit

Permalink
labhub.py: Alert when @mention is not in room
Browse files Browse the repository at this point in the history
The fix introduces removal of is_room_member
function and instead uses callback_message to warn
whenever `@mention` is not in room.

Closes #603
  • Loading branch information
abhishalya authored and Abhinav Kaushlya committed Mar 8, 2019
1 parent 1de93b6 commit 9cdc29a
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions plugins/labhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([@]<username> [to <team>]|me)')
Expand Down Expand Up @@ -143,10 +139,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(
Expand Down Expand Up @@ -193,6 +185,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)
Expand Down

0 comments on commit 9cdc29a

Please sign in to comment.