#!/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 rollbot import as_plugin" >> $PLUGIN_FILE echo "" >> $PLUGIN_FILE echo "" >> $PLUGIN_FILE echo "@as_plugin" >> $PLUGIN_FILE echo "def $1():" >> $PLUGIN_FILE echo " return \"Hello, world!\"" >> $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!"