Skip to content

Commit

Permalink
Add category metadata to example plugin for HelpPlugin formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
unode committed Jul 15, 2022
1 parent 343bb2e commit c1975f0
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions mmpy_bot/plugins/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
class ExamplePlugin(Plugin):
"""Default plugin with examples of bot functionality and usage."""

@listen_to("^admin$", direct_only=True, allowed_users=["admin", "root"])
@listen_to(
"^admin$", direct_only=True, allowed_users=["admin", "root"], category="admin"
)
async def users_access(self, message: Message):
"""Showcases a function with restricted access."""
self.driver.reply_to(message, "Access allowed!")

@listen_to("^busy|jobs$", re.IGNORECASE, needs_mention=True)
@listen_to("^busy|jobs$", re.IGNORECASE, needs_mention=True, category="admin")
async def busy_reply(self, message: Message):
"""Show the number of busy worker threads."""
busy = self.driver.threadpool.get_busy_workers()
Expand All @@ -29,14 +31,15 @@ async def busy_reply(self, message: Message):
f"Number of busy worker threads: {busy}",
)

@listen_to("hello_click", needs_mention=True)
@listen_to("hello_click", needs_mention=True, category="click")
@click.command(help="An example click command with various arguments.")
@click.argument("POSITIONAL_ARG", type=str)
@click.option("--keyword-arg", type=float, default=5.0, help="A keyword arg.")
@click.option("-f", "--flag", is_flag=True, help="Can be toggled.")
def hello_click(
self, message: Message, positional_arg: str, keyword_arg: float, flag: bool
):
"""A click function documented via docstring."""
response = (
"Received the following arguments:\n"
f"- positional_arg: {positional_arg}\n"
Expand Down Expand Up @@ -74,8 +77,9 @@ async def hello_file(self, message: Message):
file.write_text("Hello from this file!")
self.driver.reply_to(message, "Here you go", file_paths=[file])

@listen_to("^!hello_webhook$", re.IGNORECASE)
@listen_to("^!hello_webhook$", re.IGNORECASE, category="webhook")
async def hello_webhook(self, message: Message):
"""A webhook that says hello."""
self.driver.webhooks.call_webhook(
"eauegoqk4ibxigfybqrsfmt48r",
options={
Expand Down Expand Up @@ -111,7 +115,9 @@ async def ping_reply(self, message: Message):
"""Pong."""
self.driver.reply_to(message, "pong")

@listen_to("^reply at (.*)$", re.IGNORECASE, needs_mention=True)
@listen_to(
"^reply at (.*)$", re.IGNORECASE, needs_mention=True, category="schedule"
)
def schedule_once(self, message: Message, trigger_time: str):
"""Schedules a reply to be sent at the given time.
Expand All @@ -128,7 +134,12 @@ def schedule_once(self, message: Message, trigger_time: str):
except ValueError as e:
self.driver.reply_to(message, str(e))

@listen_to("^schedule every ([0-9]+)$", re.IGNORECASE, needs_mention=True)
@listen_to(
"^schedule every ([0-9]+)$",
re.IGNORECASE,
needs_mention=True,
category="schedule",
)
def schedule_every(self, message: Message, seconds: int):
"""Schedules a reply every x seconds. Use the `cancel jobs` command to stop.
Expand All @@ -139,7 +150,7 @@ def schedule_every(self, message: Message, seconds: int):
self.driver.reply_to, message, f"Scheduled message every {seconds} seconds!"
)

@listen_to("^cancel jobs$", re.IGNORECASE, needs_mention=True)
@listen_to("^cancel jobs$", re.IGNORECASE, needs_mention=True, category="schedule")
def cancel_jobs(self, message: Message):
"""Cancels all scheduled jobs, including recurring and one-time events."""
schedule.clear()
Expand Down

0 comments on commit c1975f0

Please sign in to comment.