Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ Two styles coexist. Prefer **new-style** (class-based) for new plugins.
**Old-style** (function-based): `COMMANDS` dict + underscore-prefixed async functions:
```python
PLUGIN_ID = "say"


async def _say(router, name, params, channel, userdata, rank, is_channel): ...


COMMANDS = {"say": {"execute": _say, "permission": Permission.HIDDEN}}
```

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ from command_router import Permission, command, subcommand

PLUGIN_ID = "greet"


class Plugin:
async def setup(self, router, startup):
"""Called on load (startup=True) or reload (startup=False)."""
Expand Down Expand Up @@ -152,9 +153,11 @@ from command_router import Permission

PLUGIN_ID = "say"


async def _say(router, name, params, channel, userdata, rank, is_channel):
await router.send_chat_message(router.send, channel, " ".join(params))


COMMANDS = {
"say": {"execute": _say, "permission": Permission.HIDDEN},
}
Expand Down
4 changes: 2 additions & 2 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ Registered in `CommandRouter.__init__()`:

```python
self.events = {
"time": TimerEvent(), # Periodic timers
"chat": MsgEvent(), # Channel messages
"time": TimerEvent(), # Periodic timers
"chat": MsgEvent(), # Channel messages
"channeljoin": StandardEvent(),
"channelpart": StandardEvent(),
"channelkick": StandardEvent(),
Expand Down
15 changes: 9 additions & 6 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ The `Permission` enum is defined in `command_router.py`:

```python
class Permission(IntEnum):
GUEST = 0 # Anyone
VOICED = 1 # + and above
OP = 2 # @ and above
ADMIN = 3 # Bot operator (admin list + registered)
HIDDEN = 4 # Not shown in command list
GUEST = 0 # Anyone
VOICED = 1 # + and above
OP = 2 # @ and above
ADMIN = 3 # Bot operator (admin list + registered)
HIDDEN = 4 # Not shown in command list
```

When a user invokes a command, the PRIVMSG handler checks `rank >= cmd.permission`. The user's rank is determined by their channel mode (`+`, `@`) or admin status.
Expand All @@ -166,6 +166,7 @@ async def _my_timer(router, channels):
for channel in channels:
await router.send_message(channel, "Tick!")


# In setup() or a command handler:
router.events["time"].add_event("MyTimer", 60, _my_timer, ["#mychannel"])
```
Expand All @@ -185,6 +186,7 @@ async def _on_chat(router, channels, userdata, message, channel):
if "hello" in message.lower():
await router.send_message(channel, "Hi there!")


router.events["chat"].add_event("Greeter", _on_chat, channel=[])
```

Expand All @@ -197,7 +199,7 @@ Note: `userdata` in chat event callbacks is a `dict` with keys `name`, `ident`,
### Event management

```python
router.events["time"].event_exists("MyTimer") # bool
router.events["time"].event_exists("MyTimer") # bool
router.events["time"].remove_event("MyTimer")
router.events["time"].add_channel("MyTimer", "#new")
router.events["time"].remove_channel("MyTimer", "#old")
Expand Down Expand Up @@ -242,6 +244,7 @@ async def _my_worker(handle, pipe):
# Do work...
await pipe.put({"result": "done"})


# Start the task:
router.task_pool.add_task("myWorker", _my_worker)

Expand Down
Loading