mkplugin.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env sh
  2. if [ $# -lt 1 ]
  3. then
  4. echo "usage: $0 plugin-name"
  5. echo " This command generates a file at src/plugins/plugin-name.py, containing the base of a rollbot plugin."
  6. echo " The plugin-name must be a valid python identifier, and ideally should only be composed of lowercase letters and underscores"
  7. exit 1
  8. fi
  9. if ! [[ "$1" =~ ^[a-z][a-z_]*$ ]]
  10. then
  11. echo "Plugin names should be composed entirely of lowercase letters and underscores"
  12. exit 1
  13. fi
  14. PLUGIN_FILE="./src/plugins/$1.py"
  15. if [[ -f $PLUGIN_FILE ]]
  16. then
  17. echo "Plugin module with this name already exists - pick a new module name. You can always bind it to a different command word later!"
  18. exit 1
  19. fi
  20. echo "Populating $PLUGIN_FILE with basic plugin called $1"
  21. echo "from command_system import as_plugin" >> $PLUGIN_FILE
  22. echo "" >> $PLUGIN_FILE
  23. echo "" >> $PLUGIN_FILE
  24. echo "@as_plugin # if you want to change the name of the function below, you can just pass \"$1\" to this decorator" >> $PLUGIN_FILE
  25. echo "def $1(msg):" >> $PLUGIN_FILE
  26. echo " # try adding db, bot, log, and data args, if you need those for your plugin" >> $PLUGIN_FILE
  27. echo " return \"My first plugin!\"" >> $PLUGIN_FILE
  28. echo "import plugins.$1" >> ./src/plugins/__init__.py
  29. echo "Done! Plugin is ready for you to edit at $PLUGIN_FILE, you do not need to modify any configuration!"