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

labhub.py: Alert when @mention is not in room #630

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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
Copy link
Member Author

Choose a reason for hiding this comment

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

We need to fetch the people once reducing the number of API calls and eventually update the list as soon as there are new people in the room, will improve this later on once we've fixed backend.

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