diff --git a/ircbot/plugin/lab.py b/ircbot/plugin/lab.py index 43c936c..edeb3b0 100644 --- a/ircbot/plugin/lab.py +++ b/ircbot/plugin/lab.py @@ -6,7 +6,7 @@ def register(bot): bot.listen(r'is ([a-z]+) in the lab', in_lab, require_mention=True) bot.listen(r"(who is|who's) in the lab", who_is_in_lab, require_mention=True) - + bot.listen(r"@labstaff", ping_lab_staff, require_mention=False) def in_lab(bot, msg): """Check if a staffer is in the lab.""" @@ -44,3 +44,15 @@ def who_is_in_lab(bot, msg): len(staff), staff_list, )) + +def ping_lab_staff(bot, msg): + """Ping everyone who is currently in the lab.""" + staff = {session.user for session in staff_in_lab()} + channel_users = bot.channels[msg.channel].users() + staff_nicks = set() + + for staff_username in staff: + staff_nicks = staff_nicks | {nick for nick in channel_users if nick.startswith(staff_username)} + nicks_string = ', '.join(sorted(staff_nicks)) + + msg.respond(msg.text.replace("@labstaff", nicks_string))