Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Adds ircbot command to ping staff in lab #95

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
14 changes: 13 additions & 1 deletion ircbot/plugin/lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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))
Copy link
Member

Choose a reason for hiding this comment

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

why not just send the nicks_string instead of returning the replacement?

Copy link
Contributor Author

@NotRyan NotRyan Mar 19, 2019

Choose a reason for hiding this comment

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

My reasoning was that so people being pinged could see the actual message that the ping was for in the notification itself, eg. phone users could see it without having to actually open it up. However, its true that it does bloat things a bit.