Skip to content

Commit

Permalink
✨ wiitl plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhiljha committed Apr 23, 2024
1 parent 980d900 commit a00e3e9
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .transpire.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
}

Expand Down
9 changes: 9 additions & 0 deletions sopel/plugins/README.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions sopel/plugins/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,17 @@ def check(bot, trigger):
else:
created = "unknown"

bot.reply(
bot.say(
"{user} ({uid}) | {name} | created {created} | groups: {groups}".format(
user=user,
uid=attrs["uidNumber"],
name=attrs["cn"][0],
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):
Expand Down
50 changes: 50 additions & 0 deletions sopel/plugins/lab.py
Original file line number Diff line number Diff line change
@@ -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,
),
)

0 comments on commit a00e3e9

Please sign in to comment.