diff --git a/.transpire.py b/.transpire.py index af8b7e7..d331160 100644 --- a/.transpire.py +++ b/.transpire.py @@ -407,6 +407,9 @@ def objects(): "check.py": Path(__file__) .parent.joinpath("sopel", "plugins", "check.py") .read_text(), + "lab.py": Path(__file__) + .parent.joinpath("sopel", "plugins", "lab.py") + .read_text(), }, } diff --git a/sopel/plugins/README.md b/sopel/plugins/README.md new file mode 100644 index 0000000..e6dc406 --- /dev/null +++ b/sopel/plugins/README.md @@ -0,0 +1,9 @@ +# plugins + +To port things from ircbot... + +- replace `msg.match` with `trigger` +- replace `msg.respond` with `bot.reply` + - if `ping=False` in the `msg.respond` replace it with `bot.say` +- add any extra python packages needed to the dockerfile (`pipx inject`) +- add the plugin to `.transpire.py` along with the others diff --git a/sopel/plugins/check.py b/sopel/plugins/check.py index 29bcda5..3417ea3 100644 --- a/sopel/plugins/check.py +++ b/sopel/plugins/check.py @@ -41,7 +41,7 @@ def check(bot, trigger): else: created = "unknown" - bot.reply( + bot.say( "{user} ({uid}) | {name} | created {created} | groups: {groups}".format( user=user, uid=attrs["uidNumber"], @@ -49,10 +49,9 @@ def check(bot, trigger): created=created, groups=", ".join(groups), ), - ping=False, ) else: - bot.reply(f"{user} does not exist", ping=False) + bot.say(f"{user} does not exist") def alphanum(word): diff --git a/sopel/plugins/lab.py b/sopel/plugins/lab.py new file mode 100644 index 0000000..7860718 --- /dev/null +++ b/sopel/plugins/lab.py @@ -0,0 +1,50 @@ +"""Get information about the lab.""" + +from ocflib.lab.stats import staff_in_lab +from ocflib.lab.stats import users_in_lab_count + +from sopel import plugin + + +@plugin.rule(r"is ([a-z]+) in the lab") +def in_lab(bot, trigger): + """Check if a staffer is in the lab.""" + username = trigger.group(1).strip() + for session in staff_in_lab(): + if username == session.user: + bot.reply(f"{username} is in the lab") + break + else: + bot.reply(f"{username} is not in the lab") + + +def _prevent_ping(staffer): + """Hack to prevent pinging the person by inserting a zero-width no-break space in their name.""" + return staffer[0] + "\u2060" + staffer[1:] + + +@plugin.rule(r"(who is|who's) in the lab", r"(?i)w+i+t+l+") +def who_is_in_lab(bot, trigger): + """Report on who is currently in the lab.""" + staff = {session.user for session in staff_in_lab()} + total = users_in_lab_count() + + if total != 1: + are_number_people = f"are {total} people" + else: + are_number_people = "is 1 person" + + if staff: + staff_list = ": {}".format( + ", ".join(sorted(_prevent_ping(staffer) for staffer in staff)) + ) + else: + staff_list = "" + + bot.reply( + "there {} in the lab, including {} staff{}".format( + are_number_people, + len(staff), + staff_list, + ), + )