feat: initial implementation
Asyncio IRC bot with decorator-based plugin system. Zero external dependencies, Python 3.11+. - IRC protocol: message parsing, formatting, async TCP/TLS connection - Plugin system: @command and @event decorators, file-based loading - Bot orchestrator: connect, dispatch, reconnect, nick recovery - CLI: argparse entry point with TOML config - Built-in plugins: ping, help, version, echo - 28 unit tests for parser and plugin system
This commit is contained in:
39
plugins/core.py
Normal file
39
plugins/core.py
Normal file
@@ -0,0 +1,39 @@
|
||||
"""Core plugin: ping, help, version."""
|
||||
|
||||
from derp import __version__
|
||||
from derp.plugin import command
|
||||
|
||||
|
||||
@command("ping", help="Check if the bot is alive")
|
||||
async def cmd_ping(bot, message):
|
||||
"""Respond with pong."""
|
||||
await bot.reply(message, "pong")
|
||||
|
||||
|
||||
@command("help", help="List commands or show command help")
|
||||
async def cmd_help(bot, message):
|
||||
"""Show available commands or help for a specific command.
|
||||
|
||||
Usage: !help [command]
|
||||
"""
|
||||
parts = message.text.split(None, 2)
|
||||
if len(parts) > 1:
|
||||
# Help for a specific command
|
||||
cmd_name = parts[1].lower().lstrip(bot.prefix)
|
||||
handler = bot.registry.commands.get(cmd_name)
|
||||
if handler:
|
||||
help_text = handler.help or "No help available."
|
||||
await bot.reply(message, f"{bot.prefix}{cmd_name} -- {help_text}")
|
||||
else:
|
||||
await bot.reply(message, f"Unknown command: {cmd_name}")
|
||||
return
|
||||
|
||||
# List all commands
|
||||
names = sorted(bot.registry.commands.keys())
|
||||
await bot.reply(message, f"Commands: {', '.join(bot.prefix + n for n in names)}")
|
||||
|
||||
|
||||
@command("version", help="Show bot version")
|
||||
async def cmd_version(bot, message):
|
||||
"""Report the running version."""
|
||||
await bot.reply(message, f"derp {__version__}")
|
||||
Reference in New Issue
Block a user