Files
llm-bot-framework/plugins/example_plugin.py
2026-04-29 17:41:10 -05:00

45 lines
1.4 KiB
Python

"""
Example plugin demonstrating the plugin interface.
Plugins can:
- Define metadata: PLUGIN_NAME, PLUGIN_VERSION
- Register API routes with register(app)
- Register bot commands with register_commands()
- Register background tasks with register_tasks()
"""
PLUGIN_NAME = "example_plugin"
PLUGIN_VERSION = "1.0.0"
def register(app):
"""Register API routes."""
@app.route("/api/example_plugin", methods=["GET"])
def api_example():
return {"message": "Hello from example plugin!"}, 200
def register_commands():
"""Register bot commands."""
from bot.command_registry import register_module
import ai.parser as ai_parser
async def handle_example_plugin(message, session, parsed):
await message.channel.send("Example plugin command executed!")
def validate_example_plugin_json(data):
return [] # No validation errors
register_module("example_plugin", handle_example_plugin)
ai_parser.register_validator("example_plugin", validate_example_plugin_json)
def register_tasks():
"""Register background tasks."""
# Example: modify the background loop
from bot.bot import backgroundLoop
async def example_task():
print("Example plugin background task running")
# Note: This is a simple example; in practice, you'd need a better way to extend tasks
# For now, plugins can import and modify global state if needed
pass