From c72b1c96f4b4c982d089e59d8573b3b0ea0a8e55 Mon Sep 17 00:00:00 2001 From: Ryan Chan Date: Fri, 1 Feb 2019 17:35:32 -0800 Subject: [PATCH] Adds function to ping staff in lab --- ircbot/plugin/lab.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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))