File Template for Cogs in PyCharm

File Template for Cogs in PyCharm

When using the library, you'll likely find yourself creating many cogs (the libraries way of isolating command modules, in a brief sense). In order to eliminate rewriting the boiler-plate for every cog, we can utilize a PyCharm template and the Apache Velocity template language.

These can be accessed via Settings -> Editor -> File & Code Templates.

This is my template file:

The dynamic code up top is simple:

  1. We set a new variable $COG_NAME using #set($COG_NAME= ...)
  2. We then utilize Velocity StringUtils via ${StringUtils ...} and call the method removeAndHump(), which takes a string, capitalizes the first letter, and replaces underscores by camel-casing the word.
  3. We then pass in the file name to that method with the PyCharm variable $NAME.

I would also import my bot class and annotate bot: BotClassName in this file as well, which changes project-to-project. If you don't like type annotation, you can easily remove all of that.