12345678910111213141516171819202122232425262728293031323334353637 |
- #!/usr/bin/env sh
- if [ $# -lt 1 ]
- then
- echo "usage: $0 plugin-name"
- echo " This command generates a file at src/plugins/plugin-name.py, containing the base of a rollbot plugin."
- echo " The plugin-name must be a valid python identifier, and ideally should only be composed of lowercase letters and underscores"
- exit 1
- fi
- if ! [[ "$1" =~ ^[a-z][a-z_]*$ ]]
- then
- echo "Plugin names should be composed entirely of lowercase letters and underscores"
- exit 1
- fi
- PLUGIN_FILE="./src/plugins/$1.py"
- if [[ -f $PLUGIN_FILE ]]
- then
- echo "Plugin module with this name already exists - pick a new module name. You can always bind it to a different command word later!"
- exit 1
- fi
- echo "Populating $PLUGIN_FILE with basic plugin called $1"
- echo "from command_system import as_plugin, RollbotResponse" >> $PLUGIN_FILE
- echo "" >> $PLUGIN_FILE
- echo "" >> $PLUGIN_FILE
- echo "@as_plugin # if you want to change the name of the function below, you can just pass \"$1\" to this decorator" >> $PLUGIN_FILE
- echo "def $1(msg):" >> $PLUGIN_FILE
- echo " # try adding db, bot, and log args, if you need those for your plugin" >> $PLUGIN_FILE
- echo " return RollbotResponse(msg, txt=\"My first plugin!\")" >> $PLUGIN_FILE
- echo "import plugins.$1" >> ./src/plugins/__init__.py
- echo "Done! Plugin is ready for you to edit at $PLUGIN_FILE, you do not need to modify any configuration!"
|