|
@@ -147,29 +147,48 @@ and run
|
|
|
./mkplugin my_cool_plugin
|
|
|
```
|
|
|
|
|
|
-This will end by printing something like
|
|
|
+This script will generate a file at `src/plugins/my_cool_plugin.py` containing (approximately)
|
|
|
|
|
|
-```
|
|
|
-Action required: Insert the following line into the [plugins] section of config/config.toml to activate my_cool_plugin
|
|
|
-my_cool_plugin = [ "my_cool_plugin"]
|
|
|
+```python
|
|
|
+from command_system import as_plugin
|
|
|
+
|
|
|
+
|
|
|
+@as_plugin
|
|
|
+def my_cool_plugin():
|
|
|
+ return "Hello, world!"
|
|
|
```
|
|
|
|
|
|
-Do as it says and open `config/config.toml` and add the printed line to the `[plugins]` map.
|
|
|
+The script also adds an `import plugins.my_cool_plugin` to `src/plugins/__init__.py`, so if you are
|
|
|
+reverting what this script did, remember to remove this import from that file. Only plugins imported
|
|
|
+in that top level module file will be available for the application, so if creating a plugin manually,
|
|
|
+you will need to add an import to that file.
|
|
|
|
|
|
-This script will also generate a file at `src/plugins/my_cool_plugin.py` containing
|
|
|
+The above script is the most basic possible rollbot plugin, which will simply respond with
|
|
|
+`Hello, world!` when it receives a message starting with `!my_cool_plugin`. The actual wiring of
|
|
|
+the plugin is handled by the `as_plugin` decorator, which performs all of the following:
|
|
|
+ - Inspects the name of your function and turns that into the command word. This can be overidden by
|
|
|
+ passing a single, string argument to `as_plugin`, which is detailed below.
|
|
|
+ - Inspects the arguments of your function, to determine what, if any, rollbot components need to be
|
|
|
+ passed into your function, which are detailed below.
|
|
|
+ - Wraps your plugin function to take any return values that are not instances of `RollbotResponse`
|
|
|
+ and convert them to strings, before wrapping them in a `RollbotResponse` with default settings, which
|
|
|
+ is detailed below.
|
|
|
+ - Generates a `RollbotPlugin` extension class which overrides the `on_command` method to call
|
|
|
+ your plugin function appropriately, and returns this class from the decorator, effectively assigning
|
|
|
+ it to the `my_cool_plugin` variable *instead* of your plugin function, which is what allows your
|
|
|
+ plugin to be found dynamically after just importing the plugin module
|
|
|
|
|
|
-```python
|
|
|
-from command_system import as_plugin, RollbotResponse
|
|
|
+#### Command Naming
|
|
|
|
|
|
+TODO
|
|
|
|
|
|
-@as_plugin("my_cool_plugin")
|
|
|
-def my_cool_plugin(db, msg):
|
|
|
- return RollbotResponse(msg, txt="My first plugin!")
|
|
|
-```
|
|
|
+#### Plugin Arguments
|
|
|
+
|
|
|
+TODO
|
|
|
+
|
|
|
+#### RollbotResponse
|
|
|
|
|
|
-This is the most basic possible rollbot plugin, which will simply respond with `My first plugin!`
|
|
|
-when it receives a message starting with `!my_cool_plugin`. You can modify the argument to `as_plugin`
|
|
|
-to change the plugin's command word, which must be unique within the application.
|
|
|
+TODO
|
|
|
|
|
|
Further docs to come! Good luck!
|
|
|
|